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.Is <GetCustomerByIdParam>(p => p.CustomerId == customer.Id))) .ReturnsAsync(customer); _container.Use(mockedCustomerRepository); var param = new GetAccountHeaderViewModelParam { CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = customer.Id, Scope = GetRandom.String(32) }; var customerViewService = _container.CreateInstance <CustomerViewService>(); //Act var viewModel = await customerViewService.GetAccountHeaderViewModelAsync(param); //Assert viewModel.Should().NotBeNull("This view model should never be null"); viewModel.FirstName.Should().Be(customer.FirstName); viewModel.LastName.Should().Be(customer.LastName); }
public void WHEN_CustomerId_is_Null_SHOULD_throw_ArgumentException() { //Arrange var customerViewService = _container.CreateInstance <CustomerViewService>(); var param = new GetAccountHeaderViewModelParam { CultureInfo = TestingExtensions.GetRandomCulture(), Scope = GetRandom.String(32) }; //Act var ex = Assert.ThrowsAsync <ArgumentException>(() => customerViewService.GetAccountHeaderViewModelAsync(param)); //Assert ex.Message.Should().ContainEquivalentOf("Customer"); }
/// <summary> /// Gets the <see cref="AccountHeaderViewModel"/> to greet a given Customer. /// </summary> /// <param name="param">Builder params <see cref="GetAccountHeaderViewModelParam"/></param> /// <returns></returns> public async virtual Task <AccountHeaderViewModel> GetAccountHeaderViewModelAsync(GetAccountHeaderViewModelParam 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.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } var customer = await CustomerRepository.GetCustomerByIdAsync(new GetCustomerByIdParam { CultureInfo = param.CultureInfo, CustomerId = param.CustomerId, Scope = param.Scope }).ConfigureAwait(false); var accountHeaderViewModel = ViewModelMapper.MapTo <AccountHeaderViewModel>(customer, param.CultureInfo); return(accountHeaderViewModel); }