public void SetTotalPriceWithAlbum_emptyAlbum_120()
        {
            //// Set Currency
            var userCurrency = new CurrencyViewModel();

            userCurrency.Code      = 840;
            userCurrency.ShortName = "USD";
            //// Set TrackPrices
            var priceTrack = new PriceViewModel();

            priceTrack.Currency = userCurrency;
            priceTrack.Amount   = 120;
            //// Create track with price = 120
            var track1 = new TrackDetailsViewModel()
            {
                Name  = "SuperTrack",
                Price = priceTrack
            };
            //// Create empty album
            var album1 = new AlbumDetailsViewModel();
            //// Create and set CartView model
            var myCartView = new CartViewModel()
            {
                Tracks = new List <TrackDetailsViewModel>(),
                Albums = new List <AlbumDetailsViewModel>()
            };

            myCartView.Tracks.Add(track1);
            myCartView.Albums.Add(album1);
            CartViewModelService.SetTotalPrice(myCartView, userCurrency);
            Assert.IsTrue(myCartView.TotalPrice == 120);
        }
        public void SetTotalPrice_120and120_240()
        {
            //// Set Currency
            var userCurrency = new CurrencyViewModel();

            userCurrency.Code      = 840;
            userCurrency.ShortName = "USD";
            //// Set TrackPrices
            var priceTrack = new PriceViewModel();

            priceTrack.Currency = userCurrency;
            priceTrack.Amount   = 120;
            //// Create two tracks
            var track1 = new TrackDetailsViewModel()
            {
                Name  = "SuperTrack",
                Price = priceTrack
            };
            var track2 = new TrackDetailsViewModel()
            {
                Name  = "SuperTrack",
                Price = priceTrack
            };
            //// Create and set CartView model
            var myCartView = new CartViewModel()
            {
                Tracks = new List <TrackDetailsViewModel>()
            };

            myCartView.Tracks.Add(track1);
            myCartView.Tracks.Add(track2);
            CartViewModelService.SetTotalPrice(myCartView, userCurrency);
            Assert.IsTrue(myCartView.TotalPrice == 240);
        }
        public void SetTotalPrice_noTracksInCart_0()
        {
            //// Set Currency
            var userCurrency = new CurrencyViewModel();

            userCurrency.Code      = 840;
            userCurrency.ShortName = "USD";
            //// Create and set CartView model
            var myCartView = new CartViewModel()
            {
                Tracks = new List <TrackDetailsViewModel>()
            };

            CartViewModelService.SetTotalPrice(myCartView, userCurrency);
            Assert.IsTrue(myCartView.TotalPrice == 0);
        }
        public void SetTotalPriceWithAlbum_150and240_390()
        {
            //// Set Currency
            var userCurrency = new CurrencyViewModel();

            userCurrency.Code      = 840;
            userCurrency.ShortName = "USD";
            //// Set TrackPrices
            var priceTrack = new PriceViewModel();

            priceTrack.Currency = userCurrency;
            priceTrack.Amount   = 120;
            //// Create two tracks with total price = 240
            var track1 = new TrackDetailsViewModel()
            {
                Name  = "SuperTrack1",
                Price = priceTrack
            };
            var track2 = new TrackDetailsViewModel()
            {
                Name  = "SuperTrack2",
                Price = priceTrack
            };
            //// Set TrackPrices
            var priceAlbum = new PriceViewModel();

            priceAlbum.Currency = userCurrency;
            priceAlbum.Amount   = 150;
            //// Create album with price = 150
            var album1 = new AlbumDetailsViewModel()
            {
                Name  = "MyAlbum",
                Price = priceAlbum
            };
            //// Create and set CartView model
            var myCartView = new CartViewModel()
            {
                Tracks = new List <TrackDetailsViewModel>(),
                Albums = new List <AlbumDetailsViewModel>()
            };

            myCartView.Tracks.Add(track1);
            myCartView.Tracks.Add(track2);
            myCartView.Albums.Add(album1);
            CartViewModelService.SetTotalPrice(myCartView, userCurrency);
            Assert.IsTrue(myCartView.TotalPrice == 390);
        }
Esempio n. 5
0
        public ViewResult Index()
        {
            var cartService = ServiceFactory.GetCartService();

            _viewModel.Tracks        = cartService.GetOrderTracks(CurrentUser.Id, CurrentUserCurrency?.Code);
            _viewModel.Albums        = cartService.GetOrderAlbums(CurrentUser.Id, CurrentUserCurrency?.Code);
            _viewModel.CurrentUserId = CurrentUser.Id;
            // Установка текущей валюты пользователя и пересчёт суммы к оплате
            if (CurrentUser.Id > 0)
            {
                _viewModel.CurrencyShortName = CurrentUserCurrency.ShortName;
                CartViewModelService.SetTotalPrice(_viewModel, CurrentUserCurrency);
                TempData["cart"] = _viewModel;
            }

            return(View(_viewModel));
        }