public void ApplyTo_AppliesConstraintToDeserialized() { var serializable = new Serializable { D = 3m, S = "s" }; var deserialized = new Serializable(); var serializer = Substitute.For<IRoundtripSerializer<Serializable>>(); var constraint = Substitute.For<Constraint>(); serializer.Deserialize().Returns(deserialized); var subject = new SerializationConstraint<Serializable>(serializer, constraint); subject.ApplyTo(serializable); constraint.Received().ApplyTo(deserialized); }
public void ApplyTo_AppliesConstraintToDeserialized() { var serializable = new Serializable { D = 3m, S = "s" }; var deserialized = new Serializable(); var serializer = Substitute.For <IRoundtripSerializer <Serializable> >(); var constraint = Substitute.For <Constraint>(); serializer.Deserialize().Returns(deserialized); var subject = new SerializationConstraint <Serializable>(serializer, constraint); subject.ApplyTo(serializable); constraint.Received().ApplyTo(deserialized); }
public void ApplyTo_AsksDeserializerToDeserializeWhatWasSerialized() { var serializable = new Serializable { D = 3m, S = "s" }; var serializer = Substitute.For<IRoundtripSerializer<Serializable>>(); var subject = new SerializationConstraint<Serializable>(serializer, Is.Null); subject.ApplyTo(serializable); ICall[] receivedCalls = serializer.ReceivedCalls().ToArray(); // first call: .Serialize(serializable) Assert.That(receivedCalls[0].GetMethodInfo().Name, Is.EqualTo("Serialize")); Assert.That(receivedCalls[0].GetArguments()[0], Is.SameAs(serializable)); // second call: Deserialize() Assert.That(receivedCalls[1].GetMethodInfo().Name, Is.EqualTo("Deserialize")); // third call: Dispose() Assert.That(receivedCalls[2].GetMethodInfo().Name, Is.EqualTo("Dispose")); }
public void ApplyTo_AsksDeserializerToDeserializeWhatWasSerialized() { var serializable = new Serializable { D = 3m, S = "s" }; var serializer = Substitute.For <IRoundtripSerializer <Serializable> >(); var subject = new SerializationConstraint <Serializable>(serializer, Is.Null); subject.ApplyTo(serializable); ICall[] receivedCalls = serializer.ReceivedCalls().ToArray(); // first call: .Serialize(serializable) Assert.That(receivedCalls[0].GetMethodInfo().Name, Is.EqualTo("Serialize")); Assert.That(receivedCalls[0].GetArguments()[0], Is.SameAs(serializable)); // second call: Deserialize() Assert.That(receivedCalls[1].GetMethodInfo().Name, Is.EqualTo("Deserialize")); // third call: Dispose() Assert.That(receivedCalls[2].GetMethodInfo().Name, Is.EqualTo("Dispose")); }