public void TestSerialize() { var stream = new MemoryStream(); var group = new TestGroup(); group.Type = TestGroupType.TestGroupTypeBaz; group.Baz = 4; var enumFormatter = new Mock <ICauterizeTypeFormatter>(); var byteFormatter = new Mock <ICauterizeTypeFormatter>(); var factory = new Mock <CauterizeTypeFormatterFactory>(); factory.Setup(f => f.GetFormatter(It.IsAny <Type>())).Returns((Type t) => { if (t == typeof(TestGroupType)) { return(enumFormatter.Object); } else if (t == typeof(Byte)) { return(byteFormatter.Object); } else { return(null); } }); enumFormatter.Setup(f => f.Serialize(stream, TestGroupType.TestGroupTypeBaz)); byteFormatter.Setup(f => f.Serialize(stream, (Byte)4)); var formatter = new CauterizeGroupFormatter(factory.Object); formatter.Serialize(stream, group); enumFormatter.VerifyAll(); byteFormatter.VerifyAll(); }
public void TestSerialize() { var stream = new MemoryStream(); var group = new TestGroup(); group.Type = TestGroupType.TestGroupTypeBaz; group.Baz = 4; var enumFormatter = new Mock<ICauterizeTypeFormatter>(); var byteFormatter = new Mock<ICauterizeTypeFormatter>(); var factory = new Mock<CauterizeTypeFormatterFactory>(); factory.Setup(f => f.GetFormatter(It.IsAny<Type>())).Returns((Type t) => { if (t == typeof (TestGroupType)) { return enumFormatter.Object; } else if (t == typeof (Byte)) { return byteFormatter.Object; } else { return null; } }); enumFormatter.Setup(f => f.Serialize(stream, TestGroupType.TestGroupTypeBaz)); byteFormatter.Setup(f => f.Serialize(stream, (Byte)4)); var formatter = new CauterizeGroupFormatter(factory.Object); formatter.Serialize(stream, group); enumFormatter.VerifyAll(); byteFormatter.VerifyAll(); }