Ejemplo n.º 1
0
        public void Validate_WhenCalled_ReturnsValidator()
        {
            IUpdateCountryCommand sut = CreateSut();

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

            Assert.That(result, Is.EqualTo(_validatorMockContext.ValidatorMock.Object));
        }
Ejemplo n.º 2
0
        public void Validate_WhenContactRepositoryIsNull_ThrowsArgumentNullException()
        {
            IUpdateCountryCommand 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_AssertUpdateCountryAsyncWasCalledOnContactRepository()
        {
            CommandHandler sut = CreateSut();

            ICountry country = _fixture.BuildCountryMock().Object;
            IUpdateCountryCommand command = CreateCommandMock(country).Object;
            await sut.ExecuteAsync(command);

            _contactRepositoryMock.Verify(m => m.UpdateCountryAsync(It.Is <ICountry>(value => value == country)), Times.Once);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UpdateCountry(CountryViewModel countryViewModel)
        {
            NullGuard.NotNull(countryViewModel, nameof(countryViewModel));

            if (ModelState.IsValid == false)
            {
                return(View("UpdateCountry", countryViewModel));
            }

            IUpdateCountryCommand command = _contactViewModelConverter.Convert <CountryViewModel, UpdateCountryCommand>(countryViewModel);
            await _commandBus.PublishAsync(command);

            return(RedirectToAction("Countries", "Contact"));
        }
Ejemplo n.º 5
0
        public void Validate_WhenCalled_AssertShouldBeKnownValueWasCalledOnObjectValidator()
        {
            string countryCode        = _fixture.Create <string>();
            IUpdateCountryCommand sut = CreateSut(countryCode);

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

            _validatorMockContext.ObjectValidatorMock.Verify(m => m.ShouldBeKnownValue(
                                                                 It.Is <string>(value => string.CompareOrdinal(value, countryCode.ToUpper()) == 0),
                                                                 It.IsNotNull <Func <string, Task <bool> > >(),
                                                                 It.Is <Type>(value => sut.GetType() == value),
                                                                 It.Is <string>(value => string.Compare(value, "CountryCode", StringComparison.Ordinal) == 0),
                                                                 It.Is <bool>(value => value == false)),
                                                             Times.Once());
        }
 public IActionResult Put(int id, [FromBody] CountryDto dto, [FromServices] IUpdateCountryCommand command)
 {
     dto.Id = id;
     executor.ExecuteCommand(command, dto);
     return(StatusCode(StatusCodes.Status204NoContent));
 }
Ejemplo n.º 7
0
 public IActionResult Put(int id, [FromBody] CountryDto dto, [FromServices] IUpdateCountryCommand command)
 {
     dto.Id = id;
     _executor.ExecuteCommand(command, dto);
     return(NoContent());
 }