예제 #1
0
        public void Given_HolidayTypeAndOtherwiseValidRequest_When_Validate_Then_ExpectedOutcome(string holidayType, bool expected)
        {
            // Arrange
            var builder = new RegisterHolidayRequestInputDtoBuilder();
            var input   = builder
                          .WithOneWeekOffInTheFuture()
                          .WithHolidayType(holidayType)
                          .Build();

            var holidayTypeRepoMock = new Mock <IHolidayTypeRepository>();

            holidayTypeRepoMock
            .Setup(x => x.ExistsByKey(It.IsAny <string>()))
            .Returns(false);
            holidayTypeRepoMock
            .Setup(x => x.ExistsByKey(It.Is <string>(s => s == "N")))
            .Returns(true);
            var holidayRequestRepoMock = new Mock <IHolidayRequestRepository>();

            holidayRequestRepoMock
            .Setup(x => x.ExistsByToAndFrom(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <long>()))
            .Returns(false);

            var sut = new RegisterHolidayRequestInputDtoValidator(
                holidayTypeRepoMock.Object,
                holidayRequestRepoMock.Object);

            // Act
            var actual = sut.Validate(input);

            // Assert
            Assert.Equal(expected, actual.IsValid);
        }
예제 #2
0
        public void Given_DefaultRequestWithHolidayTypeAndNullHolidayTypeRepository_When_Validate_Then_ThrowsNullReference()
        {
            // Arrange
            var builder = new RegisterHolidayRequestInputDtoBuilder();
            var input   = builder
                          .WithHolidayType("N")
                          .Build();
            var sut = new RegisterHolidayRequestInputDtoValidator(null, null);

            // Act+Assert
            Assert.Throws <NullReferenceException>(() => sut.Validate(input));
        }
예제 #3
0
        public void Given_DefaultItem_When_Validate_Then_ThreeErrorMessages()
        {
            // Arrange
            var builder = new RegisterHolidayRequestInputDtoBuilder();
            var input   = builder
                          .Build();
            var sut = new RegisterHolidayRequestInputDtoValidator(null, null);

            // Act
            var actual = sut.Validate(input);

            // Assert
            Assert.Equal(3, actual.Errors.Count);
        }
예제 #4
0
        public void Given_DefaultItem_When_Validate_Then_IsValidFalse()
        {
            // Arrange
            var builder = new RegisterHolidayRequestInputDtoBuilder();
            var input   = builder
                          .Build();
            var sut = new RegisterHolidayRequestInputDtoValidator(null, null);

            // Act
            var actual = sut.Validate(input);

            // Assert
            Assert.False(actual.IsValid);
        }
예제 #5
0
        public void Given_DefaultRequestWithHolidayTypeAndMockHolidayTypeRepository_When_Validate_Then_IsValidFalseWith2Errors()
        {
            // Arrange
            var builder = new RegisterHolidayRequestInputDtoBuilder();
            var input   = builder
                          .WithHolidayType("N")
                          .Build();
            var holidayTypeRepoMock = new Mock <IHolidayTypeRepository>();

            holidayTypeRepoMock
            .Setup(x => x.ExistsByKey(It.IsAny <string>()))
            .Returns(true);
            var sut = new RegisterHolidayRequestInputDtoValidator(
                holidayTypeRepoMock.Object,
                null);

            // Act
            var actual = sut.Validate(input);

            // Assert
            Assert.False(actual.IsValid);
            Assert.Equal(2, actual.Errors.Count);
            holidayTypeRepoMock.Verify(x => x.ExistsByKey(It.IsAny <string>()), Times.Exactly(1));
        }
예제 #6
0
        public static TheoryData <RegisterHolidayRequestInputDto, bool, bool, List <string> > CreateComplexData()
        {
            var result = new TheoryData <RegisterHolidayRequestInputDto, bool, bool, List <string> >();

            var builder = new RegisterHolidayRequestInputDtoBuilder();

            result.Add(
                builder
                .WithOneWeekOffInTheFuture()
                .WithHolidayType("N")
                .Build(),
                false,
                true,
                null);

            builder = new RegisterHolidayRequestInputDtoBuilder();
            result.Add(
                builder
                .WithToDateInTheFuture()
                .WithHolidayType("N")
                .Build(),
                false,
                false,
                new List <string> {
                "From date is required."
            });

            builder = new RegisterHolidayRequestInputDtoBuilder();
            result.Add(
                builder
                .WithFromDateInTheFuture()
                .WithHolidayType("N")
                .Build(),
                false,
                false,
                new List <string> {
                "To date is required."
            });

            builder = new RegisterHolidayRequestInputDtoBuilder();
            result.Add(
                builder
                .WithHolidayType("N")
                .Build(),
                false,
                false,
                new List <string> {
                "From date is required.",
                "To date is required."
            });

            builder = new RegisterHolidayRequestInputDtoBuilder();
            result.Add(
                builder
                .WithOneWeekOffInTheFuture()
                .WithHolidayType("Daedalus")
                .Build(),
                false,
                false,
                new List <string> {
                "HolidayType is not a valid."
            });

            builder = new RegisterHolidayRequestInputDtoBuilder();
            result.Add(
                builder
                .WithOneWeekOffInTheFuture()
                .WithHolidayType("N")
                .WithRemarks(201)
                .Build(),
                false,
                false,
                new List <string> {
                "The length of 'Remarks' must be 200 characters or fewer. You entered 201 characters."
            });

            builder = new RegisterHolidayRequestInputDtoBuilder();
            result.Add(
                builder
                .WithToDateBeforeFromDateInTheFuture()
                .WithHolidayType("N")
                .Build(),
                false,
                false,
                new List <string> {
                "From date must be before To date."
            });

            builder = new RegisterHolidayRequestInputDtoBuilder();
            result.Add(
                builder
                .WithOneWeekOffInThePast()
                .WithHolidayType("N")
                .Build(),
                false,
                false,
                new List <string> {
                "From date must be before today."      // this message is wrong!
            });

            builder = new RegisterHolidayRequestInputDtoBuilder();
            result.Add(
                builder
                .WithOneWeekOffInTheFuture()
                .WithHolidayType("N")
                .Build(),
                true,
                false,
                new List <string> {
                "This holiday period is already registered for you."
            });

            return(result);
        }