public void Validate_WhenCalled_ReturnsValidator()
        {
            ICreatePostalCodeCommand sut = CreateSut();

            IValidator result = sut.Validate(_validatorMockContext.ValidatorMock.Object, _contactRepositoryMock.Object);

            Assert.That(result, Is.EqualTo(_validatorMockContext.ValidatorMock.Object));
        }
        public void Validate_WhenContactRepositoryIsNull_ThrowsArgumentNullException()
        {
            ICreatePostalCodeCommand sut = CreateSut();

            ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.Validate(_validatorMockContext.ValidatorMock.Object, null));

            Assert.That(result.ParamName, Is.EqualTo("contactRepository"));
        }
        public async Task ExecuteAsync_WhenCalled_AssertCreatePostalCodeAsyncWasCalledOnContactRepository()
        {
            CommandHandler sut = CreateSut();

            IPostalCode postalCode           = _fixture.BuildPostalCodeMock().Object;
            ICreatePostalCodeCommand command = CreateCommandMock(postalCode).Object;
            await sut.ExecuteAsync(command);

            _contactRepositoryMock.Verify(m => m.CreatePostalCodeAsync(It.Is <IPostalCode>(value => value == postalCode)), Times.Once);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CreatePostalCode(PostalCodeViewModel postalCodeViewModel)
        {
            NullGuard.NotNull(postalCodeViewModel, nameof(postalCodeViewModel));

            if (ModelState.IsValid == false)
            {
                return(View("CreatePostalCode", postalCodeViewModel));
            }

            ICreatePostalCodeCommand command = _contactViewModelConverter.Convert <PostalCodeViewModel, CreatePostalCodeCommand>(postalCodeViewModel);
            await _commandBus.PublishAsync(command);

            return(RedirectToAction("PostalCodes", "Contact"));
        }
        public void Validate_WhenCalled_AssertShouldBeUnknownValueWasCalledOnObjectValidator()
        {
            string postalCode            = _fixture.Create <string>();
            ICreatePostalCodeCommand sut = CreateSut(postalCode);

            sut.Validate(_validatorMockContext.ValidatorMock.Object, _contactRepositoryMock.Object);

            _validatorMockContext.ObjectValidatorMock.Verify(m => m.ShouldBeUnknownValue(
                                                                 It.Is <string>(value => string.CompareOrdinal(value, postalCode) == 0),
                                                                 It.IsNotNull <Func <string, Task <bool> > >(),
                                                                 It.Is <Type>(value => sut.GetType() == value),
                                                                 It.Is <string>(value => string.CompareOrdinal(value, "PostalCode") == 0),
                                                                 It.Is <bool>(value => value == false)),
                                                             Times.Once());
        }