コード例 #1
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));
        }
コード例 #2
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));
        }
コード例 #3
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);
        }