public async void GetAllTeams_Successfull()
        {
            //Given
            int tenantId = 1;
            var team     = new Team()
            {
                TeamName = "Quinnox", TeamId = 1
            };
            var teams = new List <Team>()
            {
                team
            };

            teamServiceMoq.Setup(e => e.GetAllTeams(tenantId)).ReturnsAsync(teams);

            //When
            var controller = new TeamController(logger.Object, teamServiceMoq.Object);
            var response   = await controller.GetAllTeams(tenantId) as OkObjectResult;

            var responseObj = response.Value as List <Team>;

            //Then
            Assert.IsType <OkObjectResult>(response);
            Assert.True(responseObj.Count > 0);
            teamServiceMoq.Verify(e => e.GetAllTeams(tenantId), Times.Once);
        }
Beispiel #2
0
        public void TestAllTeams()
        {
            var controller = new TeamController(new RiskAntwerpRest_dbContext());

            var actionResult = controller.GetAllTeams();

            actionResult.Should().BeOfType <OkObjectResult>();
        }
Beispiel #3
0
        public void CreateTeamAddToList()
        {
            TeamController controller = new TeamController(new TestMemoryTeamRepository());
            var            teams      = (IEnumerable <Team>)(controller.GetAllTeams() as ObjectResult).Value;
            List <Team>    original   = new List <Team>(teams);

            Team t      = new Team("Sample");
            var  result = controller.CreateTeam(t);

            var newTeamRaw = (IEnumerable <Team>)(controller.GetAllTeams() as ObjectResult).Value;

            List <Team> newTeams = new List <Team>(newTeamRaw);

            Assert.Equal(newTeams.Count, original.Count + 1);

            var sampleTeam = newTeams.FirstOrDefault(target => target.Name == "Sample");

            Assert.NotNull(sampleTeam);
        }
Beispiel #4
0
        public void  QueryTeamListReturnCollectTeams()
        {
            TeamController controller = new TeamController(new TestMemoryTeamRepository());
            var            rawTeams   = (IEnumerable <Team>)(controller.GetAllTeams() as ObjectResult).Value;
            List <Team>    teams      = new List <Team>(rawTeams);

            Assert.Equal(teams.Count, 2);
            Assert.Equal(teams[0].Name, "one");
            Assert.Equal(teams[1].Name, "two");
        }
        public async void GetAllTeams_Invalid_TenantId()
        {
            //Given
            int tenantId = 0;

            //When
            var controller = new TeamController(logger.Object, teamServiceMoq.Object);
            var response   = await controller.GetAllTeams(tenantId) as BadRequestObjectResult;

            //Then
            Assert.IsType <BadRequestObjectResult>(response);
            Assert.Equal($"Invalid TenantId : {tenantId}", response.Value);
        }
        public async void GetAllTeams_NotFound()
        {
            //Given
            int tenantId             = 100;
            IEnumerable <Team> teams = null;

            teamServiceMoq.Setup(e => e.GetAllTeams(tenantId)).ReturnsAsync(teams);

            //When
            var controller = new TeamController(logger.Object, teamServiceMoq.Object);
            var response   = await controller.GetAllTeams(tenantId) as NotFoundObjectResult;

            //Then
            Assert.IsType <NotFoundObjectResult>(response);
            Assert.Equal($"No teams found for the tenantId : {tenantId}", response.Value);
        }
Beispiel #7
0
        public async void TestForGetAllTeams()
        {
            var options = new DbContextOptionsBuilder <LeagueContext>()
                          .UseInMemoryDatabase(databaseName: "p3TeamControllerGetTeams")
                          .Options;

            using (var context = new LeagueContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repo           r              = new Repo(context, new NullLogger <Repo>());
                Logic          logic          = new Logic(r, new NullLogger <Repo>());
                TeamController teamController = new TeamController(logic);
                var            team           = new Team
                {
                    TeamID     = Guid.NewGuid(),
                    CarpoolID  = Guid.NewGuid(),
                    LeagueID   = Guid.NewGuid(),
                    StatLineID = Guid.NewGuid(),
                    Name       = "Broncos",
                    Wins       = 21,
                    Losses     = 33
                };
                r.Teams.Add(team);
                var team2 = new Team
                {
                    TeamID     = Guid.NewGuid(),
                    CarpoolID  = Guid.NewGuid(),
                    LeagueID   = Guid.NewGuid(),
                    StatLineID = Guid.NewGuid(),
                    Name       = "Dolphins",
                    Wins       = 25,
                    Losses     = 23
                };
                r.Teams.Add(team2);
                await r.CommitSave();

                var getTeams = await teamController.GetAllTeams();

                Assert.IsAssignableFrom <IEnumerable <Team> >((getTeams as OkObjectResult).Value);
            }
        }