Esempio n. 1
0
        public void TestDefaultCtor()
        {
            // set up
            var track = UnitTestHelper.GetDefaultTrack();

            track.CalculateStatistics();

            // run
            var viewModel = new TrackDetailsViewModel(track);

            // check
            Assert.IsTrue(viewModel.Name.Any(), "name must contain value");
            Assert.IsTrue(viewModel.NumTrackPoints > 0, "there must be some track points");
            Assert.IsTrue(viewModel.Distance.Any(), "distance must contain value");
            Assert.IsTrue(viewModel.Duration.Any(), "duration must contain value");

            Assert.IsTrue(viewModel.HeightGain.Any(), "height gain must contain value");
            Assert.IsTrue(viewModel.HeightLoss.Any(), "height loss must contain value");
            Assert.IsTrue(viewModel.MaxHeight.Any(), "max. height must contain value");
            Assert.IsTrue(viewModel.MinHeight.Any(), "min. height must contain value");
            Assert.IsTrue(viewModel.MaxClimbRate.Any(), "max. climb rate must contain value");
            Assert.IsTrue(viewModel.MaxSinkRate.Any(), "max. sink rate must contain value");
            Assert.IsTrue(viewModel.MaxSpeed.Any(), "max. speed must contain value");
            Assert.IsTrue(viewModel.AverageSpeed.Any(), "average speed must contain value");

            Assert.IsNotNull(viewModel.ZoomToTrackCommand, "zoom command must not be null");
            Assert.IsNotNull(viewModel.DeleteTrackCommand, "delete command must not be null");
            Assert.IsNotNull(viewModel.TypeImageSource, "type image source must not be null");

            viewModel.ZoomToTrackCommand.Execute(null);
            viewModel.DeleteTrackCommand.Execute(null);
        }
        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);
        }
Esempio n. 3
0
        public IActionResult Details(TrackDetailsViewModel model)
        {
            if (model.IsAuthenticated == "false")
            {
                model.Error = Constants.UnauthorizedAccessError;
                return(Unauthorized(model, Constants.UnauthorizedViewRoute));
            }
            Guid   trackId      = Guid.Parse(model.TrackId);
            var    track        = TrackService.GetTrack(trackId);
            string trackContent = track.Link.Replace("watch?v=", "embed/");

            model.TrackContent = string.Format(Constants.HtmlIframeTag, 480, 270, trackContent);
            model.TrackArtist  = track.Artist;
            model.TrackTitle   = track.Title;
            string trackGenre = Enumerator.ToTextOrDefault(typeof(MusicGenre), track.Genre);

            if (string.IsNullOrEmpty(trackGenre))
            {
                model.TrackGenre = default(MusicGenre).ToString();
            }
            else
            {
                model.TrackGenre = trackGenre;
            }
            model.TrackPrice = $"${track.Price:F2}";
            return(View(model));
        }
        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);
        }
Esempio n. 5
0
        public IActionResult Details(TrackDetailsInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect($"Albums/All"));
            }

            var albumFromDb = this.albumService.GetAlbumById(model.AlbumId);
            var trackFromDb = this.trackService.GetTrackById(model.TrackId);

            if (albumFromDb == null)
            {
                return(this.Redirect("/Albums/All"));
            }

            else if (trackFromDb == null)
            {
                return(this.Redirect($"/Albums/Details?id={albumFromDb.Id}"));
            }

            TrackDetailsViewModel trackDetailsViewModel = ModelMapper.ProjectTo <TrackDetailsViewModel>(trackFromDb);

            trackDetailsViewModel.AlbumId = model.AlbumId;

            return(this.View(trackDetailsViewModel));
        }
        public IActionResult Details(TrackDetailsViewModel model)
        {
            if (model.AlbumId == null)
            {
                return(BadRequest(string.Format(
                                      Constants.EntityPropertyMissingError, "Track", "ID")));
            }
            var track = TrackService.GetTrackById(model.TrackId);

            model.Artist     = track.Artist;
            model.TrackTitle = track.Title;
            string trackGenre = Enumerator.ToTextOrDefault(typeof(MusicGenre), track.Genre);

            if (string.IsNullOrEmpty(trackGenre))
            {
                model.Genre = default(MusicGenre).ToString();
            }
            else
            {
                model.Genre = trackGenre;
            }
            model.Price = $"${track.Price:F2}";
            model.Link  = track.Link.Replace("watch?v=", "embed/");
            return(View(model));
        }
        public IActionResult Details(TrackDetailsViewModel model)
        {
            var albumId = model.AlbumId;
            var trackId = model.TrackId;

            Track track = this.trackService.GetTrackByAlbumTrackIds(albumId, trackId);

            if (track == null)
            {
                var errorViewContent = File.ReadAllText(GlobalConstants.ErrorViewPath);
                errorViewContent = errorViewContent.Replace(GlobalConstants.ErrorModel, TrackNotFoundErrorMessage);
                return(this.ThrowError(errorViewContent));
            }

            var trackViewModel = new TrackViewModel
            {
                Name      = track.Name,
                VideoLink = track.Link,
                Price     = track.Price.ToString("F2"),
                AlbumId   = track.AlbumId
            };

            this.Model.Data["TrackViewModel"] = trackViewModel;

            return(this.View());
        }
Esempio n. 8
0
        public HttpResponse Details(TrackDetailsBindingModel model)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var albumFromDb = this.albumService.GetAlbumById(model.AlbumId);

            if (albumFromDb == null)
            {
                return(this.Redirect("/Albums/All"));
            }

            var trackFromDb = this.trackService.GetTrackById(model.TrackId);

            if (trackFromDb == null)
            {
                return(this.Redirect($"/Albums/Details?albumId={model.AlbumId}"));
            }

            var trackDetailsViewModel = new TrackDetailsViewModel
            {
                Name    = trackFromDb.Name,
                Price   = trackFromDb.Price,
                Link    = trackFromDb.Link,
                AlbumId = model.AlbumId
            };

            return(this.View(trackDetailsViewModel));
        }
Esempio n. 9
0
        public void ConvertStringSamplesToDoubleTest_ValidSamples()
        {
            var doubleSamples         = new double[] { 4, 57, 79, 85, 18, 67, 84, 8, 1, 66 };
            var stringSamples         = "4, 57, 79, 85, 18, 67, 84, 8, 1, 66".Split(',');
            var samplesAsDoubleResult = TrackDetailsViewModel.ConvertStringSamplesToDouble(stringSamples);

            Assert.IsTrue(samplesAsDoubleResult.SequenceEqual(doubleSamples));
        }
        public IActionResult Details(TrackDetailsViewModel model)
        {
            var track = this.TrackService.Details(model.trackId);

            SetttingViewDataForTrackDetails(track, model.albumId);
            this.SettingViewsBasedOnAccess();
            return(this.View());
        }
Esempio n. 11
0
        public AlbumTrack GetAlbumTrack(TrackDetailsViewModel viewModel)
        {
            var trackAlbum = this.dbContext
                             .AlbumTracks
                             .FirstOrDefault(at => at.AlbumId == viewModel.AlbumId &&
                                             at.TrackId == viewModel.TrackId);

            return(trackAlbum);
        }
        public IActionResult Create(CreateTrackViewModel viewModel)
        {
            var trackId = this.trackService.AddTrack(viewModel);

            var trackDetailsViewModel = new TrackDetailsViewModel()
            {
                AlbumId = viewModel.AlbumId,
                TrackId = trackId
            };

            return(this.Details(trackDetailsViewModel));
        }
        public IActionResult Details(TrackDetailsViewModel viewModel)
        {
            this.ShowAppropriateButtonsBasedOnLoggedIn();

            var albumTrack = this.trackService.GetAlbumTrack(viewModel);
            var trackLink  = albumTrack.Track.Link.DecodeUrl().Replace("watch?v=", "embed/");

            this.Model.Data.Add("Link", trackLink);
            this.Model.Data.Add("Name", albumTrack.Track.Name);
            this.Model.Data.Add("Price", albumTrack.Track.Price);
            this.Model.Data.Add("BackToAlbum", albumTrack.AlbumId);

            return(this.View());
        }
Esempio n. 14
0
        public void TestTrackDetailsViewModel()
        {
            // set up
            var track = UnitTestHelper.GetDefaultTrack();

            track.CalculateStatistics();

            // run
            var viewModel = new TrackDetailsViewModel(track);

            // check
            Assert.IsTrue(viewModel.Name.Any(), "name must contain value");
            Assert.IsNotNull(viewModel.TypeImageSource, "type image source must not be null");
        }
Esempio n. 15
0
        public TrackDetailsViewModel GetDetails(string trackId, string albumid)
        {
            var track = this.GetById(trackId);

            var model = new TrackDetailsViewModel
            {
                Name    = track.Name,
                Link    = track.Link,
                Price   = track.Price,
                AlbumId = albumid
            };

            return(model);
        }
Esempio n. 16
0
        public ActionResult Details(string albumId, string trackId)
        {
            Track trackFromDb = this.trackService.GetTrackById(trackId);

            if (trackFromDb == null)
            {
                return(this.Redirect($"/Albums/Details?id={albumId}"));
            }

            TrackDetailsViewModel trackDetailsViewModel = ModelMapper.ProjectTo <TrackDetailsViewModel>(trackFromDb);

            trackDetailsViewModel.AlbumId = albumId;

            return(this.View(trackDetailsViewModel));
        }
        /// <summary>
        /// Конструктор.
        /// </summary>
        /// <param name="track">Трек, информация о котором будет отображаться.</param>
        internal TrackDetailsPage(IRepository <Track, Guid> tracksStore, IPath path, ILogManager logManager, PageCreator pageCreator, Track track)
        {
            InitializeComponent();

            _pageCreator = pageCreator;
            _logger      = logManager.GetLog();

            _viewModel                = new TrackDetailsViewModel(tracksStore, path, logManager, track);
            _viewModel.PushPage      += OnPushPage;
            _viewModel.ConfirmDelete += OnConfirmDelete;
            _viewModel.OpenBrowser   += OpenBrowserAsync;
            _viewModel.ClosePage     += async() => await Navigation.PopAsync();

            BindingContext = _viewModel;
        }
        public IActionResult Create(TrackViewModel model)
        {
            var track = Mapper.Map <Track>(model);

            string albumId = this.Request.QueryData[IRunesConstants.AlbumIdFromTrackCreateFormThroughRequestQeury].ToString();

            var trackId = this.TrackService.CreateTrack(track, albumId);

            var trackDetails = new TrackDetailsViewModel
            {
                trackId = trackId,
                albumId = albumId
            };

            return(this.Details(trackDetails));
        }
        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. 20
0
        public ActionResult Details()
        {
            string albumId = this.Request.QueryData["albumId"].ToString();
            string trackId = this.Request.QueryData["trackId"].ToString();

            Track trackFromDb = this.trackService.GetTrackById(trackId);

            if (trackFromDb == null)
            {
                return(this.Redirect($"/Albums/Details?id={albumId}"));
            }

            TrackDetailsViewModel trackDetailsViewModel = ModelMapper.ProjectTo <TrackDetailsViewModel>(trackFromDb);

            trackDetailsViewModel.AlbumId = albumId;

            return(this.View(trackDetailsViewModel));
        }
Esempio n. 21
0
        public async Task CalculateResults_Invalid()
        {
            var dataManager = new DataManager();
            await dataManager.LoadAndParseData();

            var samplesList         = dataManager.Tracks[0].GetDegradationSamples();
            var samplesListAsDouble = TrackDetailsViewModel.ConvertStringSamplesToDouble(samplesList);
            var newTyrePlacement    =
                new TyrePlacementViewModel(TyrePlacement.FL)
            {
                SelectedTyre = new TyreDetailsViewModel(dataManager.Tyres[0])
            };

            newTyrePlacement.CalculateResults(samplesListAsDouble, 22.28);
            Assert.AreNotEqual(9, newTyrePlacement.Average.Value);
            Assert.AreNotEqual(14, newTyrePlacement.Mode.Value);
            Assert.AreNotEqual(11, newTyrePlacement.Range.Value);
        }
Esempio n. 22
0
        public async Task <ActionResult> Details(string trackId, string albumId)
        {
            Track trackFromDb = await this.trackService.GetTrackByIdAsync(trackId);

            if (trackFromDb == null)
            {
                return(this.Redirect($"/Albums/Details?id={albumId}"));
            }

            TrackDetailsViewModel trackDetailsViewModel = new TrackDetailsViewModel
            {
                Name    = trackFromDb.Name,
                Link    = trackFromDb.Link,
                Price   = trackFromDb.Price.ToString(),
                AlbumId = trackFromDb.AlbumId,
            };

            return(this.View(trackDetailsViewModel));
        }
Esempio n. 23
0
        public HttpResponse Details(string albumId, string trackId)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var track = this.tracksService.GetById(trackId);

            var viewModel = new TrackDetailsViewModel()
            {
                AlbumId = albumId,
                Name    = track.Name,
                Price   = track.Price,
                Link    = track.Link
            };

            return(this.View(viewModel));
        }
        public HttpResponse Details(string trackId)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var track     = this.tracksService.GetDetails(trackId);
            var viewModel = new TrackDetailsViewModel
            {
                Name    = track.Name,
                Link    = track.Link,
                AlbumId = track.AlbumId,
                Price   = track.Price,
            };

            if (viewModel == null)
            {
                return(this.Error("Track not found."));
            }

            return(this.View(viewModel));
        }
Esempio n. 25
0
        public HttpResponse Details(string albumId)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var track = this.tracksService.GetTrackDetails(albumId);

            if (track == null)
            {
                return(this.Error("The track does not exist!"));
            }

            var model = new TrackDetailsViewModel
            {
                Name         = track.Name,
                AlbumId      = track.AlbumId,
                IFrameSource = track.Link,
                Price        = track.Price
            };

            return(this.View(model));
        }
Esempio n. 26
0
 /// <summary>
 /// </summary>
 /// <param name="trackDetailsViewModel">
 /// The track details view model.
 /// </param>
 /// <returns>
 /// </returns>
 public static TrackManagementViewModel GetTrackManagementViewModel(TrackDetailsViewModel trackDetailsViewModel)
 {
     return(_managementModelsMapper.Map <TrackManagementViewModel>(trackDetailsViewModel));
 }
Esempio n. 27
0
        public IActionResult Details(string id)
        {
            TrackDetailsViewModel track = trackService.GetById(id).MapTo <TrackDetailsViewModel>();

            return(View(track));
        }
Esempio n. 28
0
        public void ConvertStringSamplesToDoubleTest_InvalidSamples()
        {
            var stringSamples = "4m, 57, 79, 85, 18, 67, 84, 8, 1, 66".Split(',');

            TrackDetailsViewModel.ConvertStringSamplesToDouble(stringSamples);
        }