protected static void ShowCustomSerializationResult(object obj, PropertiesContractResolver propertiesContractResolver)
        {
            var customJsonSerializerSettings = new JsonSerializerSettings { ContractResolver = propertiesContractResolver };

            Console.WriteLine("");
            Console.WriteLine("Custom serialization result: {0}", JsonConvert.SerializeObject(obj, customJsonSerializerSettings));
        }
        public void ConstructorWithWhiteSpaceExcludePropertiesStringSetsExcludePropertiesToEmptySet(string whiteSpaceExcludeProperties)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver(excludeProperties: whiteSpaceExcludeProperties);

            // Act

            // Assert
            Assert.False(propertiesContractResolver.ExcludeProperties.Any());
        }
        public override void ShowUsage()
        {
            var director = CreateDirector();
            var propertiesContractResolver = new PropertiesContractResolver(properties: "Name");

            ShowUsageHeader("Example 1: simple usage");
            ShowDefaultSerializationResult(director);
            ShowInstruction("To only serialize the \"Name\" property do:");
            ShowCreatePropertiesContractResolver("\"Name\"");
            ShowCustomSerializationResult(director, propertiesContractResolver);
            ShowMoveToNextExample();
        }
        public override void ShowUsage()
        {
            var director = CreateDirector();
            var propertiesContractResolver = new PropertiesContractResolver(excludeProperties: "*");

            ShowUsageHeader("Example 7: general wildcard usage");
            ShowDefaultSerializationResult(director);
            ShowInstruction("To exclude all properties from serialization:");
            ShowCreateExcludePropertiesContractResolver("\"*\"");
            ShowCustomSerializationResult(director, propertiesContractResolver);
            ShowMoveToNextExample();
        }
 public override void ShowUsage()
 {
     var director = CreateDirector();
     var propertiesContractResolver = new PropertiesContractResolver(excludeProperties: "Director.Name");
     
     ShowUsageHeader("Example 3: explicit type usage");
     ShowDefaultSerializationResult(director);
     ShowInstruction("To serialize everything but the \"Name\" property of the \"Director\" type do:");
     ShowCreatePropertiesContractResolver("\"Director.Name\"");
     ShowCustomSerializationResult(director, propertiesContractResolver);
     ShowMoveToNextExample();
 }
 public override void ShowUsage()
 {
     var movie = CreateMovie();
     var propertiesContractResolver = new PropertiesContractResolver(properties: "Movie.*");
     
     ShowUsageHeader("Example 5: property wildcard usage");
     ShowDefaultSerializationResult(movie);
     ShowInstruction("To output all properties of the \"Movie\" type from serialization:");
     ShowCreatePropertiesContractResolver("\"Movie.*\"");
     ShowCustomSerializationResult(movie, propertiesContractResolver);
     ShowMoveToNextExample();
 }
        public override void ShowUsage()
        {
            var movie = CreateMovie();
            var propertiesContractResolver = new PropertiesContractResolver(properties: "Movie.Title, Movie.Director, Director.Name");

            ShowUsageHeader("Example 4: nested properties usage");
            ShowDefaultSerializationResult(movie);
            ShowInstruction("To serialize the \"Movie.Title\" and \"Director.Name\" properties:");
            ShowCreatePropertiesContractResolver("\"Movie.Title, Movie.Director, Director.Name\"");
            ShowCustomSerializationResult(movie, propertiesContractResolver);
            ShowMoveToNextExample();
        }
        public void DefaultSettingsDoNotModifyDefaultSerialization(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var objectToSerialize          = CreateObjectToSerialize();
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = propertyMatchMode
            };

            // Act
            var jsonUsingDefaultSerializer = JsonConvert.SerializeObject(objectToSerialize, CreateDefaultJsonSerializerSettings());
            var jsonUsingCustomSerializer  = JsonConvert.SerializeObject(objectToSerialize, CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal(jsonUsingDefaultSerializer, jsonUsingCustomSerializer);
        }
        public void ExcludePropertiesWithNestedPropertyDoesNotSerializeNestedProperty(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = propertyMatchMode
            };

            propertiesContractResolver.ExcludeProperties.Add("Movie.Title");
            propertiesContractResolver.ExcludeProperties.Add("Director.Name");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Director\":{\"Id\":77}}", json);
        }
        public void PropertiesWildcardWillCauseSerializationOfAllPropertiesOfTheSpecifiedType(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = propertyMatchMode
            };

            propertiesContractResolver.Properties.Add("Movie.*");
            propertiesContractResolver.Properties.Add("Director.*");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Title\":\"Inception\",\"Director\":{\"Id\":77,\"Name\":\"Christopher Nolan\"}}", json);
        }
        public void NameAndTypePropertyMatchModeWillNotSerializeSpecifiedExcludeProperties()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = PropertyMatchMode.NameAndType
            };

            propertiesContractResolver.ExcludeProperties.Add("Movie.Id");
            propertiesContractResolver.ExcludeProperties.Add("Movie.Title");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Director\":{\"Id\":77,\"Name\":\"Christopher Nolan\"}}", json);
        }
        public void TypeWildcardWillCauseSerializationOfAllPropertiesWithTheSpecifiedName(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var customPropertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = propertyMatchMode
            };

            customPropertiesContractResolver.Properties.Add("*.Id");
            customPropertiesContractResolver.Properties.Add("*.Director");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(customPropertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Director\":{\"Id\":77}}", json);
        }
        public void NamePropertyMatchModeWithPropertiesThatExistInDifferentTypesSerializesPropertyOnAllTypes()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = PropertyMatchMode.Name
            };

            propertiesContractResolver.Properties.Add("Id");
            propertiesContractResolver.Properties.Add("Director");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Director\":{\"Id\":77}}", json);
        }
        public void NamePropertyMatchModeWithPropertiesWithNoTypeSpecifiedWillNotSerializeSpecifiedProperties()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = PropertyMatchMode.NameAndType
            };

            propertiesContractResolver.Properties.Add("Id");
            propertiesContractResolver.Properties.Add("Title");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{}", json);
        }
        public void NameAndTypePropertyMatchModeWithNestedExcludePropertiesWillNotSerializeExcludeProperties()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = PropertyMatchMode.NameAndType
            };

            propertiesContractResolver.ExcludeProperties.Add("Movie.Title");
            propertiesContractResolver.ExcludeProperties.Add("Movie.Director");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12}", json);
        }
        public void SamePropertySpecifiedAsTypeWildcardPropertiesAndExcludePropertiesWillNotSerializeThatProperty(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = propertyMatchMode
            };

            propertiesContractResolver.Properties.Add("Director.*");
            propertiesContractResolver.ExcludeProperties.Add("Director.*");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{}", json);
        }
        public void NamePropertyMatchModeWithPropertiesWithTypeSpecifiedWillSerializeSpecifiedProperties()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = PropertyMatchMode.Name
            };

            propertiesContractResolver.Properties.Add("Movie.Id");
            propertiesContractResolver.Properties.Add("Movie.Title");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Title\":\"Inception\"}", json);
        }
        public void ExcludePropertiesGeneralWildcardOverrulesPropertiesGeneralWildcard(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = propertyMatchMode
            };

            propertiesContractResolver.Properties.Add("*");
            propertiesContractResolver.ExcludeProperties.Add("*");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{}", json);
        }
        public void NameAndTypePropertyMatchModeCorrectlySerializesNestedProperties()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = PropertyMatchMode.NameAndType
            };

            propertiesContractResolver.Properties.Add("Movie.Title");
            propertiesContractResolver.Properties.Add("Movie.Director");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Title\":\"Inception\",\"Director\":{}}", json);
        }
        public void NameAndTypePropertyMatchModeWithPropertiesThatExistInDifferentTypesSerializesPropertyOnAllTypes()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = PropertyMatchMode.NameAndType
            };

            propertiesContractResolver.Properties.Add("Movie.Title");
            propertiesContractResolver.Properties.Add("Movie.Director");
            propertiesContractResolver.Properties.Add("Director.Name");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Title\":\"Inception\",\"Director\":{\"Name\":\"Christopher Nolan\"}}", json);
        }
        public void ConvertingUsingWildcardsDoesNotModifyExcludePropertiesCollection(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = PropertyMatchMode.NameAndType
            };

            propertiesContractResolver.ExcludeProperties.Add("*");
            propertiesContractResolver.ExcludeProperties.Add("*.Title");
            propertiesContractResolver.ExcludeProperties.Add("Title");
            propertiesContractResolver.ExcludeProperties.Add("Title.*");

            // Act
            JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.True(propertiesContractResolver.ExcludeProperties.SequenceEqual(new[] { "*", "*.Title", "Title", "Title.*" }));
        }
        public void PropertiesSetToGeneralWildcardWillSerializeAllProperties(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var objectToSerialize = CreateObjectToSerialize();

            var propertiesContractResolver = new PropertiesContractResolver {
                PropertyMatchMode = propertyMatchMode
            };

            propertiesContractResolver.Properties.Add("*");

            // Act
            var jsonUsingDefaultSerializer = JsonConvert.SerializeObject(objectToSerialize, CreateDefaultJsonSerializerSettings());
            var jsonUsingCustomSerializer  = JsonConvert.SerializeObject(objectToSerialize, CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal(jsonUsingDefaultSerializer, jsonUsingCustomSerializer);
        }
        public void NameAndTypePropertyMatchModeWillOnlyMatchWhenTypeAndNameMatch()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            propertiesContractResolver.Properties.Add("Movie.Id");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12}", json);
        }
        public void ExcludePropertiesWithNestedPropertyDoesNotSerializeNestedProperty(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = propertyMatchMode };
            propertiesContractResolver.ExcludeProperties.Add("Movie.Title");
            propertiesContractResolver.ExcludeProperties.Add("Director.Name");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Director\":{\"Id\":77}}", json);
        }
        public void NameAndTypePropertyMatchModeWillNotMatchUnknownTypeProperties()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            propertiesContractResolver.Properties.Add("Dummy.Id");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{}", json);
        }
        public void ExcludePropertiesWithTypeWildcardPropertyDoesNotSerializeAnyPropertyWithTheSpecifiedType(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            propertiesContractResolver.ExcludeProperties.Add("Movie.*");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{}", json);
        }
        public void NameAndTypePropertyMatchModeWithPropertiesThatExistInDifferentTypesSerializesPropertyOnAllTypes()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            propertiesContractResolver.Properties.Add("Movie.Title");
            propertiesContractResolver.Properties.Add("Movie.Director");
            propertiesContractResolver.Properties.Add("Director.Name");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Title\":\"Inception\",\"Director\":{\"Name\":\"Christopher Nolan\"}}", json);
        }
        public void NameAndTypePropertyMatchModeMatchesPropertiesCaseInsensitive(string field)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            propertiesContractResolver.Properties.Add(field);

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12}", json);
        }
        public void NameAndTypePropertyMatchModeCorrectlySerializesNestedProperties()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            propertiesContractResolver.Properties.Add("Movie.Title");
            propertiesContractResolver.Properties.Add("Movie.Director");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Title\":\"Inception\",\"Director\":{}}", json);
        }
        public void NameAndTypePropertyMatchModeWithNestedExcludePropertiesWillNotSerializeExcludeProperties()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            propertiesContractResolver.ExcludeProperties.Add("Movie.Title");
            propertiesContractResolver.ExcludeProperties.Add("Movie.Director");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12}", json);
        }
        public void ExcludePropertiesGeneralWildcardOverrulesPropertiesGeneralWildcard(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = propertyMatchMode };
            propertiesContractResolver.Properties.Add("*");
            propertiesContractResolver.ExcludeProperties.Add("*");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{}", json);
        }
        public void SamePropertySpecifiedAsTypeWildcardPropertiesAndExcludePropertiesWillNotSerializeThatProperty(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = propertyMatchMode };
            propertiesContractResolver.Properties.Add("Director.*");
            propertiesContractResolver.ExcludeProperties.Add("Director.*");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{}", json);
        }
        public void NamePropertyMatchModeWithPropertiesWithNoTypeSpecifiedWillNotSerializeSpecifiedProperties()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            propertiesContractResolver.Properties.Add("Id");
            propertiesContractResolver.Properties.Add("Title");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{}", json);
        }
        public void ExcludePropertiesWithTypeWildcardDoesNotSerializeAnyPropertyWithTheSpecifiedName(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var customPropertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            customPropertiesContractResolver.ExcludeProperties.Add("*.Title");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(customPropertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Director\":{\"Id\":77,\"Name\":\"Christopher Nolan\"}}", json);
        }
        public void ExcludePropertiesWithTypeWildcardForNestedPropertyDoesNotSerializeAnyPropertyWithTheSpecifiedType(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            propertiesContractResolver.ExcludeProperties.Add("Director.*");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Title\":\"Inception\",\"Director\":{}}", json);
        }
        public void NameAndTypePropertyMatchModeIgnoresUnknownExcludeProperties(string unknownField)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            propertiesContractResolver.ExcludeProperties.Add(unknownField);

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Title\":\"Inception\",\"Director\":{\"Id\":77,\"Name\":\"Christopher Nolan\"}}", json);
        }
        public void NameAndTypePropertyMatchModeWillNotSerializeSpecifiedExcludeProperties()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            propertiesContractResolver.ExcludeProperties.Add("Movie.Id");
            propertiesContractResolver.ExcludeProperties.Add("Movie.Title");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Director\":{\"Id\":77,\"Name\":\"Christopher Nolan\"}}", json);
        }
        public void TypeWildcardWillCauseSerializationOfAllPropertiesWithTheSpecifiedName(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var customPropertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = propertyMatchMode };
            customPropertiesContractResolver.Properties.Add("*.Id");
            customPropertiesContractResolver.Properties.Add("*.Director");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(customPropertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Director\":{\"Id\":77}}", json);
        }
        public void NamePropertyMatchModeMatchesExcludePropertiesCaseInsensitive(string field)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.Name };
            propertiesContractResolver.ExcludeProperties.Add(field);

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Title\":\"Inception\",\"Director\":{\"Name\":\"Christopher Nolan\"}}", json);
        }
        public void ConstructorWithNoPropertiesStringSetsPropertiesToEmptySet()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver(excludeProperties: string.Empty);

            // Act

            // Assert
            Assert.False(propertiesContractResolver.Properties.Any());
        }
        public void PropertiesWildcardWillCauseSerializationOfAllPropertiesOfTheSpecifiedType(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = propertyMatchMode };
            propertiesContractResolver.Properties.Add("Movie.*");
            propertiesContractResolver.Properties.Add("Director.*");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Title\":\"Inception\",\"Director\":{\"Id\":77,\"Name\":\"Christopher Nolan\"}}", json);
        }
        public void NamePropertyMatchModeWithPropertiesWithTypeSpecifiedWillSerializeSpecifiedProperties()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.Name };
            propertiesContractResolver.Properties.Add("Movie.Id");
            propertiesContractResolver.Properties.Add("Movie.Title");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Title\":\"Inception\"}", json);
        }
        public void NameAndTypePropertyMatchModeWithOnlyUnknownPropertiesDoesNotSerializeAnything(string unknownField)
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            propertiesContractResolver.Properties.Add(unknownField);

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{}", json);
        }
        public void ExcludePropertiesWithTypeWildcardAddedForPropertyInDifferentTypesDoesNotSerializePropertyInAnyType(PropertyMatchMode propertyMatchMode)
        {
            // Arrange
            var customPropertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.NameAndType };
            customPropertiesContractResolver.ExcludeProperties.Add("*.Id");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(customPropertiesContractResolver));

            // Assert
            Assert.Equal("{\"Title\":\"Inception\",\"Director\":{\"Name\":\"Christopher Nolan\"}}", json);
        }
        public void NamePropertyMatchModeWithPropertiesThatExistInDifferentTypesSerializesPropertyOnAllTypes()
        {
            // Arrange
            var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = PropertyMatchMode.Name };
            propertiesContractResolver.Properties.Add("Id");
            propertiesContractResolver.Properties.Add("Director");

            // Act
            var json = JsonConvert.SerializeObject(CreateObjectToSerialize(), CreateCustomJsonSerializerSettings(propertiesContractResolver));

            // Assert
            Assert.Equal("{\"Id\":12,\"Director\":{\"Id\":77}}", json);
        }