public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel() { //Arrange var customer = MockCustomerFactory.CreateRandom(); var mockedCustomerRepository = new Mock <ICustomerRepository>(); mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.IsAny <GetCustomerByIdParam>())) .ReturnsAsync(customer); _container.Use(mockedCustomerRepository); var customerViewService = _container.CreateInstance <CustomerAddressViewService>(); //Act var param = new GetCreateAddressViewModelAsyncParam { Scope = GetRandom.String(32), CustomerId = Guid.NewGuid(), CultureInfo = TestingExtensions.GetRandomCulture(), CountryCode = GetRandom.String(2), }; var viewModel = await customerViewService.GetCreateAddressViewModelAsync(param); //Assert viewModel.Should().NotBeNull("This view model should never be null"); viewModel.CountryCode.ShouldBeEquivalentTo(param.CountryCode); viewModel.FirstName.ShouldBeEquivalentTo(customer.FirstName); viewModel.LastName.ShouldBeEquivalentTo(customer.LastName); viewModel.PhoneNumber.ShouldBeEquivalentTo(customer.PhoneNumber); }
public void WHEN_CustomerId_is_Null_SHOULD_throw_ArgumentException() { //Arrange var customerAddressViewService = _container.CreateInstance <CustomerAddressViewService>(); var param = new GetCreateAddressViewModelAsyncParam { Scope = GetRandom.String(32), CultureInfo = TestingExtensions.GetRandomCulture(), CountryCode = GetRandom.String(2), }; //Act var ex = Assert.ThrowsAsync <ArgumentException>(() => customerAddressViewService.GetCreateAddressViewModelAsync(param)); //Assert ex.Message.Should().ContainEquivalentOf("CustomerId"); }
/// <summary> /// Gets the <see cref="EditAddressViewModel"/> for the creation of an address for a specified customer id. /// </summary> /// <param name="param"></param> /// <returns></returns> public virtual async Task <EditAddressViewModel> GetCreateAddressViewModelAsync(GetCreateAddressViewModelAsyncParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.CountryCode)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CountryCode)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } var customer = await CustomerRepository.GetCustomerByIdAsync(new GetCustomerByIdParam { CustomerId = param.CustomerId, CultureInfo = param.CultureInfo, Scope = param.Scope }).ConfigureAwait(false); var newAddressWithDefaultValues = new Address { FirstName = customer.FirstName, LastName = customer.LastName, PhoneNumber = customer.PhoneNumber, PhoneExtension = customer.PhoneExtension, Email = customer.Email, CountryCode = param.CountryCode }; return(await GetEditAddressViewModel(new GetEditAddressViewModelParam { Address = newAddressWithDefaultValues, IsUpdating = false, CultureInfo = param.CultureInfo }).ConfigureAwait(false)); }