public void WhenSelectedViewChanged_ArticlesInitilized() { //Prepare Mock <INewsService> mockedNewsService = new Mock <INewsService>(); Article[] articles = new Article[] { new Article { ArticleType = ArticleTypes.Major, Keywords = new string[] { "Diablo" } }, new Article { ArticleType = ArticleTypes.Notification, Keywords = new string[] { "Maintenance" } } }; mockedNewsService.Setup(x => x.GetNewsAsync(It.Is <string[]>(keywords => keywords.Length > 0), It.IsAny <CancellationToken>())).Returns(Task.FromResult(articles)); GameViewModel game = new GameViewModel(mockedNewsService.Object); game.BackgroundImage = "testimage"; game.Keywords = new string[] { "Diablo", "Maintenance" }; Mock <IGameService> mockedGameService = new Mock <IGameService>(); mockedGameService.Setup(x => x.GetGames()).Returns(new GameViewModel[] { game }).Verifiable(); GamesViewModel target = new GamesViewModel(mockedGameService.Object); //Act target.SelectedGameView = game; Thread.Sleep(3000); //Verify Assert.IsNotNull(game.MajorArticles); Assert.IsNotNull(game.MinorArticles); }
public async Task <ActionResult <Games> > UpdateGame(int id, GamesViewModel gamesViewModel) { if (id != gamesViewModel.Id) { return(BadRequest(id)); } var game = await _applicationContext.Games.GetAsync(id); if (game is null) { return(NotFound()); } // Update our entity model game.Update(gamesViewModel.Name); // Stage our entity _applicationContext.Games.Update(game); // Commit changes to Db await _applicationContext.CommitAsync(); return(NoContent()); }
public void WhenConstructed_IntializesValues() { //Prepare Mock <INewsService> mockedNewService = new Mock <INewsService>(); mockedNewService.Setup(x => x.GetNews(It.IsAny <string[]>())); GameViewModel target = new GameViewModel(mockedNewService.Object); target.BackgroundImage = "testimage"; Mock <IGameService> mockedGameService = new Mock <IGameService>(); mockedGameService.Setup(x => x.GetGames()).Returns(new GameViewModel[] { target }).Verifiable(); GamesViewModel viewmodel = new GamesViewModel(mockedGameService.Object); //Act viewmodel.SelectedGameView = target; //Verify Assert.AreEqual(target, viewmodel.SelectedGameView); Assert.AreEqual("testimage", viewmodel.BackgroundImage); mockedGameService.VerifyAll(); }
private void SetUpModelForGamesFilter(GamesViewModel model) { const int startMaxPrice = 1000000; model.SelectedGenresIds = model.SelectedGenresIds ?? new int[] { }; model.SelectedPlatformTypesIds = model.SelectedPlatformTypesIds ?? new int[] { }; model.SelectedPublishersIds = model.SelectedPublishersIds ?? new int[] { }; model.Genres = _genreService.GetAllGenres().Select(g => g.ToViewModel()).ToList(); model.PlatformTypes = _platformTypeService.GetAllPlatformTypes().Select(pt => pt.ToViewModel()).ToList(); model.Publishers = _publisherService.GetAllPublishers().Select(p => p.ToShortViewModel()).ToList(); if (model.MaxPrice == default(decimal)) { model.MaxPrice = startMaxPrice; } model.PageInfo = model.PageInfo ?? new PageInfo { PageNumber = 1, PageSize = PageSize.AllItems, TotalItems = _gameService.GetAmountOfGames() }; model.Resource = model.Resource ?? new GamesResource(); model.Resource.Name = Resource.Name; model.Resource.Price = Resource.Price; model.Resource.Details = Resource.Details; model.Resource.Edit = Resource.Edit; model.Resource.Remove = Resource.Remove; model.Resource.Submit = Resource.Submit; model.Resource.Hide = Resource.Hide; model.Resource.Show = Resource.Show; }
public IEnumerable <GamesViewModel> GamesFetcher() { var games = new List <GamesViewModel>(); using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://api.twitch.tv/kraken/search/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = client.GetAsync("games?q=star&type=suggest").Result; if (response.IsSuccessStatusCode) { string responseString = response.Content.ReadAsStringAsync().Result; dynamic blah = JsonConvert.DeserializeObject(responseString); var oneDeep = blah.games; foreach (var item in oneDeep) { var tempUser = new GamesViewModel(); tempUser.box = item.box.medium; tempUser.name = item.name; games.Add(tempUser); } } } return(games); }
private List <Game> GetTestGames() { var games = new GamesViewModel() { Games = { new Game() { Id = 7, Title = "aaa", ReleaseDate = Convert.ToDateTime("2009-05-06 00:00:00.0000000"), Genre = "aaa", Platform = "aaa", Developer = "aaa", Price = 11 }, new Game() { Id = 7, Title = "iii", ReleaseDate = Convert.ToDateTime("2016-08-09 00:00:00.0000000"), Genre = "iii", Platform = "iii", Developer = "iii", Price = 222 } } }; return(games.Games); }
public GamesViewModel Submit( string teamSlug, DateTime queryDate) { var result = new GamesViewModel(); var strDate = Utility.UniversalDate(queryDate); var httpWebRequest = CreateRequest( sport: "baseball", league: "mlb", apiRequest: "games", queryParms: $"season_id=mlb-{queryDate.Year}&on={strDate}&team_id={teamSlug}&status=ended"); // queryParms: $"season_id=mlb-{queryDate.Year}&status=ended"); var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader( httpResponse.GetResponseStream())) { var json = streamReader.ReadToEnd(); var dto = JsonConvert.DeserializeObject <GameDto>( json); //Players = dto.Players; //Teams = dto.Teams; //Games = dto.Games; result = MapDtoToViewModel(dto); } return(result); }
private GamesViewModel MapDtoToViewModel(GameDto dto) { var result = new GamesViewModel(); result.ScoreLine = dto.ScoreLine; return(result); }
// GET: Sunday public ActionResult Resume(string season, string gameType) { season = seasonValue; if (string.IsNullOrEmpty(season) && string.IsNullOrEmpty(gameType)) { return(RedirectToAction("HomePage")); } GamesViewModel sundayVM = new GamesViewModel(); if (TempData["Game"] != null) { sundayVM = TempData["Game"] as GamesViewModel; } else { List <PlayersToGame> lastTeams = GetFinalTeams(gameType); lastTeams = CreateTeams(season, gameType, sundayVM, lastTeams); } return(View(sundayVM)); }
public async Task <ActionResult <GamesViewModel> > Post([FromBody] GamesViewModel gamesViewModel) { try { if (ModelState.IsValid) { //var isvalidGame = _gameRepository.SearchNameGameAsync(gamesViewModel.Name,true); //if (isvalidGame != null) //{ // return BadRequest("Game is already in database"); //} //using Automapper var newGame = _mapper.Map <GamesViewModel, Games>(gamesViewModel); if (newGame.CreationDate == DateTime.MinValue) { newGame.CreationDate = DateTime.Now; } _gameRepository.AddEntity(newGame); if (await _gameRepository.SaveAll()) { //using Automapper return(Created($"/api/GameAPI/{newGame.Name}", _mapper.Map <Games, GamesViewModel>(newGame))); } } } catch { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }
public MainViewModel(IScreen screen, ISettingsManager settingsManager, IVersionManager versionManager) { HostScreen = screen; Games = new GamesViewModel(Locator.Current); Downloads = new DownloadsViewModel(Locator.Current.GetService <IJobManager>()); Messsages = new MessagesViewModel(Locator.Current.GetService <IDatabaseManager>(), Locator.Current.GetService <IMessageManager>()); GotoSettings = ReactiveCommand.CreateFromObservable(() => screen.Router.Navigate.Execute(new SettingsViewModel(screen, settingsManager, versionManager, Locator.Current.GetService <IGameManager>()))); // login status settingsManager.WhenAnyValue(sm => sm.AuthenticatedUser) .Select(u => u == null ? "Not logged." : $"Logged as {u.Name}") .ToProperty(this, x => x.LoginStatus, out _loginStatus); // show notice when new version arrives but hide when button was clicked versionManager.NewVersionAvailable .Where(release => release != null) .Subscribe(newRelease => { ShowUpdateNotice = true; }); // update notice close button CloseUpdateNotice = ReactiveCommand.Create(() => { ShowUpdateNotice = false; }); // restart button RestartApp = ReactiveCommand.Create(() => { UpdateManager.RestartApp(); }); }
public void TestLoadGamesByGenreWithoutResults() { bool loadComplete = false; GamesViewModel viewModel = new GamesViewModel(new MockGameCatalog()); viewModel.LoadComplete += (s, e) => { loadComplete = true; }; viewModel.LoadGamesByGenre("Mature"); // Non-existent Genre EnqueueConditional(() => loadComplete); EnqueueCallback(() => { Assert.AreNotEqual(viewModel.Games, null, "Expected games list not to be null."); }); EnqueueCallback(() => { Assert.IsTrue(viewModel.Games.Count == 0, "Expected games list have no results."); }); EnqueueTestComplete(); }
public async Task <ActionResult <GamesViewModel> > Put(int name, GamesViewModel gamesViewModel)//string name { try { if (ModelState.IsValid) { var oldGame = _gameRepository.GetGameById(name); //var oldGame = _gameRepository.GetGameAsync(name); if (oldGame == null) { return(NotFound("Not found")); } _mapper.Map(gamesViewModel, oldGame); if (await _gameRepository.SaveAll()) { //using Automapper return(_mapper.Map <GamesViewModel>(oldGame)); } } } catch { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }
public IActionResult Index() { var viewModel = new GamesViewModel { Games = GamesRepository.GetAllGames() }; return(View(viewModel)); }
}//DeleteFromList() // Public so it can be called when the program is running public async Task SelectGame(GamesViewModel game) { if (GamesList == null) { return; } await _pageService.PushAsyncPage(new SelectedGamePage(game)); } // SelectGame()
public IActionResult Index() { PCGame fallout = new PCGame() { Name = "Fallout 4", Language = "C++" }; PCGame stalker = new PCGame() { Name = "S.T.A.L.K.E.R.", Language = "C++ & Lua Script" }; PCGame masseffect = new PCGame() { Name = "Mass Effect", Language = "C++" }; List <PCGame> PCGamesCollection = new List <PCGame>(); PCGamesCollection.Add(fallout); PCGamesCollection.Add(stalker); PCGamesCollection.Add(masseffect); XBoxGame minecraft = new XBoxGame() { Name = "Minecraft", Language = "Java" }; XBoxGame obsolete = new XBoxGame() { Name = "Obsolete", Language = "C#" }; XBoxGame crysis = new XBoxGame() { Name = "Crysis", Language = "C++" }; List <XBoxGame> XBoxGamesCollection = new List <XBoxGame>(); XBoxGamesCollection.Add(minecraft); XBoxGamesCollection.Add(obsolete); XBoxGamesCollection.Add(crysis); GamesViewModel viewModel = new GamesViewModel() { PCGames = PCGamesCollection, XBoxGames = XBoxGamesCollection }; return(View(viewModel)); }
public ActionResult Classification(string gameType) { GamesViewModel GamesViewModel = new GamesViewModel(); List <Classification> classification = GetClassification(seasonValue, gameType); GamesViewModel.Classification = BuildClassification(classification); return(View(GamesViewModel)); }
public CodesController(ApplicationDbContext context) { _context = context; GamesVM = new GamesViewModel() { Game = new Game(), Code = new Code() }; }
public ActionResult AddPlayer(GamesViewModel viewModel) { if (viewModel.NewPlayer != null) { AddPlayer(viewModel.NewPlayer); } return(RedirectToAction("Resume", new { @season = viewModel.Season, @gameType = viewModel.GameType })); }
public async Task <ActionResult <Games> > CreateGame(GamesViewModel gamesViewModel) { var game = new Games(gamesViewModel.Name); _applicationContext.Games.Add(game); await _applicationContext.CommitAsync(); return(CreatedAtAction(nameof(game), game)); }
public IActionResult Index() { var model = new GamesViewModel(); var gamesRepo = new GamesRepository(_context); model.Games = gamesRepo.GetAllPublicGames(); model.GameURL = _config.Value.GameURL; return(View(model)); }
public void IndexRendersGames() { var gamesViewModel = new GamesViewModel(); var mockGamesContext = new MockGamesContext().StubBuildViewModelToReturn(gamesViewModel); var controller = new GamesController(mockGamesContext); var result = (ViewResult)controller.Index(); Assert.Equal(gamesViewModel, result.ViewData.Model); mockGamesContext.VerifyBuildViewModelCalled(); }
// GET: /Games/ public IActionResult Index() { var gamesViewModel = new GamesViewModel() { Title = "Games", Games = _gameRepository.GetAllGames().OrderBy(g => g.Name) }; return(View(gamesViewModel)); }
public MainPage() { this.InitializeComponent(); if (_viewModel == null) { _viewModel = new GamesViewModel(); _viewModel.GetGamesCommand.Execute(null); DataContext = _viewModel; } }
public GameDemosController(ApplicationDbContext db, IWebHostEnvironment hostEnvironment) { _db = db; _hostEnvironment = hostEnvironment; GamesVM = new GamesViewModel() { Game = new Game(), GameDemo = new GameDemo(), GameDemos = new List <GameDemo>() }; }
public async Task <string> PutAsync(GamesViewModel gamesModel) { var content = new StringContent(JsonConvert.SerializeObject(gamesModel), Encoding.UTF8, "application/json"); using (HttpResponseMessage response = await client.PutAsync("api/games", content)) { string result = response.Content.ReadAsStringAsync().ToString(); return(result); } }
/// <summary> /// Opens view with a list of games /// </summary> /// <returns></returns> public IActionResult Index() { var games = _gameRepository.GetAllGames(); var gamesList = new GamesViewModel { Games = games }; return(View("Index", gamesList)); }
public async Task <GamesViewModel> GetGamesViewModelAsync() { var gameAllViewModels = await this.GetGameAllViewModelsAsync(); var gamesViewModel = new GamesViewModel { Games = gameAllViewModels, }; return(gamesViewModel); }
public static GamesViewModel MapFromGameToGamesViewModel(Game game) { var gamesVM = new GamesViewModel { GameId = game.GameId, Name = game.Name, Price = game.Price, Genre = game.Genre.Name }; return(gamesVM); }
public HomeController(ILogger <HomeController> logger, ApplicationDbContext db) { _logger = logger; _db = db; gamesVM = new GamesViewModel() { Game = new Game(), Games = new List <Game>(), GameTags = new List <GameTag>(), GameDemos = new List <GameDemo>() }; }
public Games() { DataContext = new GamesViewModel(); InitializeComponent(); }