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 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 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 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 ExcludePropertiesSetToGeneralWildcardDoesNotSerializeAnyProperties(PropertyMatchMode propertyMatchMode) { // Arrange var propertiesContractResolver = new PropertiesContractResolver { PropertyMatchMode = propertyMatchMode }; propertiesContractResolver.ExcludeProperties.Add("*"); // 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 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 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 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 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 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 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 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); }