コード例 #1
0
        public async Task ValidSerialNumber_NotEligiable()
        {
            // Arrange
            var validSerialNumber = "I Am a Serial Number";
            var request           = _fixture.Build <EnterCompetition>()
                                    .With(x => x.SerialNumber, validSerialNumber)
                                    .Create();
            var productServiceMock = new Mock <IProductService>();

            productServiceMock.Setup(x => x.IsSerialNumberValid(validSerialNumber)).ReturnsAsync(true);
            var competitionRepoMock = new Mock <ICompetitionRepository>();

            competitionRepoMock.Setup(x => x.IsSerialNumberEligible(validSerialNumber)).ReturnsAsync(false);
            var validator = new EnterCompetitionValidator(productServiceMock.Object, competitionRepoMock.Object);

            // Act
            var result = await validator.TestValidateAsync(request);

            // Assert
            result.ShouldHaveValidationErrorFor(x => x.SerialNumber).WithErrorMessage("Serial number is no longer eligiable to enter draw.");
        }
コード例 #2
0
        public async Task NoValidationErrors()
        {
            // Arrange
            var request = _fixture.Build <EnterCompetition>()
                          .With(x => x.Email, "*****@*****.**")
                          .With(x => x.AcceptsTerms, true)
                          .With(x => x.ConfirmsCorrectAge, true)
                          .Create();
            var productServiceMock = new Mock <IProductService>();

            productServiceMock.Setup(x => x.IsSerialNumberValid(request.SerialNumber)).ReturnsAsync(true);
            var competitionRepoMock = new Mock <ICompetitionRepository>();

            competitionRepoMock.Setup(x => x.IsSerialNumberEligible(request.SerialNumber)).ReturnsAsync(true);
            var validator = new EnterCompetitionValidator(productServiceMock.Object, competitionRepoMock.Object);

            // Act
            var result = await validator.TestValidateAsync(request);

            // Assert
            result.ShouldNotHaveAnyValidationErrors();
        }