コード例 #1
0
        public void TesttController_GetByID_CountShouldBeCorrectInt()
        {
            var result = _controller.Get(1);

            Assert.AreEqual(1, _mockService.CallCount);
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <TeamDetail>));
        }
コード例 #2
0
        public void RetrieveFailureATeamInTheRepo()
        {
            List <Team> Teams = createTeams();

            var mock = new Mock <ITeamRepository>(MockBehavior.Strict);

            // Filling mock with data
            mock.As <ICRUDRepository <Team, int, TeamFilter> >().Setup(m => m.Get(It.IsAny <int>()))
            .Returns <int?>(id => Task.FromResult(Teams.FirstOrDefault(c => false)));

            var mockCountryRepo = new Mock <ICountryRepository>(MockBehavior.Strict);

            mockCountryRepo.As <ICRUDRepository <Country, int, TeamFilter> >().Setup(m => m.Get(It.IsAny <int>()))
            .Returns <int>(id => Task.FromResult(new Country()));

            // Creating the controller which we want to create
            TeamController controller = new TeamController(mock.Object, mockCountryRepo.Object);

            // configuring the context for the controler
            fakeContext(controller);

            HttpResponseMessage response = controller.Get(0).Result;

            Assert.AreEqual(response.StatusCode, HttpStatusCode.NotFound);
        }
コード例 #3
0
        private void TeamPlayers_SortedCorrectly(string team, int pageNumber, int indexOnPage, int expectedPlayerNumberOnPage, int expectedPlayerCount)
        {
            ActionResult result = _controller.Get(team, 10, pageNumber);

            Assert.IsType <OkObjectResult>(result);

            OkObjectResult okResult = result as OkObjectResult;

            Assert.Equal(200, okResult.StatusCode);

            PaginatedResponse <Player> responseData = okResult.Value as PaginatedResponse <Player>;

            Assert.NotNull(responseData);

            Assert.Equal(expectedPlayerCount, responseData.Data.Count());

            Assert.Equal(expectedPlayerNumberOnPage, responseData.Data.ToList()[indexOnPage].PlayerNumber);
        }
コード例 #4
0
        public void Test_GetbyID_Return_OkResult()
        {
            //Arrange
            var controller = new TeamController(TeamService);
            //Act
            var data = controller.Get(1);

            //Assert
            Assert.IsType <OkObjectResult>(data);
        }
コード例 #5
0
ファイル: TypeTablesTests.cs プロジェクト: tnmanda/Editorial
        public void Teams()
        {
            ILogger <TeamController> _testlogger = null;

            using (var context = new AppDbContext(options, null))
            {
                var controller = new TeamController(context, _testlogger);

                // Get all
                var result = controller.Get();

                // Assert
                var okResult = Assert.IsAssignableFrom <IEnumerable <Team> >(result);
                var pgcount  = okResult.ToList().Count;
                Assert.Equal(2, pgcount);

                // Get by ID
                var result1   = controller.Get(1);
                var okResult1 = Assert.IsAssignableFrom <Team>(result1);
                Assert.Equal("team 1", okResult1.TeamName);

                // test update
                var pg1 = new Team {
                    TeamID = 1, TeamName = "team 1 upd"
                };
                controller.UpdateEntry(pg1);
                var result3 = controller.Get(1);
                Assert.NotEqual("team 1", result3.TeamName);
                Assert.Equal("team 1 upd", result3.TeamName);

                // test delete
                var result4 = controller.Get(2);
                Assert.Equal("team 2", result4.TeamName);

                IActionResult result5    = controller.Delete(2);
                var           viewResult = Assert.IsType <Microsoft.AspNetCore.Mvc.OkResult>(result5);
                var           result6    = controller.Get(2);
                Assert.Null(result6);
            }
        }
コード例 #6
0
        public async void Get_Not_Exists()
        {
            TeamControllerMockFacade mock = new TeamControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiTeamResponseModel>(null));
            TeamController controller = new TeamController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Get(default(int));

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
コード例 #7
0
        public async void Get_Exists()
        {
            TeamControllerMockFacade mock = new TeamControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult(new ApiTeamResponseModel()));
            TeamController controller = new TeamController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Get(default(string));

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var record = (response as OkObjectResult).Value as ApiTeamResponseModel;

            record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <string>()));
        }
コード例 #8
0
        public void TeamPostGet()
        {
            Team team = new Team
            {
                Access = true,
                Name   = "Work together!"
            };

            TeamController controller = new TeamController(new MockDatabase());

            controller.Create(1, team);

            var result = controller.Get(1) as OkNegotiatedContentResult <Team>;

            Assert.IsNotNull(result);

            Assert.AreEqual("Work together!", result.Content.Name);
            Assert.AreEqual(true, result.Content.Access);
        }
コード例 #9
0
        public void TeamPostPutGet()
        {
            Team team = new Team
            {
                Access = true,
                Name   = "Work together!"
            };

            TeamController controller = new TeamController(new MockDatabase());

            team = (controller.Create(1, team) as OkNegotiatedContentResult <Team>).Content;

            team.Access = false;
            team.Name   = "Nah";

            var result = controller.Get(team.Id) as OkNegotiatedContentResult <Team>;

            Assert.IsNotNull(result);

            Assert.AreEqual("Nah", result.Content.Name);
            Assert.AreEqual(false, result.Content.Access);
        }
コード例 #10
0
        public async Task GetAll_ShouldReturnTeamsAndOkStatus()
        {
            var expTeams = new List <Team>();

            for (int i = 1; i <= 30; i++)
            {
                var team = new Team()
                {
                    Id      = i,
                    Name    = $"test Team {i}",
                    Players = new List <Player>()
                };
                for (int j = 1; j <= 2; j++)
                {
                    var expPlayer = new Player()
                    {
                        Id    = i,
                        Email = $"test{i}@test.com",
                        Name  = $"test player {i}"
                    };
                    team.Players.Add(expPlayer);
                }
            }


            mockTeamService.Setup(x => x.Get()).ReturnsAsync(expTeams);
            var result = await TeamController.Get();

            var okResult = Assert.IsType <OkObjectResult>(result);
            var actTeams = Assert.IsType <List <Team> >(okResult.Value);

            Assert.Equal(expTeams, actTeams);
            foreach (var team in actTeams)
            {
                Assert.Equal(2, team.Players.Count);
            }
        }
コード例 #11
0
        public void CreateTeamTest()
        {
            string teamName = "New Team";
            var    team     = controller.Create(teamName, testContext.users[0]);

            var fetchedTeam = controller.Get(team.Id, testContext.users[0]);

            Assert.NotNull(fetchedTeam);

            Assert.Equal(team.Id, fetchedTeam.Id);

            Assert.Equal(teamName, fetchedTeam.Name);
            Assert.Equal(fetchedTeam.Acl.ownerId, testContext.users[0].Id);
        }