示例#1
0
        public void TestSerializeAndDeserialize()
        {
            SerTestObject obj = new SerTestObject()
            {
                Number = 100,
                Text   = "Demo"
            };

            obj.SomeList.Add("ptv");
            obj.SomeList.Add("vrk");

            var serialized = obj.SerializeObject();

            serialized.Should().NotBeNullOrWhiteSpace();

            SerTestObject desObj = serialized.DeserializeObject <SerTestObject>();

            desObj.Should().NotBeNull();

            desObj.Number.Should().Be(obj.Number);
            desObj.Text.Should().Be(obj.Text);

            desObj.SomeList.Count.Should().Be(obj.SomeList.Count); // this is not really needed as the below line covers this too
            Enumerable.SequenceEqual(desObj.SomeList.OrderBy(k => k), obj.SomeList.OrderBy(t => t)).Should().BeTrue();
        }
示例#2
0
        public void SerializeObjectShouldHandleNullInstance()
        {
            SerTestObject obj = null;
            Action        act = () => obj.SerializeObject();

            // currently throws NullReferenceException
            act.ShouldThrowExactly <ArgumentNullException>("Object to serialize is null.");
        }