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 void WhenGameRegionsChanged_SelectedRegionPropertyUpdated()
        {
            //Prepare
            Mock<INewsService> mockedNewsService = new Mock<INewsService>();
            GameViewModel target = new GameViewModel(mockedNewsService.Object);
            List<GameRegion> gameRegions = new List<GameRegion> { new GameRegion(), new GameRegion() };

            //Act
            target.GameRegions = gameRegions;

            //Verify
            Assert.AreEqual(gameRegions[0], target.SelectedRegion);
        }
        public void WhenConstructed_IntializesValues()
        {
            //Prepare
            Mock<INewsService> mockedNewsService = new Mock<INewsService>();

            //Act
            GameViewModel target = new GameViewModel(mockedNewsService.Object);

            //Verify
            Assert.IsNull(target.BackgroundImage);
            Assert.IsNull(target.GameId);
            Assert.IsNull(target.HeaderImage);
            Assert.IsNull(target.HeaderText);
            Assert.IsNull(target.LogoImage);
            Assert.IsNotNull(target.InstallGameCommand);
            Assert.IsNull(target.GameRegions);
            Assert.IsNull(target.SelectedRegion);
            Assert.IsInstanceOfType(target.SelectGameRegionCommand, typeof(ICommand));
        }
        public void WhenSelectedViewChanged_PropertyIsUpdated()
        {
            //Prepare
            Mock<INewsService> mockedNewService = new Mock<INewsService>();
            mockedNewService.Setup(x => x.GetNews(It.IsAny<string[]>()));

            GameViewModel game = new GameViewModel(mockedNewService.Object);
            game.BackgroundImage = "testimage";

            Mock<IGameService> mockedGameService = new Mock<IGameService>();
            mockedGameService.Setup(x => x.GetGames()).Returns(new GameViewModel[] { game }).Verifiable();

            GamesViewModel viewmodel = new GamesViewModel(mockedGameService.Object);

            bool backgroundImageChangedRaised = false;
            viewmodel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "BackgroundImage")
                {
                    backgroundImageChangedRaised = true;
                }
            };

            bool selectedGameViewChangedRaised = false;
            viewmodel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "SelectedGameView")
                {
                    selectedGameViewChangedRaised = true;
                }
            };

            //Act
            viewmodel.SelectedGameView = game;

            //Verify
            Assert.AreSame(game, viewmodel.SelectedGameView);
            Assert.IsTrue(backgroundImageChangedRaised);
            Assert.IsTrue(selectedGameViewChangedRaised);
        }
        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();
        }
        public void WhenPropertyChanged_PropertyIsUpdated()
        {
            //Prepare
            Mock<INewsService> mockedNewsService = new Mock<INewsService>();
            mockedNewsService.Setup(x => x.GetNews(It.Is<string[]>(keywords => keywords.Length > 0))).Returns(
                new Article[] { new Article() }).Verifiable();

            GameViewModel target = new GameViewModel(mockedNewsService.Object);

            bool backgroundImageChanged = false;
            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "BackgroundImage")
                {
                    backgroundImageChanged = true;
                }
            };

            bool gameIdChanged = false;
            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "GameId")
                {
                    gameIdChanged = true;
                }
            };

            bool headerImageChanged = false;
            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "HeaderImage")
                {
                    headerImageChanged = true;
                }
            };

            bool headerTextChanged = false;
            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "HeaderText")
                {
                    headerTextChanged = true;
                }
            };

            bool logoImageChanged = false;
            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "LogoImage")
                {
                    logoImageChanged = true;
                }
            };

            bool selectedRegionChanged = false;
            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "SelectedRegion")
                {
                    selectedRegionChanged = true;
                }
            };

            bool gameRegionsChanged = false;
            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "GameRegions")
                {
                    gameRegionsChanged = true;
                }
            };

            //Act
            target.BackgroundImage = "";
            target.GameId = "";
            target.HeaderImage = "";
            target.HeaderText = "";
            target.LogoImage = "";
            target.SelectedRegion = new GameRegion();
            target.GameRegions = new GameRegion[] { };

            //Verify
            Assert.IsTrue(backgroundImageChanged);
            Assert.IsTrue(gameIdChanged);
            Assert.IsTrue(headerImageChanged);
            Assert.IsTrue(headerTextChanged);
            Assert.IsTrue(logoImageChanged);
            Assert.IsTrue(selectedRegionChanged);
            Assert.IsTrue(gameRegionsChanged);
        }
        public void WhenSelectGameRegionCommandExecuted_SelectedRegionPropertyChanged()
        {
            //Prepare
            Mock<INewsService> mockedNewsService = new Mock<INewsService>();
            GameViewModel target = new GameViewModel(mockedNewsService.Object);
            GameRegion gameRegion = new GameRegion();

            //Act
            target.SelectGameRegionCommand.Execute(gameRegion);

            //Verify
            Assert.AreEqual(gameRegion, target.SelectedRegion);
        }