예제 #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_HolidayRequest_When_Validate_Then_ExpectedOutcome(
            RegisterHolidayRequestInputDto input,
            bool holidayRequestRepoResult,
            bool isValid,
            List <string> errors)
        {
            errors = errors ?? new List <string>();
            // Arrange
            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(holidayRequestRepoResult);

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

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

            // Assert
            Assert.Equal(isValid, actual.IsValid);
            Assert.Equal(errors.Count, actual.Errors.Count);
            for (var i = 0; i < errors.Count; i++)
            {
                Assert.Equal(errors[i], actual.Errors[i].ErrorMessage);
            }
        }
예제 #6
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));
        }