public void ValidateDoesNotThrowWhenComparedObjectsAreEqual() { object otherObject = new CompareObject("test"); CompareObject currentObject = new CompareObject("test"); ValidationContext testContext = new ValidationContext(otherObject, null, null); CompareAttribute attr = new CompareAttribute("CompareProperty"); attr.Validate(currentObject.CompareProperty, testContext); }
public static void Validate_PropertyHasDisplayName_UpdatesFormatErrorMessageToContainDisplayName() { CompareAttribute attribute = new CompareAttribute(nameof(CompareObject.ComparePropertyWithDisplayName)); string oldErrorMessage = attribute.FormatErrorMessage("name"); Assert.False(oldErrorMessage.Contains("CustomDisplayName")); Assert.Throws<ValidationException>(() => attribute.Validate("test1", new ValidationContext(new CompareObject("test")))); string newErrorMessage = attribute.FormatErrorMessage("name"); Assert.NotEqual(oldErrorMessage, newErrorMessage); Assert.True(newErrorMessage.Contains("CustomDisplayName")); }
public void ValidateThrowsWithOtherPropertyDisplayName() { CompareObject currentObject = new CompareObject("a"); object otherObject = new CompareObject("b"); ValidationContext testContext = new ValidationContext(otherObject, null, null); testContext.DisplayName = "CurrentProperty"; CompareAttribute attr = new CompareAttribute("ComparePropertyWithDisplayName"); Assert.Throws <ValidationException>( delegate { attr.Validate(currentObject.CompareProperty, testContext); }, "'CurrentProperty' and 'DisplayName' do not match."); }
public static void Validate_PropertyHasDisplayName_UpdatesFormatErrorMessageToContainDisplayName() { CompareAttribute attribute = new CompareAttribute(nameof(CompareObject.ComparePropertyWithDisplayName)); string oldErrorMessage = attribute.FormatErrorMessage("name"); Assert.False(oldErrorMessage.Contains("CustomDisplayName")); Assert.Throws <ValidationException>(() => attribute.Validate("test1", new ValidationContext(new CompareObject("test")))); string newErrorMessage = attribute.FormatErrorMessage("name"); Assert.NotEqual(oldErrorMessage, newErrorMessage); Assert.True(newErrorMessage.Contains("CustomDisplayName")); }
public void ValidateThrowsWhenPropertyNameIsUnknown() { CompareObject currentObject = new CompareObject("a"); object otherObject = new CompareObject("b"); ValidationContext testContext = new ValidationContext(otherObject, null, null); testContext.DisplayName = "CurrentProperty"; CompareAttribute attr = new CompareAttribute("UnknownPropertyName"); ExceptionHelper.ExpectException <System.ComponentModel.DataAnnotations.ValidationException>( () => attr.Validate(currentObject.CompareProperty, testContext), "Could not find a property named UnknownPropertyName." ); }
public void ValidateThrowsWhenComparedObjectsAreNotEqual() { CompareObject currentObject = new CompareObject("a"); object otherObject = new CompareObject("b"); ValidationContext testContext = new ValidationContext(otherObject, null, null); testContext.DisplayName = "CurrentProperty"; CompareAttribute attr = new CompareAttribute("CompareProperty"); ExceptionHelper.ExpectException <System.ComponentModel.DataAnnotations.ValidationException>( delegate { attr.Validate(currentObject.CompareProperty, testContext); }, "'CurrentProperty' and 'CompareProperty' do not match."); }
public void ValidateThrowsWhenPropertyNameIsUnknown() { CompareObject currentObject = new CompareObject("a"); object otherObject = new CompareObject("b"); ValidationContext testContext = new ValidationContext(otherObject, null, null); testContext.DisplayName = "CurrentProperty"; CompareAttribute attr = new CompareAttribute("UnknownPropertyName"); Assert.Throws <ValidationException>( () => attr.Validate(currentObject.CompareProperty, testContext), "Could not find a property named UnknownPropertyName." ); }
public static void Validate_SetOnlyProperty_ThrowsArgumentException() { CompareAttribute attribute = new CompareAttribute(nameof(CompareObject.SetOnlyProperty)); Assert.Throws <ArgumentException>(null, () => attribute.Validate("b", s_context)); }
public static void Validate_Indexer_ThrowsArgumentException_Netcoreapp() { CompareAttribute attribute = new CompareAttribute("Item"); Assert.Throws <ArgumentException>(null, () => attribute.Validate("b", s_context)); }
public static void Validate_Indexer_ThrowsTargetParameterCountException_Netfx() { CompareAttribute attribute = new CompareAttribute("Item"); Assert.Throws <TargetParameterCountException>(() => attribute.Validate("b", s_context)); }
public static void Validate_SetOnlyProperty_ThrowsArgumentException() { CompareAttribute attribute = new CompareAttribute(nameof(CompareObject.SetOnlyProperty)); Assert.Throws<ArgumentException>(null, () => attribute.Validate("b", s_context)); }
public static void Validate_Indexer_ThrowsTargetParameterCountException() { CompareAttribute attribute = new CompareAttribute("Item"); Assert.Throws<TargetParameterCountException>(() => attribute.Validate("b", s_context)); }
public static void Validate_PrivateProperty_ThrowsArgumentException() { CompareAttribute attribute = new CompareAttribute("PrivateProperty"); Assert.Throws <ValidationException>(() => attribute.Validate("b", s_context)); }