Ejemplo n.º 1
0
        public async Task UpdatePostalCode_WhenCalledWithValidModel_ReturnsRedirectToActionResult()
        {
            Controller sut = CreateSut();

            PostalCodeViewModel model  = CreateModel();
            IActionResult       result = await sut.UpdatePostalCode(model);

            Assert.That(result, Is.TypeOf <RedirectToActionResult>());
        }
Ejemplo n.º 2
0
        public async Task UpdatePostalCode_WhenCalledWithValidModel_ReturnsRedirectToActionResultWhereActionNameIsEqualToPostalCodes()
        {
            Controller sut = CreateSut();

            PostalCodeViewModel    model  = CreateModel();
            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdatePostalCode(model);

            Assert.That(result.ActionName, Is.EqualTo("PostalCodes"));
        }
Ejemplo n.º 3
0
        public async Task UpdatePostalCode_WhenCalledWithInvalidModel_AssertPublishAsyncWasNotCalledOnCommandBus()
        {
            Controller sut = CreateSut(modelIsValid: false);

            PostalCodeViewModel model = CreateModel();
            await sut.UpdatePostalCode(model);

            _commandBusMock.Verify(m => m.PublishAsync(It.IsAny <IUpdatePostalCodeCommand>()), Times.Never);
        }
Ejemplo n.º 4
0
        public async Task UpdatePostalCode_WhenCalledWithInvalidModel_ReturnsViewResultWhereViewNameIsEqualToUpdatePostalCode()
        {
            Controller sut = CreateSut(modelIsValid: false);

            PostalCodeViewModel model  = CreateModel();
            ViewResult          result = (ViewResult)await sut.UpdatePostalCode(model);

            Assert.That(result.ViewName, Is.EqualTo("UpdatePostalCode"));
        }
        public async Task CreatePostalCode_WhenCalledWithInvalidModel_ReturnsViewResult()
        {
            Controller sut = CreateSut(modelIsValid: false);

            PostalCodeViewModel model  = CreateModel();
            IActionResult       result = await sut.CreatePostalCode(model);

            Assert.That(result, Is.TypeOf <ViewResult>());
        }
Ejemplo n.º 6
0
        public async Task UpdatePostalCode_WhenCalledWithInvalidModel_ReturnsViewResultWhereModelIsEqualToInvalidModel()
        {
            Controller sut = CreateSut(modelIsValid: false);

            PostalCodeViewModel model  = CreateModel();
            ViewResult          result = (ViewResult)await sut.UpdatePostalCode(model);

            Assert.That(result.Model, Is.TypeOf <PostalCodeViewModel>());

            PostalCodeViewModel postalCodeViewModel = (PostalCodeViewModel)result.Model;

            Assert.That(postalCodeViewModel, Is.EqualTo(model));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> UpdatePostalCode(string countryCode, string postalCode)
        {
            NullGuard.NotNullOrWhiteSpace(countryCode, nameof(countryCode))
            .NotNullOrWhiteSpace(postalCode, nameof(postalCode));

            IPostalCode postalCodeObj = await GetPostalCode(countryCode, postalCode);

            PostalCodeViewModel postalCodeViewModel = _contactViewModelConverter.Convert <IPostalCode, PostalCodeViewModel>(postalCodeObj);

            postalCodeViewModel.EditMode = EditMode.Edit;

            return(View("UpdatePostalCode", postalCodeViewModel));
        }
Ejemplo n.º 8
0
        public async Task UpdatePostalCode_WhenCalledWithValidModel_AssertPublishAsyncWasCalledOnCommandBus()
        {
            Controller sut = CreateSut();

            PostalCodeViewModel model = CreateModel();
            await sut.UpdatePostalCode(model);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdatePostalCodeCommand>(command =>
                                                                                        string.CompareOrdinal(command.CountryCode, model.Country.Code.ToUpper()) == 0 &&
                                                                                        string.CompareOrdinal(command.PostalCode, model.Code) == 0 &&
                                                                                        string.CompareOrdinal(command.City, model.City) == 0 &&
                                                                                        string.CompareOrdinal(command.State, model.State) == 0)),
                                   Times.Once);
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> UpdatePostalCode(PostalCodeViewModel postalCodeViewModel)
        {
            NullGuard.NotNull(postalCodeViewModel, nameof(postalCodeViewModel));

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

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

            return(RedirectToAction("PostalCodes", "Contact"));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> CreatePostalCode(string countryCode)
        {
            NullGuard.NotNullOrWhiteSpace(countryCode, nameof(countryCode));

            ICountry country = await GetCountry(countryCode);

            if (country == null)
            {
                return(RedirectToAction("PostalCodes", "Contact"));
            }

            PostalCodeViewModel postalCodeViewModel = new PostalCodeViewModel
            {
                Country  = _contactViewModelConverter.Convert <ICountry, CountryViewModel>(country),
                EditMode = EditMode.Create
            };

            return(View("CreatePostalCode", postalCodeViewModel));
        }
Ejemplo n.º 11
0
        public JsonResult GetPostalCodeData(string postalCode)
        {
            PostalCodeViewModel model = new PostalCodeViewModel();
            var postalCodeData        = controller.GetPostalCode(postalCode);

            if (postalCodeData == null)
            {
                return(Json(model.Error = "ZIP code data Not Found", JsonRequestBehavior.AllowGet));
            }
            model.Address.AddressPostalCodeId   = postalCodeData.Id;
            model.Address.AddressStateId        = postalCodeData.AddressStateId;
            model.Address.AddressMunicipalityId = postalCodeData.AddressMunicipalityId;
            model.AvailableColonies             = controller.GetAvailableColoniesByPostalCode(postalCodeData.Id).Select(x => new AvailableColoniesViewModel {
                Id = x.Id, Name = x.Name
            }).ToList();
            model.MunicipalityName = GetMunicipalityName(postalCodeData.AddressMunicipalityId);
            model.StateName        = GetStateName(postalCodeData.AddressStateId);

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
        public async Task CreatePostalCode_WhenCalledWithKnownCountryCode_ReturnsViewResultWhereModelIsPostalCodeViewModel()
        {
            string     countryCode = _fixture.Create <string>();
            ICountry   country     = _fixture.BuildCountryMock(countryCode).Object;
            Controller sut         = CreateSut(country: country);

            ViewResult result = (ViewResult)await sut.CreatePostalCode(countryCode);

            Assert.That(result.Model, Is.TypeOf <PostalCodeViewModel>());

            PostalCodeViewModel postalCodeViewModel = (PostalCodeViewModel)result.Model;

            Assert.That(postalCodeViewModel, Is.Not.Null);
            Assert.That(postalCodeViewModel.Country, Is.Not.Null);
            Assert.That(postalCodeViewModel.Country.Code, Is.EqualTo(countryCode));
            Assert.That(postalCodeViewModel.Code, Is.Null);
            Assert.That(postalCodeViewModel.City, Is.Null);
            Assert.That(postalCodeViewModel.State, Is.Null);
            Assert.That(postalCodeViewModel.EditMode, Is.EqualTo(EditMode.Create));
        }
Ejemplo n.º 13
0
        public async Task UpdatePostalCode_WhenCalledWithCountryCodeAndPostalCode_ReturnsViewResultWhereModelIsPostalCodeViewModel()
        {
            string      countryCode   = _fixture.Create <string>();
            string      postalCode    = _fixture.Create <string>();
            string      city          = _fixture.Create <string>();
            string      state         = _fixture.Create <string>();
            ICountry    country       = _fixture.BuildCountryMock(countryCode).Object;
            IPostalCode postalCodeObj = _fixture.BuildPostalCodeMock(country, postalCode, city, state).Object;
            Controller  sut           = CreateSut(postalCodeObj);

            ViewResult result = (ViewResult)await sut.UpdatePostalCode(_fixture.Create <string>(), _fixture.Create <string>());

            Assert.That(result.Model, Is.TypeOf <PostalCodeViewModel>());

            PostalCodeViewModel postalCodeViewModel = (PostalCodeViewModel)result.Model;

            Assert.That(postalCodeViewModel, Is.Not.Null);
            Assert.That(postalCodeViewModel.Country, Is.Not.Null);
            Assert.That(postalCodeViewModel.Country.Code, Is.EqualTo(countryCode));
            Assert.That(postalCodeViewModel.Code, Is.EqualTo(postalCode));
            Assert.That(postalCodeViewModel.City, Is.EqualTo(city));
            Assert.That(postalCodeViewModel.State, Is.EqualTo(state));
            Assert.That(postalCodeViewModel.EditMode, Is.EqualTo(EditMode.Edit));
        }