public void WhenHelperReturnsNoMessage_FallbackMessageIsSet(string nullOrEmptyString, string fallBackMessage) { // arrange var mockService = new Mock <IValidationMessageService>(); mockService.Setup(ms => ms.GetValue(It.IsAny <string>(), It.IsAny <string>())).Returns(nullOrEmptyString); DependencyResolverHelper.SetValidationMessageServiceIntoResolver(mockService); // act var validator = new RequiredAttribute(); validator.Initialise("asdf", "asefasdf", fallBackMessage); // can be any validation attribute // assert Assert.AreEqual(fallBackMessage, validator.ErrorMessage); }
public void WhenNoMessage_DefaultAttributeMessageIsSet_UmbracoValidators(Type type) { // arrange var mockService = new Mock <IValidationMessageService>(); mockService.Setup(ms => ms.GetValue(It.IsAny <string>(), It.IsAny <string>())).Returns(string.Empty); DependencyResolverHelper.SetValidationMessageServiceIntoResolver(mockService); var testInstance = AttributeGeneratorHelper.IntialiseAttribute(type); var controlInstance = AttributeGeneratorHelper.IntialiseAttribute(type); // act testInstance.Initialise("asdf", "asefasdf", string.Empty); // can be any validation attribute // assert Assert.AreEqual(controlInstance.ErrorMessage, testInstance.ErrorMessage); }
public void WhenHelperReturnsMessage_AttributeMessageIsSet() { // arrange var serviceMessage = "I'm the service message"; var mockService = new Mock <IValidationMessageService>(); mockService.Setup(ms => ms.GetValue(It.IsAny <string>(), It.IsAny <string>())).Returns(serviceMessage); DependencyResolverHelper.SetValidationMessageServiceIntoResolver(mockService); // act var validator = new RequiredAttribute(); validator.Initialise("asdf", "asefasdf"); // can be any validation attribute // assert Assert.AreEqual(serviceMessage, validator.ErrorMessage); }
public void WhenMessageServiceReturnsNamedValue_ValidationMessageIsSet() { // arrange string validationMessage = "This is the correct message"; // message service var mockService = new Mock <IValidationMessageService>(); mockService.Setup(ms => ms.GetValue(It.IsAny <string>(), string.Empty)).Returns(validationMessage); DependencyResolverHelper.SetValidationMessageServiceIntoResolver(mockService); // Act var requiredAttribute = new UmbracoRequiredAttribute("asdf"); // Assert Assert.AreEqual(validationMessage, requiredAttribute.ErrorMessage); }
public void WhenMessageServiceReturnsEmptyValue_DefaultValidatorMessageIsSet() { // arrange string validationMessage = string.Empty; string defaultKeyValidationMessage = string.Empty; // message service var mockService = new Mock <IValidationMessageService>(); mockService.Setup(ms => ms.GetValue(It.IsAny <string>(), string.Empty)).Returns(validationMessage); DependencyResolverHelper.SetValidationMessageServiceIntoResolver(mockService); // Act var requiredAttribute = new UmbracoRequiredAttribute("asdf", "adsfasdf"); var standardRequiredAttribute = new RequiredAttribute(); // Assert Assert.IsNotEmpty(requiredAttribute.ErrorMessage); Assert.AreEqual(standardRequiredAttribute.ErrorMessage, requiredAttribute.ErrorMessage); }