public void ApplyTo_NonSerialized_False()
        {
            var nonSerializable = "<notSerializable />";
            var subject         = new DeserializationConstraint <Serializable>(
                new JsonDeserializer(), Is.Not.Null);

            Assert.That(matches(subject, nonSerializable), Is.False);
        }
        public void ApplyTo_NonSerialized_False()
        {
            var nonSerializable = "<notSerializable />";
            var subject = new DeserializationConstraint<Serializable>(
                new JsonDeserializer(), Is.Not.Null);

            Assert.That(matches(subject, nonSerializable), Is.False);
        }
        public void WriteMessageTo_NonSerialized_ExpectedContainsConstraintExpectations_ActualContainsExpectationsErrorPlusObject()
        {
            var nonSerializable = "<notSerializable />";
            var subject         = new DeserializationConstraint <Serializable>(
                new JsonDeserializer(), Is.Not.Null);

            Assert.That(getMessage(subject, nonSerializable), Does
                        .StartWith(TextMessageWriter.Pfx_Expected + "Deserialized object not null").And
                        .Contains(TextMessageWriter.Pfx_Actual + "Could not deserialize object"));
        }
        public void ApplyTo_NonMatching_False()
        {
            var nonMatching = Serializable.JsonString("s", 3m);
            var subject     = new DeserializationConstraint <Serializable>(
                new JsonDeserializer(),
                Has.Property("S").EqualTo("sS")
                .And.Property("D").EqualTo(3m));

            Assert.That(matches(subject, nonMatching), Is.False);
        }
        public void ApplyTo_MatchingDeserialized_True()
        {
            var matching = Serializable.XmlString("s", 3m);
            var subject  = new DeserializationConstraint <Serializable>(
                new XmlDeserializer(),
                Has.Property("S").EqualTo("s")
                .And.Property("D").EqualTo(3m));

            Assert.That(matches(subject, matching), Is.True);
        }
        public void WriteMessageTo_NonSerialized_ExpectedContainsConstraintExpectations_ActualContainsExpectationsErrorPlusObject()
        {
            var nonSerializable = "<notSerializable />";
            var subject = new DeserializationConstraint<Serializable>(
                new JsonDeserializer(), Is.Not.Null);

            Assert.That(getMessage(subject, nonSerializable), Does
                .StartWith(TextMessageWriter.Pfx_Expected + "Deserialized object not null").And
                .Contains(TextMessageWriter.Pfx_Actual + "Could not deserialize object"));
        }
        public void ApplyTo_NonMatching_False()
        {
            var nonMatching = Serializable.JsonString("s", 3m);
            var subject = new DeserializationConstraint<Serializable>(
                new JsonDeserializer(),
                Has.Property("S").EqualTo("sS")
                    .And.Property("D").EqualTo(3m));

            Assert.That(matches(subject, nonMatching), Is.False);
        }
        public void ApplyTo_MatchingDeserialized_True()
        {
            var matching = Serializable.DataContractString("s", 3m);
            var subject = new DeserializationConstraint<Serializable>(
                new DataContractDeserializer(),
                Has.Property("S").EqualTo("s")
                    .And.Property("D").EqualTo(3m));

            Assert.That(matches(subject, matching), Is.True);
        }
        public void WriteMessageTo_NonMatching_ActualContainsOffendingValueAndActualObject()
        {
            var nonMatching = Serializable.JsonString("s", 3m);
            var subject     = new DeserializationConstraint <Serializable>(
                new JsonDeserializer(),
                Has.Property("S").EqualTo("sS")
                .And.Property("D").EqualTo(3m));

            Assert.That(getMessage(subject, nonMatching), Does.Contain(TextMessageWriter.Pfx_Actual + "\"s\"").And
                        .Contains(" -> <" + typeof(Serializable).FullName + ">"));
        }
        public void WriteMessageTo_NonMatching_ActualContainsOffendingValueAndActualObject()
        {
            var nonMatching = Serializable.JsonString("s", 3m);
            var subject = new DeserializationConstraint<Serializable>(
                new JsonDeserializer(),
                Has.Property("S").EqualTo("sS")
                    .And.Property("D").EqualTo(3m));

            Assert.That(getMessage(subject, nonMatching), Does.Contain(TextMessageWriter.Pfx_Actual + "\"s\"").And
                .Contains(" -> <" + typeof(Serializable).FullName + ">"));
        }
        public void ApplyTo_AppliesConstraintToDeserialized()
        {
            string serializationRepresentation = "representation";
            var deserialized = new Serializable { D = 3m, S = "s" };

            var deserializer = Substitute.For<IDeserializer>();
            var constraint = Substitute.For<Constraint>();
            deserializer.Deserialize<Serializable>(serializationRepresentation).Returns(deserialized);

            var subject = new DeserializationConstraint<Serializable>(deserializer, constraint);
            subject.ApplyTo(serializationRepresentation);

            constraint.Received().ApplyTo(deserialized);
        }
        public void ApplyTo_AppliesConstraintToDeserialized()
        {
            string serializationRepresentation = "representation";
            var    deserialized = new Serializable {
                D = 3m, S = "s"
            };

            var deserializer = Substitute.For <IDeserializer>();
            var constraint   = Substitute.For <Constraint>();

            deserializer.Deserialize <Serializable>(serializationRepresentation).Returns(deserialized);

            var subject = new DeserializationConstraint <Serializable>(deserializer, constraint);

            subject.ApplyTo(serializationRepresentation);

            constraint.Received().ApplyTo(deserialized);
        }