public async Task Validate_Given_Invalid_EventSeriesId_Validator_Is_Invalid(int value)
        {
            // Arrange
            var validId              = 1;
            var validTitle           = "This is a valid title.";
            var validDescription     = "This is a valid Description";
            var validStartDate       = new DateTime(2020, 3, 1);
            var validEndDate         = new DateTime(2020, 3, 2);
            var validRegStartDate    = new DateTime(2020, 2, 3);
            var validRegEndDate      = new DateTime(2020, 2, 4);
            var validMaxRegs         = 10;
            var inValidEventTypeId   = 0;
            var inValidEventSeriesId = value;
            var command              = new UpdateEventCommand
            {
                Id            = validId,
                Title         = validTitle,
                Description   = validDescription,
                StartDate     = validStartDate,
                EndDate       = validEndDate,
                RegStartDate  = validRegStartDate,
                RegEndDate    = validRegEndDate,
                MaxRegsCount  = validMaxRegs,
                EventTypeId   = inValidEventTypeId,
                EventSeriesId = inValidEventSeriesId
            };
            var validator = new UpdateEventCommandValidator(new DateTimeTestProvider()); // manually invoke to test the Validator

            // Act/Assert
            var result = await validator.ValidateAsync(command);

            Assert.False(result.IsValid);
            Assert.Contains(result.Errors, x => x.PropertyName == "EventSeriesId");
        }
        public async Task Handle_Given_MaxRegs_Zero_Throws_ValidattionException()
        {
            // Arrange
            var validId           = 1;
            var validTitle        = "This is a valid title.";
            var validDescription  = "This is a valid Description";
            var validStartDate    = new DateTime(2020, 3, 1);
            var validEndDate      = new DateTime(2020, 3, 2);
            var validRegStartDate = new DateTime(2020, 2, 3);
            var validRegEndDate   = new DateTime(2020, 2, 4);
            var inValidMaxRegs    = 0;
            var validEventTypeId  = 1;
            var command           = new UpdateEventCommand
            {
                Id           = validId,
                Title        = validTitle,
                Description  = validDescription,
                StartDate    = validStartDate,
                EndDate      = validEndDate,
                RegStartDate = validRegStartDate,
                RegEndDate   = validRegEndDate,
                MaxRegsCount = inValidMaxRegs,
                EventTypeId  = validEventTypeId
            };
            var validator = new UpdateEventCommandValidator(new DateTimeTestProvider()); // manually invoke to test the Validator

            // Act/Assert
            var result = await validator.ValidateAsync(command);

            var ex = await Assert.ThrowsAsync <ValidationException>(() => _sut.Handle(command, CancellationToken.None));

            Assert.False(result.IsValid);
            Assert.Contains(result.Errors, x => x.PropertyName == "MaxRegsCount");
        }
        public async Task Validate_Given_Invalid_City_Validator_Is_Invalid(string value)
        {
            // Arrange
            var validId           = 1;
            var validTitle        = "Event Created from Unit Tests.";
            var validDescription  = "This event was created from a Unit Test.";
            var validStartDate    = new DateTime(2020, 3, 3);
            var validEndDate      = new DateTime(2020, 3, 4);
            var validRegStartDate = new DateTime(2020, 2, 1);
            var validRegEndDate   = new DateTime(2020, 2, 2);
            var validMaxRegs      = 10;
            var validEventTypeId  = 1;
            var validStreet       = "123 Anywhere St.";
            var validSuite        = "Room #3";
            var inValidCity       = value;
            var validState        = "MD";
            var validZip          = "12345";

            var command = new UpdateEventCommand
            {
                Id           = validId,
                Title        = validTitle,
                Description  = validDescription,
                StartDate    = validStartDate,
                EndDate      = validEndDate,
                RegStartDate = validRegStartDate,
                RegEndDate   = validRegEndDate,
                MaxRegsCount = validMaxRegs,
                EventTypeId  = validEventTypeId,
                Street       = validStreet,
                Suite        = validSuite,
                City         = inValidCity,
                State        = validState,
                Zip          = validZip
            };
            var validator = new UpdateEventCommandValidator(new DateTimeTestProvider());

            // Act/Assert
            var result = await validator.ValidateAsync(command);

            Assert.False(result.IsValid);
            Assert.Equal(1, result.Errors.Count);
            Assert.Contains(result.Errors, x => x.PropertyName == "City");
        }
        public async Task Validate_Given_Valid_Zip_Validator_Is_Valid(string value)
        {
            // Arrange
            var validId           = 1;
            var validTitle        = "Event Created from Unit Tests.";
            var validDescription  = "This event was created from a Unit Test.";
            var validStartDate    = new DateTime(2020, 3, 3);
            var validEndDate      = new DateTime(2020, 3, 4);
            var validRegStartDate = new DateTime(2020, 2, 1);
            var validRegEndDate   = new DateTime(2020, 2, 2);
            var validMaxRegs      = 10;
            var validEventTypeId  = 1;
            var validStreet       = "123 Anywhere St.";
            var validSuite        = "Room #3";
            var validCity         = "Yourtown";
            var validState        = "MD";
            var validZip          = value;

            var command = new UpdateEventCommand
            {
                Id           = validId,
                Title        = validTitle,
                Description  = validDescription,
                StartDate    = validStartDate,
                EndDate      = validEndDate,
                RegStartDate = validRegStartDate,
                RegEndDate   = validRegEndDate,
                MaxRegsCount = validMaxRegs,
                EventTypeId  = validEventTypeId,
                Street       = validStreet,
                Suite        = validSuite,
                City         = validCity,
                State        = validState,
                Zip          = validZip
            };
            var validator = new UpdateEventCommandValidator(new DateTimeTestProvider());

            // Act/Assert
            var result = await validator.ValidateAsync(command);

            Assert.True(result.IsValid);
        }
        public async Task Handle_Given_Invalid_Title_Throws_ValidationException(string value)
        {
            // Arrange
            var validId           = 1;
            var inValidTitle      = value;
            var validDescription  = "This event was created from a Unit Test.";
            var validStartDate    = new DateTime(2020, 3, 1);
            var validEndDate      = new DateTime(2020, 3, 2);
            var validRegStartDate = new DateTime(2020, 2, 1);
            var validRegEndDate   = new DateTime(2020, 2, 2);
            var validMaxRegs      = 10;
            var validEventTypeId  = 1;
            var command           = new UpdateEventCommand
            {
                Id           = validId,
                Title        = inValidTitle,
                Description  = validDescription,
                StartDate    = validStartDate,
                EndDate      = validEndDate,
                RegStartDate = validRegStartDate,
                RegEndDate   = validRegEndDate,
                MaxRegsCount = validMaxRegs,
                EventTypeId  = validEventTypeId
            };
            var validator = new UpdateEventCommandValidator(new DateTimeTestProvider()); // manually invoke to test the Validator

            // Act/Assert
            var result = await validator.ValidateAsync(command);

            var ex = await Assert.ThrowsAsync <ValidationException>(() => _sut.Handle(command, CancellationToken.None));

            Assert.Equal(1, ex.Failures.Count);
            Assert.False(result.IsValid);
            Assert.Equal(1, result.Errors.Count);
            Assert.Contains(result.Errors, x => x.PropertyName == "Title");
        }