Exemple #1
0
        public void Validate_WhenCalled_ReturnsValidator()
        {
            IUpdateLetterHeadCommand sut = CreateSut();

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

            Assert.That(result, Is.EqualTo(_validatorMockContext.ValidatorMock.Object));
        }
Exemple #2
0
        public void Validate_WhenCommonRepositoryIsNull_ThrowsArgumentNullException()
        {
            IUpdateLetterHeadCommand sut = CreateSut();

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

            Assert.That(result.ParamName, Is.EqualTo("commonRepository"));
        }
Exemple #3
0
        public async Task ExecuteAsync_WhenCalled_AssertUpdateLetterHeadAsyncWasCalledOnCommonRepository()
        {
            CommandHandler sut = CreateSut();

            ILetterHead letterHead           = _fixture.BuildLetterHeadMock().Object;
            IUpdateLetterHeadCommand command = CreateCommandMock(letterHead).Object;
            await sut.ExecuteAsync(command);

            _commonRepositoryMock.Verify(m => m.UpdateLetterHeadAsync(It.Is <ILetterHead>(value => value == letterHead)), Times.Once);
        }
Exemple #4
0
        public async Task <IActionResult> UpdateLetterHead(LetterHeadViewModel letterHeadViewModel)
        {
            NullGuard.NotNull(letterHeadViewModel, nameof(letterHeadViewModel));

            if (ModelState.IsValid == false)
            {
                return(View("UpdateLetterHead", letterHeadViewModel));
            }

            IUpdateLetterHeadCommand command = _commonViewModelConverter.Convert <LetterHeadViewModel, UpdateLetterHeadCommand>(letterHeadViewModel);
            await _commandBus.PublishAsync(command);

            return(RedirectToAction("LetterHeads", "Common"));
        }
Exemple #5
0
        public void Validate_WhenCalled_AssertShouldBeKnownValueWasCalledOnObjectValidator()
        {
            int number = _fixture.Create <int>();
            IUpdateLetterHeadCommand sut = CreateSut(number);

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

            _validatorMockContext.ObjectValidatorMock.Verify(m => m.ShouldBeKnownValue(
                                                                 It.Is <int>(value => value == number), It.IsNotNull <Func <int, Task <bool> > >(),
                                                                 It.Is <Type>(value => sut.GetType() == value),
                                                                 It.Is <string>(value => string.Compare(value, "Number", StringComparison.Ordinal) == 0),
                                                                 It.Is <bool>(value => value == false)),
                                                             Times.Once());
        }