Ejemplo n.º 1
0
        public void GetPaymentMethods_WhenSetDefaultPaymentMethodToOtherPaymentMethod_ShouldReturnDefaultPaymentMethodCorrectly()
        {
            _paymentServiceMock.Setup(x => x.GetPaymentMethodsByMarketIdAndLanguageCode(It.IsAny <string>(), "en")).Returns(
                new[]
            {
                new PaymentMethodViewModel {
                    PaymentMethodId = Guid.NewGuid(), Description = "Lorem ipsum", FriendlyName = "name 1", SystemKeyword = "CashOnDelivery"
                },
                new PaymentMethodViewModel {
                    PaymentMethodId = Guid.NewGuid(), Description = "Lorem ipsum", FriendlyName = "name 2", SystemKeyword = "GenericCreditCard", IsDefault = true
                },
                new PaymentMethodViewModel {
                    PaymentMethodId = Guid.NewGuid(), Description = "Lorem ipsum", FriendlyName = "name 3", SystemKeyword = "system3"
                }
            });

            var cashOnDeliveryPaymentOption = new CashOnDeliveryPaymentOption(null, null, _currentMarketMock.Object, _languageServiceMock.Object, _paymentServiceMock.Object);
            var creaditPaymentOption        = new GenericCreditCardPaymentOption(null, null, _currentMarketMock.Object, _languageServiceMock.Object, _paymentServiceMock.Object);

            _paymentOptions = new List <IPaymentOption>();
            _paymentOptions.Add(cashOnDeliveryPaymentOption as IPaymentOption);
            _paymentOptions.Add(creaditPaymentOption as IPaymentOption);

            _subject = new PaymentMethodViewModelFactory(_currentMarketMock.Object, _languageServiceMock.Object, _paymentServiceMock.Object, _paymentOptions);

            var result   = _subject.GetPaymentMethodViewModels().FirstOrDefault(p => p.SystemKeyword == "GenericCreditCard").IsDefault;
            var expected = true;

            Assert.Equal(expected, result);
        }
Ejemplo n.º 2
0
        public PaymentMethodViewModelFactoryTests()
        {
            _paymentServiceMock = new Mock <IPaymentService>();
            _paymentServiceMock.Setup(x => x.GetPaymentMethodsByMarketIdAndLanguageCode(It.IsAny <string>(), "en")).Returns(
                new[]
            {
                new PaymentMethodViewModel {
                    PaymentMethodId = Guid.NewGuid(), Description = "Lorem ipsum", FriendlyName = "name 1", SystemKeyword = "CashOnDelivery", IsDefault = true
                },
                new PaymentMethodViewModel {
                    PaymentMethodId = Guid.NewGuid(), Description = "Lorem ipsum", FriendlyName = "name 2", SystemKeyword = "GenericCreditCard"
                },
                new PaymentMethodViewModel {
                    PaymentMethodId = Guid.NewGuid(), Description = "Lorem ipsum", FriendlyName = "name 3", SystemKeyword = "system3"
                }
            });

            _marketMock = new Mock <IMarket>();
            _marketMock.Setup(m => m.MarketId).Returns(new MarketId("sampleMarket"));

            _currentMarketMock = new Mock <ICurrentMarket>();
            _currentMarketMock.Setup(x => x.GetCurrentMarket()).Returns(_marketMock.Object);

            _languageServiceMock = new Mock <LanguageService>(null, null, null);
            _languageServiceMock.Setup(x => x.GetCurrentLanguage()).Returns(new CultureInfo("en-US"));

            var cashOnDeliveryPaymentOption = new CashOnDeliveryPaymentOption(null, null, _currentMarketMock.Object, _languageServiceMock.Object, _paymentServiceMock.Object);
            var creaditPaymentOption        = new GenericCreditCardPaymentOption(null, null, _currentMarketMock.Object, _languageServiceMock.Object, _paymentServiceMock.Object);

            _paymentOptions = new List <IPaymentOption>();
            _paymentOptions.Add(cashOnDeliveryPaymentOption as IPaymentOption);
            _paymentOptions.Add(creaditPaymentOption as IPaymentOption);

            _subject = new PaymentMethodViewModelFactory(_currentMarketMock.Object, _languageServiceMock.Object, _paymentServiceMock.Object, _paymentOptions);
        }
        public CheckoutViewModelFactoryTests()
        {
            _cart = new FakeCart(new MarketImpl(new MarketId(Currency.USD)), Currency.USD);
            _cart.Forms.Single().Shipments.Single().LineItems.Add(new InMemoryLineItem());
            _cart.Forms.Single().CouponCodes.Add("couponcode");

            var paymentServiceMock = new Mock <IPaymentService>();

            paymentServiceMock.Setup(x => x.GetPaymentMethodsByMarketIdAndLanguageCode(It.IsAny <string>(), "en")).Returns(
                new[]
            {
                new PaymentMethodViewModel()
                {
                    PaymentMethodId = Guid.NewGuid(), Description = "Lorem ipsum", FriendlyName = "payment method 1", SystemKeyword = cashPaymentName
                },
                new PaymentMethodViewModel()
                {
                    PaymentMethodId = Guid.NewGuid(), Description = "Lorem ipsum", FriendlyName = "payment method 2", SystemKeyword = creditPaymentName, IsDefault = true
                }
            });

            var marketMock          = new Mock <IMarket>();
            var currentMarketMock   = new Mock <ICurrentMarket>();
            var languageServiceMock = new Mock <LanguageService>(null, null, null);

            currentMarketMock.Setup(x => x.GetCurrentMarket()).Returns(marketMock.Object);
            languageServiceMock.Setup(x => x.GetCurrentLanguage()).Returns(new CultureInfo("en-US"));

            var cashOnDeliveryPaymentOption = new CashOnDeliveryPaymentOption(null, null, currentMarketMock.Object, languageServiceMock.Object, paymentServiceMock.Object);
            var creaditPaymentOption        = new GenericCreditCardPaymentOption(null, null, currentMarketMock.Object, languageServiceMock.Object, paymentServiceMock.Object);

            var paymentOptions = new List <IPaymentOption>();

            paymentOptions.Add(cashOnDeliveryPaymentOption as IPaymentOption);
            paymentOptions.Add(creaditPaymentOption as IPaymentOption);
            _creditPayment = creaditPaymentOption;

            var paymentMethodViewModelFactory = new PaymentMethodViewModelFactory(currentMarketMock.Object, languageServiceMock.Object, paymentServiceMock.Object, paymentOptions);

            var orderGroupFactoryMock = new Mock <IOrderGroupFactory>();

            orderGroupFactoryMock.Setup(x => x.CreatePayment(It.IsAny <IOrderGroup>())).Returns((IOrderGroup orderGroup) => new FakePayment());
            var serviceLocatorMock = new Mock <IServiceLocator>();

            serviceLocatorMock.Setup(x => x.GetInstance <IOrderGroupFactory>()).Returns(orderGroupFactoryMock.Object);
            ServiceLocator.SetLocator(serviceLocatorMock.Object);

            _addressBookServiceMock = new Mock <IAddressBookService>();
            _addressBookServiceMock.Setup(x => x.List()).Returns(() => new List <AddressModel> {
                new AddressModel {
                    AddressId = "addressid"
                }
            });
            _preferredBillingAddress      = CustomerAddress.CreateInstance();
            _preferredBillingAddress.Name = "preferredBillingAddress";
            _addressBookServiceMock.Setup(x => x.GetPreferredBillingAddress()).Returns(_preferredBillingAddress);
            _addressBookServiceMock.Setup(x => x.UseBillingAddressForShipment()).Returns(true);

            _startPage = new StartPage();
            var contentLoaderMock = new Mock <IContentLoader>();

            contentLoaderMock.Setup(x => x.Get <StartPage>(It.IsAny <PageReference>())).Returns(_startPage);

            var urlResolverMock = new Mock <UrlResolver>();
            var httpcontextMock = new Mock <HttpContextBase>();
            var requestMock     = new Mock <HttpRequestBase>();

            requestMock.Setup(x => x.Url).Returns(new Uri("http://site.com"));
            requestMock.Setup(x => x.UrlReferrer).Returns(new Uri("http://site.com"));
            httpcontextMock.Setup(x => x.Request).Returns(requestMock.Object);

            var shipmentViewModelFactoryMock = new Mock <ShipmentViewModelFactory>(null, null, null, null, null);

            shipmentViewModelFactoryMock.Setup(x => x.CreateShipmentsViewModel(It.IsAny <ICart>())).Returns(() => new[]
            {
                new ShipmentViewModel {
                    CartItems = new[]
                    {
                        new CartItemViewModel {
                            Quantity = 1
                        }
                    }
                }
            });

            _subject = new CheckoutViewModelFactory(
                new MemoryLocalizationService(),
                (() => paymentMethodViewModelFactory),
                _addressBookServiceMock.Object,
                contentLoaderMock.Object,
                urlResolverMock.Object,
                (() => httpcontextMock.Object),
                shipmentViewModelFactoryMock.Object);
        }