internal static Mock <IViewModelMapper> CreateViewNullValues() { CartProductSummaryViewModel dummyCartProduct = new CartProductSummaryViewModel { DisplayName = null, }; LineItemDetailViewModel dummyLineItem = new LineItemDetailViewModel { ImageUrl = null, ProductId = null, VariantId = null, Total = null, DefaultListPrice = null, ListPrice = null, ProductSummary = null, FallbackImageUrl = null, IsOnSale = GetRandom.Boolean(), Quantity = GetRandom.PositiveInt(), }; TaxViewModel dummyTaxViewModel = new TaxViewModel { DisplayName = null, TaxTotal = null }; OrderSummaryViewModel dummyOrderSummary = new OrderSummaryViewModel { Shipping = null, SubTotal = null, Taxes = null, Total = null, DiscountTotal = null }; CartViewModel dummyCart = new CartViewModel { HomepageUrl = null, LineItemDetailViewModels = new List <LineItemDetailViewModel> { dummyLineItem }, OrderSummary = null, IsCartEmpty = GetRandom.Boolean(), TotalQuantity = GetRandom.PositiveInt(), LineItemCount = GetRandom.PositiveInt() }; RewardViewModel dummyReward = new RewardViewModel() { Description = null }; CouponViewModel dummyCoupons = new CouponViewModel() { CouponCode = null, DisplayText = null }; var viewModelMapper = new Mock <IViewModelMapper>(); viewModelMapper.Setup( mapper => mapper.MapTo <CartProductSummaryViewModel>(It.IsNotNull <CartProductSummary>(), It.IsNotNull <CultureInfo>())) .Returns(dummyCartProduct) .Verifiable(); viewModelMapper.Setup( mapper => mapper.MapTo <CartViewModel>(It.IsNotNull <Overture.ServiceModel.Orders.Cart>(), It.IsNotNull <CultureInfo>())) .Returns(dummyCart) .Verifiable(); viewModelMapper.Setup( mapper => mapper.MapTo <LineItemDetailViewModel>(It.IsNotNull <LineItem>(), It.IsNotNull <CultureInfo>())) .Returns(dummyLineItem) .Verifiable(); viewModelMapper.Setup( mapper => mapper.MapTo <OrderSummaryViewModel>(It.IsNotNull <Overture.ServiceModel.Orders.Cart>(), It.IsNotNull <CultureInfo>())) .Returns(dummyOrderSummary) .Verifiable(); viewModelMapper.Setup(mapper => mapper.MapTo <TaxViewModel>(It.IsNotNull <Tax>(), It.IsNotNull <CultureInfo>())) .Returns(dummyTaxViewModel) .Verifiable(); viewModelMapper.Setup(mapper => mapper.MapTo <RewardViewModel>(It.IsNotNull <Reward>(), It.IsNotNull <CultureInfo>())) .Returns(dummyReward) .Verifiable(); viewModelMapper.Setup(mapper => mapper.MapTo <CouponViewModel>(It.IsNotNull <Coupon>(), It.IsNotNull <CultureInfo>())) .Returns(dummyCoupons) .Verifiable(); return(viewModelMapper); }
public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel() { //Arrange var isAuthenticated = GetRandom.Boolean(); var firstName = GetRandom.String(32); var lastName = GetRandom.String(32); var cultureInfo = TestingExtensions.GetRandomCulture(); var composerContext = new Mock <IComposerContext>(); composerContext .SetupGet(c => c.IsAuthenticated) .Returns(isAuthenticated); _container.Use(composerContext); var customerRepository = new Mock <ICustomerRepository>(); customerRepository .Setup(c => c.GetCustomerByIdAsync(It.IsAny <GetCustomerByIdParam>())) .ReturnsAsync(new Customer { FirstName = firstName, LastName = lastName }); _container.Use(customerRepository); var expectedLoginUrl = _container.Get <IMyAccountUrlProvider>().GetLoginUrl(new BaseUrlParameter { CultureInfo = cultureInfo }); var expectedMyAccountUrl = _container.Get <IMyAccountUrlProvider>().GetMyAccountUrl(new BaseUrlParameter { CultureInfo = cultureInfo }); var membershipViewService = _container.CreateInstance <MembershipViewService>(); membershipViewService.Membership = _container.Get <IMembershipProxy>(); var getSignInHeaderParam = new GetSignInHeaderParam { Scope = GetRandom.String(32), CustomerId = GetRandom.Guid(), CultureInfo = cultureInfo, EncryptedCustomerId = GetRandom.String(64), IsAuthenticated = isAuthenticated }; //Act var viewModel = await membershipViewService.GetSignInHeaderModel(getSignInHeaderParam); //Assert viewModel.Should().NotBeNull("This view model should never be null"); viewModel.IsLoggedIn.Should().Be(isAuthenticated); if (isAuthenticated) { viewModel.Url.Should().Be(expectedMyAccountUrl, "Because logged in user are invited to their account"); } else { viewModel.Url.Should().Be(expectedLoginUrl, "Because logged out user are invited to log in"); } viewModel.FirstName.Should().Be(firstName); viewModel.LastName.Should().Be(lastName); }
public void SetUp() { _container = new AutoMocker(); var repoMock = _container.GetMock <IPaymentRepository>(); repoMock.Setup(repo => repo.UpdatePaymentMethodAsync(It.IsNotNull <UpdatePaymentMethodParam>())) .Returns((UpdatePaymentMethodParam p) => { var cart = new ProcessedCart { Name = p.CartName, CultureName = p.CultureInfo.Name, ScopeId = p.Scope, CustomerId = p.CustomerId, Payments = new List <Payment> { new Payment { Id = p.PaymentId, PaymentMethod = new PaymentMethod { Id = p.PaymentMethodId, PaymentProviderName = p.PaymentProviderName, Type = GetRandom.Enumeration <PaymentMethodType>(), DisplayName = new LocalizedString { { p.CultureInfo.Name, GetRandom.String(12) } }, Enabled = true, Default = GetRandom.Boolean(), }, PaymentStatus = PaymentStatus.New } } }; return(Task.FromResult(cart)); }).Verifiable("The repository was not called to Update the payment method."); repoMock.Setup(repo => repo.InitializePaymentAsync(It.IsNotNull <InitializePaymentParam>())) .Returns((InitializePaymentParam p) => { var cart = new Overture.ServiceModel.Orders.Cart { Name = p.CartName, CultureName = p.CultureInfo.Name, ScopeId = p.Scope, CustomerId = p.CustomerId, Payments = new List <Payment> { new Payment { Id = p.PaymentId, PaymentMethod = new PaymentMethod { Id = p.PaymentId, PaymentProviderName = GetRandom.String(12), Type = GetRandom.Enumeration <PaymentMethodType>(), DisplayName = new LocalizedString { { p.CultureInfo.Name, GetRandom.String(12) } }, Enabled = true, Default = GetRandom.Boolean(), PropertyBag = new PropertyBag { //TODO: Change this to reflect real return from OV. { "HostedCardTokenizationUrl", string.Format("https://{0}/?id={1}&css={2}", GetRandom.WwwUrl(), GetRandom.String(16), GetRandom.String(255)) } } }, PaymentStatus = PaymentStatus.New } } }; return(Task.FromResult(cart)); }).Verifiable("The repository was not called to initialize the Payment."); var vmMapperMock = _container.GetMock <IViewModelMapper>(); vmMapperMock.Setup( vmm => vmm.MapTo <ActivePaymentViewModel>(It.IsNotNull <Payment>(), It.IsNotNull <CultureInfo>())) .Returns((Payment p, CultureInfo ci) => { var vm = new ActivePaymentViewModel { Id = p.Id, PaymentStatus = p.PaymentStatus }; return(vm); }).Verifiable("The ViewModelMapper has not been called to create an ActivePaymentViewModel."); }
internal static Mock <IViewModelMapper> Create() { CartProductSummaryViewModel dummyCartProduct = new CartProductSummaryViewModel { DisplayName = GetRandom.String(32), }; TaxViewModel dummyTaxViewModel = new TaxViewModel { DisplayName = GetRandom.String(32), TaxTotal = GetRandom.Decimal(1.0m, 200.0m) }; LineItemDetailViewModel dummyLineItem = new LineItemDetailViewModel { ImageUrl = GetRandom.WwwUrl(), ProductId = GetRandom.String(32), VariantId = GetRandom.String(32), Total = GetRandom.PositiveDouble().ToString(CultureInfo.InvariantCulture), DefaultListPrice = GetRandom.PositiveDouble().ToString(CultureInfo.InvariantCulture), ListPrice = GetRandom.PositiveDouble().ToString(CultureInfo.InvariantCulture), ProductSummary = dummyCartProduct, FallbackImageUrl = GetRandom.WwwUrl(), IsOnSale = GetRandom.Boolean(), Quantity = GetRandom.PositiveInt(), }; OrderSummaryViewModel dummyOrderSummaryViewModel = new OrderSummaryViewModel { Shipping = GetRandom.String(32), SubTotal = GetRandom.String(32), Total = GetRandom.String(32), DiscountTotal = GetRandom.String(32), Taxes = new List <TaxViewModel> { dummyTaxViewModel } }; CartViewModel dummyCart = new CartViewModel { HomepageUrl = GetRandom.String(32), LineItemDetailViewModels = new List <LineItemDetailViewModel> { dummyLineItem }, OrderSummary = dummyOrderSummaryViewModel, IsCartEmpty = GetRandom.Boolean(), TotalQuantity = GetRandom.PositiveInt(), LineItemCount = GetRandom.PositiveInt() }; var rewardViewModel = new RewardViewModel() { Description = GetRandom.Phrase(40) }; var couponViewModel = new CouponViewModel() { CouponCode = GetRandom.String(7), DisplayText = GetRandom.Phrase(35) }; var viewModelMapper = new Mock <IViewModelMapper>(); viewModelMapper.Setup( mapper => mapper.MapTo <CartProductSummaryViewModel>(It.IsNotNull <CartProductSummary>(), It.IsNotNull <CultureInfo>())) .Returns(dummyCartProduct) .Verifiable(); viewModelMapper.Setup(mapper => mapper.MapTo <CartViewModel>(It.IsNotNull <Overture.ServiceModel.Orders.Cart>(), It.IsNotNull <CultureInfo>())) .Returns(dummyCart) .Verifiable(); viewModelMapper.Setup( mapper => mapper.MapTo <LineItemDetailViewModel>(It.IsNotNull <LineItem>(), It.IsNotNull <CultureInfo>())) .Returns(dummyLineItem) .Verifiable(); viewModelMapper.Setup(mapper => mapper.MapTo <TaxViewModel>(It.IsNotNull <Tax>(), It.IsNotNull <CultureInfo>())) .Returns(dummyTaxViewModel) .Verifiable(); viewModelMapper.Setup(mapper => mapper.MapTo <RewardViewModel>(It.IsNotNull <Reward>(), It.IsNotNull <CultureInfo>())) .Returns(rewardViewModel) .Verifiable(); viewModelMapper.Setup( mapper => mapper.MapTo <CouponViewModel>(It.IsNotNull <Coupon>(), It.IsNotNull <CultureInfo>())) .Returns(couponViewModel) .Verifiable(); return(viewModelMapper); }
public async Task WHEN_param_ok_and_cart_SHOULD_return_valid_viewModel() { //Arrange _container.Use(CartViewModelFactoryMock.MockGetPaymentMethodViewModel()); var param = new UpdatePaymentMethodParam { CartName = GetRandom.String(12), CultureInfo = CultureInfo.InvariantCulture, CustomerId = GetRandom.Guid(), PaymentId = GetRandom.Guid(), PaymentMethodId = GetRandom.Guid(), PaymentProviderName = GetRandom.String(15), Scope = GetRandom.String(10) }; var paymentProviderFactoryMock = _container.GetMock <IPaymentProviderFactory>(); paymentProviderFactoryMock.Setup(factory => factory.ResolveProvider(It.IsNotNull <string>())) .Returns(new FakePaymentProvider()); var paymentRepoMock = _container.GetMock <IPaymentRepository>(); paymentRepoMock.Setup(pr => pr.GetPaymentMethodsAsync(It.IsNotNull <GetPaymentMethodsParam>())).ReturnsAsync( new List <PaymentMethod> { new PaymentMethod { Id = param.PaymentMethodId, PaymentProviderName = param.PaymentProviderName, Enabled = true, } } ); paymentRepoMock.Setup(pr => pr.GetCartPaymentsAsync(It.IsNotNull <GetCartPaymentsParam>())) .ReturnsAsync(new List <Payment>() { new Payment { Id = param.PaymentId, Amount = 0.0m, BillingAddress = new Address() { City = GetRandom.String(18), CountryCode = GetRandom.String(2, true), FirstName = GetRandom.String(8), LastName = GetRandom.String(12), IsPreferredBilling = GetRandom.Boolean(), IsPreferredShipping = GetRandom.Boolean(), Email = GetRandom.Email(), Line1 = GetRandom.Phrase(20), Line2 = string.Empty, PhoneNumber = GetRandom.Usa.PhoneNumber(), PostalCode = GetRandom.String(7, true), RegionCode = GetRandom.String(5, true) }, PaymentStatus = PaymentStatus.New, PaymentMethod = new PaymentMethod { Id = param.PaymentMethodId, Enabled = true } } }); var sut = _container.CreateInstance <PaymentViewService>(); //Act var vm = await sut.UpdateActivePaymentMethodAsync(param); //Assert vm.Should().NotBeNull(); vm.Id.Should().NotBeEmpty(); vm.PaymentStatus.Should().NotBeNullOrWhiteSpace(); }