예제 #1
0
        public void TestUpdateShouldSerializeNull()
        {
            MaybeContractResolverWrapper testWrapper = new MaybeContractResolverWrapper();
            JsonProperty property = new JsonProperty
            {
                PropertyType = typeof(int),
                PropertyName = "Id"
            };

            Assert.IsNotNull(testWrapper.TestUpdateShouldSerialize(property));
            Assert.IsNull(property.ShouldSerialize, "Should not set Serialize when type is not Maybe");
        }
예제 #2
0
        public void TestUpdateShouldSerializeMaybe()
        {
            MaybeContractResolverWrapper testWrapper = new MaybeContractResolverWrapper();
            JsonProperty property = new JsonProperty
            {
                PropertyType = typeof(Maybe <int>),
                PropertyName = "Id"
            };

            Assert.IsNotNull(testWrapper.TestUpdateShouldSerialize(property));
            Assert.IsTrue(property.ShouldSerialize(new { Id = new Maybe <int>(5) }));
            Assert.IsFalse(property.ShouldSerialize(new { Id = Maybe <int> .None }));
        }
예제 #3
0
        public void TestUpdateShouldSerializeMaybeProtectedField()
        {
            MaybeContractResolverWrapper testWrapper = new MaybeContractResolverWrapper();
            JsonProperty property = new JsonProperty
            {
                PropertyType = typeof(Maybe <float>),
                PropertyName = "Price"
            };

            FakeClass fc = new FakeClass
            {
                Name = "test"
            };

            Assert.IsNotNull(testWrapper.TestUpdateShouldSerialize(property));
            Assert.IsFalse(property.ShouldSerialize(fc));
        }
예제 #4
0
        public void TestUpdateShouldSerializeMaybeField()
        {
            MaybeContractResolverWrapper testWrapper = new MaybeContractResolverWrapper();
            JsonProperty property = new JsonProperty
            {
                PropertyType = typeof(Maybe <string>),
                PropertyName = nameof(FakeClass.Name)
            };

            FakeClass fc = new FakeClass
            {
                Name = "test"
            };

            Assert.IsNotNull(testWrapper.TestUpdateShouldSerialize(property));
            Assert.IsTrue(property.ShouldSerialize(fc));
        }