public void IsRequired_LeftAlone_DataMemberIsRequiredFalse(bool?initialValue) { // Arrange var provider = new DataMemberRequiredBindingMetadataProvider(); var attributes = new object[] { new DataMemberAttribute() { IsRequired = false, } }; var key = ModelMetadataIdentity.ForProperty( typeof(string), nameof(ClassWithDataMemberIsRequiredFalse.StringProperty), typeof(ClassWithDataMemberIsRequiredFalse)); var context = new BindingMetadataProviderContext(key, attributes); context.BindingMetadata.IsRequired = initialValue; // Act provider.GetBindingMetadata(context); // Assert Assert.Equal(initialValue, context.BindingMetadata.IsRequired); }
public void IsRequired_SetToTrue_WithDataMemberIsRequiredTrue() { // Arrange var provider = new DataMemberRequiredBindingMetadataProvider(); var attributes = new object[] { new DataMemberAttribute() { IsRequired = true, } }; var key = ModelMetadataIdentity.ForProperty( typeof(string), nameof(ClassWithDataMemberIsRequiredTrue.StringProperty), typeof(ClassWithDataMemberIsRequiredTrue)); var context = new BindingMetadataProviderContext(key, attributes); // Act provider.GetBindingMetadata(context); // Assert Assert.True(context.BindingMetadata.IsRequired); }
public void IsBindingRequired_LeftAlone_WithoutDataContractAttribute(bool initialValue) { // Arrange var provider = new DataMemberRequiredBindingMetadataProvider(); var attributes = new object[] { new DataMemberAttribute() { IsRequired = true, } }; var key = ModelMetadataIdentity.ForProperty( typeof(string), nameof(ClassWithDataMemberIsRequiredTrueWithoutDataContract.StringProperty), typeof(ClassWithDataMemberIsRequiredTrueWithoutDataContract)); var context = new BindingMetadataProviderContext(key, new ModelAttributes(attributes, new object[0])); context.BindingMetadata.IsBindingRequired = initialValue; // Act provider.GetBindingMetadata(context); // Assert Assert.Equal(initialValue, context.BindingMetadata.IsBindingRequired); }
public void IsBindingRequired_LeftAlone_ForNonPropertyMetadata(bool initialValue) { // Arrange var provider = new DataMemberRequiredBindingMetadataProvider(); var attributes = new object[] { new DataMemberAttribute() { IsRequired = true, } }; var key = ModelMetadataIdentity.ForType(typeof(ClassWithDataMemberIsRequiredTrue)); var context = new BindingMetadataProviderContext(key, new ModelAttributes(attributes, new object[0])); context.BindingMetadata.IsBindingRequired = initialValue; // Act provider.GetBindingMetadata(context); // Assert Assert.Equal(initialValue, context.BindingMetadata.IsBindingRequired); }
public void IsBindingRequired_SetToTrue_WithDataMemberIsRequiredTrue() { // Arrange var provider = new DataMemberRequiredBindingMetadataProvider(); var attributes = new object[] { new DataMemberAttribute() { IsRequired = true, } }; var key = ModelMetadataIdentity.ForProperty( typeof(string), nameof(ClassWithDataMemberIsRequiredTrue.StringProperty), typeof(ClassWithDataMemberIsRequiredTrue)); var context = new BindingMetadataProviderContext(key, new ModelAttributes(attributes, new object[0])); // Act provider.GetBindingMetadata(context); // Assert Assert.True(context.BindingMetadata.IsBindingRequired); }
public void IsRequired_LeftAlone_DataMemberIsRequiredFalse(bool? initialValue) { // Arrange var provider = new DataMemberRequiredBindingMetadataProvider(); var attributes = new object[] { new DataMemberAttribute() { IsRequired = false, } }; var key = ModelMetadataIdentity.ForProperty( typeof(string), nameof(ClassWithDataMemberIsRequiredFalse.StringProperty), typeof(ClassWithDataMemberIsRequiredFalse)); var context = new BindingMetadataProviderContext(key, attributes); context.BindingMetadata.IsRequired = initialValue; // Act provider.GetBindingMetadata(context); // Assert Assert.Equal(initialValue, context.BindingMetadata.IsRequired); }
public void IsBindingRequired_LeftAlone_WithoutDataMemberAttribute(bool initialValue) { // Arrange var provider = new DataMemberRequiredBindingMetadataProvider(); var key = ModelMetadataIdentity.ForProperty( typeof(string), nameof(ClassWithoutAttributes.StringProperty), typeof(ClassWithoutAttributes)); var context = new BindingMetadataProviderContext(key, new ModelAttributes(new object[0], new object[0])); context.BindingMetadata.IsBindingRequired = initialValue; // Act provider.GetBindingMetadata(context); // Assert Assert.Equal(initialValue, context.BindingMetadata.IsBindingRequired); }