Ejemplo n.º 1
0
        public void ShowTeams_TestList_EqualLists()
        {
            // Arrange
            var mockXmlReq      = new Mock <IXmlSoccerRequester>();
            var testDbContext   = new TestXmlSoccerApiDBContext();
            var apiTestTeamList = CreateTestTeamList(NumberOfTeams);

            mockXmlReq.Setup(x => x.GetAllTeamsByLeagueAndSeason(
                                 It.IsAny <string>(), It.IsAny <int>()))
            .Returns(apiTestTeamList);

            var footballController = new FootballController(mockXmlReq.Object, testDbContext);

            // Act
            var viewResult = footballController.Teams() as ViewResult;

            // Assert
            mockXmlReq.Verify(x => x.GetAllTeamsByLeagueAndSeason(It.IsAny <string>(), It.IsAny <int>()), Times.Once());

            Assert.AreEqual(1, testDbContext.SavedChanges);

            var modelTeamList = viewResult.Model as List <FootballTeam>;

            // Checking if list forwarded as a model (viewResult.Model) to View
            // corresponds to test list (Does this list have the same values of their objects? )
            Assert.IsNotNull(modelTeamList);
            Assert.AreEqual(NumberOfTeams, apiTestTeamList.Count);
            Assert.AreEqual(apiTestTeamList.Count, modelTeamList.Count);

            for (int i = 0; i < modelTeamList.Count; i++)
            {
                Assert.IsTrue(modelTeamList[i].IsEqualToXmlTeam(apiTestTeamList[i]));
            }
        }
Ejemplo n.º 2
0
        public void ShowTeams_RepeatedControllerActionCall_NoRepeatedApiRequest()
        {
            // Arrange
            var mockXmlReq      = new Mock <IXmlSoccerRequester>();
            var testDbContext   = new TestXmlSoccerApiDBContext();
            var apiTestTeamList = CreateTestTeamList(0);

            mockXmlReq.Setup(x => x.GetAllTeamsByLeagueAndSeason(
                                 It.IsAny <string>(), It.IsAny <int>()))
            .Returns(apiTestTeamList);

            var footballController = new FootballController(mockXmlReq.Object, testDbContext);

            // Act
            var viewResult = footballController.Teams() as ViewResult;

            viewResult = footballController.Teams() as ViewResult;

            // Assert
            mockXmlReq.Verify(x => x.GetAllTeamsByLeagueAndSeason(It.IsAny <string>(), It.IsAny <int>()), Times.Once());

            Assert.AreEqual(1, testDbContext.SavedChanges);
        }