public void ValidationResultsShouldHaveCorrectResultMessage()
        {
            // Arrange

            var validationResults = new ValidationResults();


            // Act

            validationResults.AddValidationResult("Test", "Test message with property: {0}");
            validationResults.AddValidationResult("Test2", "Test message 2 with property: {0}");

            // Assert

            validationResults.GetMessages().Should().Be("Test message with property: Test\r\nTest message 2 with property: Test2");
        }
 public static void ValidateNotNull(this ValidationResults results, int property, string propertyName)
 {
     if (property == -1)
     {
         results.AddValidationResult(propertyName, "{0} cannot be null");
     }
 }
 public static void ValidateNotNullOrEmpty(this ValidationResults results, string property, string propertyName)
 {
     if (string.IsNullOrEmpty(property))
     {
         results.AddValidationResult(propertyName, "{0} cannot be null or empty");
     }
 }
 private ValidationResults ValidateIdNotNull(ValidationResults results, string id)
 {
     if (string.IsNullOrEmpty(id))
     {
         results.AddValidationResult(nameof(id), "{0} cannot be null or empty");
     }
     return(results);
 }
Beispiel #5
0
        public void ValidationExceptionShouldCorrectlyBeCreatedAndGetTheCorrectMessage()
        {
            // Arrange

            var validationResults = new ValidationResults();

            validationResults.AddValidationResult("test", "Testmessage with property {0}");
            validationResults.AddValidationResult("test2", "Testmessage2 with property {0}");

            // Act

            var exc = new ValidationException(validationResults);

            // Assert

            exc.Message.Should().Be("Testmessage with property test\r\nTestmessage2 with property test2");
        }
 private ValidationResults ValidateCompanyNameDoesntExist(ValidationResults results, AddCompanyWithOfficeCommand validatableObject)
 {
     if (_companyRepository.GetAll().Any(x => x.Name == validatableObject.CompanyName))
     {
         results.AddValidationResult(nameof(validatableObject.CompanyName), "{0} already exists.");
     }
     return(results);
 }
 private ValidationResults ValidateAddressAlreadyExists(ValidationResults results, AddCompanyWithOfficeCommand validatableObject)
 {
     if (_officeRepository.GetAll().Any(x => x.Street == validatableObject.Street && x.HouseNumber == validatableObject.HouseNumber && x.City == validatableObject.City))
     {
         results.AddValidationResult(nameof(validatableObject.CompanyName), "The adress already exists in the database.");
     }
     return(results);
 }
 private ValidationResults ValidateObjectWithNameExists(ValidationResults results, DeviceModel model)
 {
     if (string.IsNullOrEmpty(model.Id) && !string.IsNullOrEmpty(model.Name))
     {
         if (_deviceData.GetAll().Any(x => x.Name.Equals(model.Name)))
         {
             results.AddValidationResult(nameof(model.Name), "A devicemodel with this {0}, is already in the database.");
         }
     }
     else if (!string.IsNullOrEmpty(model.Id) && !string.IsNullOrEmpty(model.Name))
     {
         if (_deviceData.GetAll().Where(x => x.Id.ToString() != model.Id).Any(x => x.Name.Equals(model.Name)))
         {
             results.AddValidationResult(nameof(model.Name), "A devicemodel with this {0}, is already in the database.");
         }
     }
     return(results);
 }
Beispiel #9
0
 private ValidationResults ValidateObjectWithIdExists(ValidationResults results, string id)
 {
     if (!string.IsNullOrEmpty(id))
     {
         var device = _deviceData.Get(id);
         if (device == null)
         {
             results.AddValidationResult(nameof(id), "There is no object found with {0}");
         }
     }
     return(results);
 }
        public void QueryHandlerBaseWithNegativeValidatorShouldThrowValidationException()
        {
            // Arrange

            var validator         = new Mock <IValidator <TestQuery> >();
            var validationResults = new ValidationResults();

            validationResults.AddValidationResult("Test1", "Test message with property: {0}");
            validationResults.AddValidationResult("Test2", "Test message 2 with property: {0}");
            validator.Setup(x => x.Validate(It.IsAny <ValidationResults>(), It.IsAny <TestQuery>())).Returns(validationResults);
            var queryHandler = new TestQueryHandlerBaseClass(validator.Object);

            // Act

            Action act = () => queryHandler.Execute(new TestQuery());;

            // Assert

            act.Should().Throw <ValidationException>()
            .WithMessage("Test message with property: Test1\r\nTest message 2 with property: Test2");
        }