public void Index_ShouldSetCurrentPageAsStartPage()
        {
            var controller = CreateController();
            var currentPage = new StartPage();

            var result = controller.Index(currentPage);

            Assert.Equal(currentPage, ((StartPageViewModel)result.Model).StartPage);
        }
        public MultiShipmentViewModelFactoryTests()
        {
            _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 addressBookServiceMock = new Mock<IAddressBookService>();
            addressBookServiceMock.Setup(x => x.List()).Returns(() => new List<AddressModel> { new AddressModel { AddressId = "addressid" } });
            var 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);

            PreferredCultureAccessor accessor = () => CultureInfo.InvariantCulture;
            var shipmentViewModelFactoryMock = new Mock<ShipmentViewModelFactory>(null, null, null, null, null, null, accessor, null);
            shipmentViewModelFactoryMock.Setup(x => x.CreateShipmentsViewModel(It.IsAny<ICart>())).Returns(() => new[]
            {
                new ShipmentViewModel {CartItems = new[]
                {
                    new CartItemViewModel { Quantity = 1 }
                }
            }
            });

            _subject = new MultiShipmentViewModelFactory(
                new MemoryLocalizationService(),
                addressBookServiceMock.Object,
                contentLoaderMock.Object,
                urlResolverMock.Object,
                (() => httpcontextMock.Object),
                shipmentViewModelFactoryMock.Object);
        }
        public CartViewModelFactoryTests()
        {
            _cart = new FakeCart(new MarketImpl(MarketId.Default), Currency.USD);
            _cart.Forms.Single().Shipments.Single().LineItems.Add(new InMemoryLineItem { Quantity = 1, PlacedPrice = 105, LineItemDiscountAmount = 5});

            _startPage = new StartPage() { CheckoutPage = new ContentReference(1), WishListPage = new ContentReference(1) };
            var contentLoaderMock = new Mock<IContentLoader>();
            contentLoaderMock.Setup(x => x.Get<StartPage>(It.IsAny<ContentReference>())).Returns(_startPage);

            PreferredCultureAccessor accessor = () => CultureInfo.InvariantCulture;
            var shipmentViewModelFactoryMock = new Mock<ShipmentViewModelFactory>(null,null,null,null,null,null,accessor,null);
            _cartItems = new List<CartItemViewModel> {new CartItemViewModel {DiscountedPrice = new Money(100, Currency.USD), Quantity = 1} };
            shipmentViewModelFactoryMock.Setup(x => x.CreateShipmentsViewModel(It.IsAny<ICart>())).Returns(() => new[] { new ShipmentViewModel {CartItems = _cartItems} });

            var currencyServiceMock = new Mock<ICurrencyService>();
            currencyServiceMock.Setup(x => x.GetCurrentCurrency()).Returns(Currency.USD);

            _totals = new OrderGroupTotals(
                new Money(100, Currency.USD),
                new Money(100, Currency.USD),
                new Money(100, Currency.USD),
                new Money(100, Currency.USD),
                new Money(100, Currency.USD),
                new Dictionary<IOrderForm, OrderFormTotals>());

            var orderGroupTotalsCalculatorMock = new Mock<IOrderGroupTotalsCalculator>();
            orderGroupTotalsCalculatorMock.Setup(x => x.GetTotals(It.IsAny<ICart>())).Returns(_totals);

            _orderDiscountTotal = new Money(5, Currency.USD);
            var orderGroupCalculatorMock = new Mock<IOrderGroupCalculator>();
            orderGroupCalculatorMock.Setup(x => x.GetOrderDiscountTotal(It.IsAny<IOrderGroup>(), It.IsAny<Currency>()))
                .Returns(_orderDiscountTotal);

            orderGroupCalculatorMock.Setup(x => x.GetSubTotal(_cart)).Returns(new Money(_cart.GetAllLineItems().Sum(x => x.PlacedPrice * x.Quantity - ((ILineItemDiscountAmount)x).EntryAmount), _cart.Currency));

            _subject = new CartViewModelFactory(
                contentLoaderMock.Object,
                currencyServiceMock.Object,
                orderGroupTotalsCalculatorMock.Object,
                orderGroupCalculatorMock.Object,
                shipmentViewModelFactoryMock.Object);
        }
        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");

            _cashPayment = new PaymentMethodViewModel<PaymentMethodBase> { SystemName = cashPaymentName };
            _creditPayment = new PaymentMethodViewModel<PaymentMethodBase> { SystemName = creditPaymentName };
            var paymentServiceMock = new Mock<IPaymentService>();
            var marketMock = new Mock<IMarket>();
            var currentMarketMock = new Mock<ICurrentMarket>();
            var languageServiceMock = new Mock<LanguageService>(null, null, null, null);
            var paymentMethodViewModelFactory = new PaymentMethodViewModelFactory(currentMarketMock.Object, languageServiceMock.Object, paymentServiceMock.Object);

            currentMarketMock.Setup(x => x.GetCurrentMarket()).Returns(marketMock.Object);
            languageServiceMock.Setup(x => x.GetCurrentLanguage()).Returns(new CultureInfo("en-US"));
            paymentServiceMock.Setup(x => x.GetPaymentMethodsByMarketIdAndLanguageCode(It.IsAny<string>(), "en")).Returns(
               new[]
               {
                    new PaymentMethodModel { Description = "Lorem ipsum", FriendlyName = "payment method 1", LanguageId = "en", PaymentMethodId = Guid.NewGuid(), SystemName = cashPaymentName },
                    new PaymentMethodModel { Description = "Lorem ipsum", FriendlyName = "payment method 2", LanguageId = "en", PaymentMethodId = Guid.NewGuid(), SystemName = creditPaymentName }
               });

            var 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 orderFactoryMock = new Mock<IOrderFactory>();
            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);

            Func<CultureInfo> func = () => CultureInfo.InvariantCulture;
            var shipmentViewModelFactoryMock = new Mock<ShipmentViewModelFactory>(null, null, null, null, null, null, func, 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,
                orderFactoryMock.Object,
                urlResolverMock.Object,
                (() => httpcontextMock.Object),
                shipmentViewModelFactoryMock.Object);
        }