Exemple #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]));
            }
        }
Exemple #2
0
        public void ShowTeams_VariousControllerArgs_ProperArgumentsCall()
        {
            // Arrange
            var mockXmlReq          = new Mock <IXmlSoccerRequester>(MockBehavior.Strict);
            var testDbContext       = new TestXmlSoccerApiDBContext();
            var apiTestTeamList     = CreateTestTeamList(0);
            var callMockExpressions = CreateTeamsRequestsExpressions(CallMockArguments).ToList();

            mockXmlReq.SetupSequenceCalls(apiTestTeamList, callMockExpressions);

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

            // Act
            CallControlerActionMuliply(footballController.Teams, CallActionArguments);

            // Assert
            Assert.AreEqual(callMockExpressions.Count, testDbContext.SavedChanges);

            mockXmlReq.Verify(
                x => x.GetAllTeamsByLeagueAndSeason(It.IsAny <string>(), It.IsAny <int>()),
                Times.Exactly(callMockExpressions.Count));
            mockXmlReq.Verify(
                x => x.GetAllTeamsByLeagueAndSeason(DefaultLeagueFullName, DefaultSeasonYear),
                Times.Exactly(callMockExpressions.Count - 2));
            mockXmlReq.Verify(x => x.GetAllTeamsByLeagueAndSeason(LeagueIdExample, DefaultSeasonYear), Times.Once);
            mockXmlReq.Verify(x => x.GetAllTeamsByLeagueAndSeason(LeagueIdExample, SeasonYearExample), Times.Once);
        }
Exemple #3
0
        public void ShowTable_EmptyXmlList_ViewMessage()
        {
            // Arrange
            var mockXmlReq         = new Mock <IXmlSoccerRequester>();
            var testDbContext      = new TestXmlSoccerApiDBContext();
            var apiTestLeagueTable = CreateTestLeagueTable(0);

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

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

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

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

            Assert.AreEqual(1, testDbContext.SavedChanges);
            Assert.AreEqual(viewResult.ViewBag.EmptyList, viewResult.ViewBag.Message);

            var modelLeagueTable = viewResult.Model as List <TeamLeagueStanding>;

            // 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(modelLeagueTable);
            Assert.AreEqual(0, apiTestLeagueTable.Count);
            Assert.AreEqual(apiTestLeagueTable.Count, modelLeagueTable.Count);
        }
Exemple #4
0
        public void TestMethod1()
        {
            var testData   = GetTestData();
            var controller = new FootballController(testData);

            var result = controller.result() as List <TestData>;

            Assert.AreEqual(testData.Count, result.Count);
        }
Exemple #5
0
        public async Task GivenInvalidLeagueCodeImportShouldReturn404()
        {
            var controller = new FootballController(MockComponentsProvider(GetInMemoryDbContext()));

            var result = await controller.Import(Guid.NewGuid().ToString());

            var objectResult = result as NotFoundObjectResult;

            Assert.NotNull(objectResult);

            var value = objectResult.Value.ToString();

            Assert.True(value == "{ Message = Not found }");
        }
Exemple #6
0
        public async Task GivenAlreadyImportedLeagueCodeShouldReturnConflict()
        {
            var controller = new FootballController(MockComponentsProvider(GetInMemoryDbContext()));

            await controller.Import("BL1");

            var result = await controller.Import("BL1");

            var objectResult = result as ConflictObjectResult;

            Assert.NotNull(objectResult);

            var value = objectResult.Value.ToString();

            Assert.True(value == "{ Message = League already imported }");
        }
Exemple #7
0
        public async Task GivenValidLeagueCodeImportShouldStoreData()
        {
            var controller = new FootballController(MockComponentsProvider(GetInMemoryDbContext()));

            var result = await controller.Import("BL1");

            var objectResult = result as ObjectResult;

            Assert.NotNull(objectResult);

            Assert.True(objectResult.StatusCode == 201);

            var value = objectResult.Value.ToString();

            Assert.True(value == "{ Message = Successfully imported }");
        }
        public async Task GivenValidLeagueCodeShouldReturnPlayerCount()
        {
            var componentsProvider = MockComponentsProvider(GetInMemoryDbContext());
            var footballController = new FootballController(componentsProvider);
            var playerController   = new PlayerController(componentsProvider);

            await footballController.Import("BL1");

            var result = await playerController.TotalPlayers("BL1");

            var objectResult = result as OkObjectResult;

            Assert.NotNull(objectResult);
            var value = objectResult.Value.ToString();

            Assert.True(value == "{ total = 1184 }");
        }
Exemple #9
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);
        }