Exemplo n.º 1
0
        public void GetMatchesTest_Check_Score()
        {
            //arrange
            var matches = new List <Matches>
            {
                new Matches
                {
                    Id           = 4,
                    Location     = "Jeziorany",
                    Address      = "ul. Marii Konopnickiej",
                    Year         = 2018,
                    MatchesScore = new List <MatchesScore>
                    {
                        new MatchesScore {
                            TeamId = 1, HalfTimeScore = 2, FullTimeScore = 6
                        },
                        new MatchesScore {
                            TeamId = 2, HalfTimeScore = 1, FullTimeScore = 2
                        }
                    }
                },
                new Matches
                {
                    Id           = 5,
                    Location     = "Olsztyn",
                    Address      = "ul. Jagielończyka",
                    Year         = 2012,
                    MatchesScore = new List <MatchesScore>
                    {
                        new MatchesScore {
                            TeamId = 1, HalfTimeScore = 3, FullTimeScore = 2
                        },
                        new MatchesScore {
                            TeamId = 2, HalfTimeScore = 2, FullTimeScore = 4
                        }
                    }
                }
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Matches> >();

            mockSet.As <IQueryable <Matches> >().Setup(m => m.Provider).Returns(matches.Provider);
            mockSet.As <IQueryable <Matches> >().Setup(m => m.Expression).Returns(matches.Expression);
            mockSet.As <IQueryable <Matches> >().Setup(m => m.ElementType).Returns(matches.ElementType);
            mockSet.As <IQueryable <Matches> >().Setup(m => m.GetEnumerator()).Returns(matches.GetEnumerator());
            var mockContext = new Mock <MulderContext>();

            mockContext.Setup(c => c.Matches).Returns(mockSet.Object);

            ///act
            var service = new MatchesService(mockContext.Object);
            var result  = service.GetMatches();

            //assert
            Assert.IsTrue(result.Count == 2);
            Assert.IsTrue(result[0].ScoreInfo[0].FullTimeScore == 6);
            Assert.IsTrue(result[0].ScoreInfo[1].FullTimeScore == 2);
            Assert.IsTrue(result[1].ScoreInfo[0].FullTimeScore == 2);
            Assert.IsTrue(result[1].ScoreInfo[1].FullTimeScore == 4);
        }
Exemplo n.º 2
0
        async Task ExecuteLoadMatchesCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Matches.Clear();
                var matches = await MatchesService.GetMatches();

                foreach (var match in matches)
                {
                    Matches.Add(match);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }