Example #1
0
        public void TestCreateTeamPersistedPass()
        {
            //Arrange
            int rowId = 0;

            //Act
            rowId = _TeamController.CreateTeam(_TestTeam2);

            //Assert
            Assert.IsTrue(rowId == _TestTeam.Id);
        }
        public void CreateTeamReturns201StatusAndTeamWhenSuccessful()
        {
            var createTeamRequest = TestHelpers.CreateTeamRequest();
            var team = TestHelpers.CreateTeamResponse(name: createTeamRequest.Name, context: createTeamRequest.Context);

            _teamsUseCase.Setup(x => x.ExecutePost(createTeamRequest)).Returns(team);

            var response = _teamController.CreateTeam(createTeamRequest) as ObjectResult;

            _teamsUseCase.Verify(x => x.ExecutePost(createTeamRequest), Times.Once);
            response?.StatusCode.Should().Be(201);
            response?.Value.Should().BeEquivalentTo(team);
        }
        public void CreateTeam_Test()
        {
            var result = teamController.CreateTeam() as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
            Assert.IsNotNull(result);
        }
Example #4
0
        public void TestInitialize()
        {
            _TeamController   = new TeamController();
            _PlayerController = new PlayerController();

            _TestTeam = new Team {
                Name = "TeamTest"
            };
            _TestTeam2    = _TestTeam;
            _TestTeamFail = new Team();
            _TeamController.CreateTeam(_TestTeam);

            _TestPlayer1 = new Player {
                NickName = "JohnnyBoi",
                Age      = "87",
                Role     = "Kaffehenter",
                TeamId   = _TestTeam.Id
            };
            _TestPlayer2 = new Player {
                NickName = "Zunny",
                Age      = "109",
                Role     = "AWP",
                TeamId   = _TestTeam.Id
            };
            _TestPlayer3 = new Player {
                NickName = "SvendBent",
                Age      = "7",
                Role     = "Rifle",
                TeamId   = _TestTeam.Id
            };
            _TestPlayer4 = new Player {
                NickName = "SkæveKaj",
                Age      = "44",
                Role     = "IGL/Rifler",
                TeamId   = _TestTeam.Id
            };
            _TestPlayer5 = new Player {
                NickName = "D0rteDeagle",
                Age      = "42",
                Role     = "Rifle",
                TeamId   = _TestTeam.Id
            };


            _PlayerController.CreatePlayer(_TestPlayer1);
            _TestTeam.Players.Add(_TestPlayer1);
            _PlayerController.CreatePlayer(_TestPlayer2);
            _TestTeam.Players.Add(_TestPlayer2);
            _PlayerController.CreatePlayer(_TestPlayer3);
            _TestTeam.Players.Add(_TestPlayer3);
            _PlayerController.CreatePlayer(_TestPlayer4);
            _TestTeam.Players.Add(_TestPlayer4);
            _PlayerController.CreatePlayer(_TestPlayer5);
            _TestTeam.Players.Add(_TestPlayer5);
            _TeamController.EditTeam(_TestTeam);
        }
        public async void Given_Exception_When_CreateTeam_Then_ReturnBadRequest()
        {
            //Arrange
            var controller = new TeamController(null);

            //Act
            var result = await controller.CreateTeam(null);

            //Assert
            result.Should().BeOfType <BadRequestObjectResult>();
        }
Example #6
0
        public void CreateTeam()
        {
            // Arrange
            var team = new Team()
            {
                Name = "Team"
            };

            // Act
            _target.CreateTeam(1, team);
            // Assert
            A.CallTo(() => _teamService.CreateTeam(1, team)).MustHaveHappened();
        }
        protected async Task AssertCanCreateTeam()
        {
            var team = await Controller.CreateTeam(new CreateTeam
            {
                Team = new Team {
                    Id = 1, Name = "my team"
                }
            });

            Assert.IsNotNull(team);
            Assert.IsTrue(!string.IsNullOrEmpty(team.Name));
            Assert.IsTrue(team.Id > 0);
        }
        public async void CreateTeam_Invalid_TeamName_Or_TenantId()
        {
            //Given
            Team team = new Team()
            {
                TeamName    = null,
                Description = "Test team",
                TenantId    = 0
            };

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

            //Then
            Assert.IsType <BadRequestObjectResult>(response);
            Assert.Equal($"Invalid Team Name : {team.TeamName} or TenantId : {team.TenantId}", response.Value);
        }
Example #9
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);
        }
Example #10
0
        public void TestInitialize()
        {
            _teamController   = new TeamController();
            _playerController = new PlayerController();

            _testTeam = new Team {
                Name = "TestTeam"
            };

            _teamId      = _teamController.CreateTeam(_testTeam);
            _testTeam.Id = _teamId;

            _testPlayer1 = new Player {
                NickName = "TestNickName",
                Age      = "TestAge",
                Role     = "TestRole",
                TeamId   = _teamId
            };
            _testPlayer2 = new Player {
                NickName = "TestNickName",
                Age      = "TestAge",
                Role     = "TestRole",
                TeamId   = _teamId
            };
            _testPlayer3 = new Player {
                NickName = "TestNickName",
                Age      = "TestAge",
                Role     = "TestRole",
                TeamId   = _teamId
            };
            _testPlayer4 = new Player {
                NickName = "TestNickName",
                Age      = "TestAge",
                Role     = "TestRole",
                TeamId   = _teamId
            };
            _testPlayer5 = new Player {
                NickName = "TestNickName",
                Age      = "TestAge",
                Role     = "TestRole",
                TeamId   = _teamId
            };
        }
        public async void CreateTeam_Duplicate_TeamName()
        {
            //Given
            Team team = new Team()
            {
                TeamName    = "Quinnox",
                Description = "Test team",
                TenantId    = 1
            };

            teamServiceMoq.Setup(e => e.CreateTeam(team)).ThrowsAsync(new Exception("Team with same name exist"));

            //When
            var controller = new TeamController(logger.Object, teamServiceMoq.Object);
            var response   = await controller.CreateTeam(team) as ConflictObjectResult;

            //Then
            Assert.IsType <ConflictObjectResult>(response);
            Assert.Equal($"Team {team.TeamName} already exist for the Tenant", response.Value);
        }
        public async void Given_TeamDoesNotExist_When_CreateTeam_Then_ReturnTeam()
        {
            //Arrange
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.Send(
                                   It.IsAny <CreateTeamCommand>(),
                                   It.IsAny <CancellationToken>()
                                   ))
            .ReturnsAsync(Unit.Value);

            var controller = new TeamController(mockMediator.Object);
            var command    = new CreateTeamCommand {
                Name = "Liverpool", Country = "England"
            };

            //Act
            var result = await controller.CreateTeam(command);

            //Assert
            var okResult = result.Should().BeOfType <CreatedResult>().Subject;
        }
        public async void CreateTeam_UnSuccessful()
        {
            //Given
            Team team = new Team()
            {
                TeamName    = "Quinnox",
                Description = "Test team",
                TenantId    = 1
            };
            int teamCreatedCount = 0;

            teamServiceMoq.Setup(e => e.CreateTeam(team)).ReturnsAsync(teamCreatedCount);

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

            //Then
            Assert.IsType <NotFoundObjectResult>(response);
            Assert.Equal("Unsuccessfull while creating the Team", response.Value);
            teamServiceMoq.Verify(e => e.CreateTeam(team), Times.Once);
        }
        public async void Given_TeamDoesExist_When_CreateTeam_Then_ReturnBadRequest()
        {
            //Arrange
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.Send(
                                   It.IsAny <CreateTeamCommand>(),
                                   It.IsAny <CancellationToken>()
                                   ))
            .Throws(new TeamAlreadyExistsException("Liverpool"));

            var controller = new TeamController(mockMediator.Object);
            var command    = new CreateTeamCommand {
                Name = "Liverpool"
            };

            //Act
            var result = await controller.CreateTeam(command);

            //Assert
            var badRequestResult = result.Should().BeOfType <BadRequestObjectResult>().Subject;

            badRequestResult.Value.Should().Be("Team \"Liverpool\" already exists.");
        }
Example #15
0
        public void TestInit()
        {
            int testTeam1Id = -1;
            int testTeam2Id = -1;
            int testMapId   = -1;
            int testEventId = -1;

            //Instantiate controller
            UserController   = new UserController();
            TeamController   = new TeamController();
            PlayerController = new PlayerController();
            MatchController  = new MatchController();
            EventController  = new EventController();

            //Build test objects:

            //Account
            TestUserAccount = new Account {
                Balance = 1000.00M
            };

            //User
            TestUser = new User {
                Account     = TestUserAccount,
                FirstName   = "UserTestUser",
                LastName    = "UserTestUser",
                UserName    = "******",
                Email       = "UserTestUser",
                PhoneNumber = "12345678"
            };

            //Players
            TestPlayer1 = new Player {
                NickName = "TestPlayer1",
                Age      = "99",
                Role     = "Tester"
            };
            TestPlayer2 = new Player {
                NickName = "TestPlayer2",
                Age      = "99",
                Role     = "Tester"
            };
            TestPlayer3 = new Player {
                NickName = "TestPlayer3",
                Age      = "99",
                Role     = "Tester"
            };
            TestPlayer4 = new Player {
                NickName = "TestPlayer4",
                Age      = "99",
                Role     = "Tester"
            };
            TestPlayer5 = new Player {
                NickName = "TestPlayer5",
                Age      = "99",
                Role     = "Tester"
            };
            TestPlayer6 = new Player {
                NickName = "TestPlayer6",
                Age      = "99",
                Role     = "Tester"
            };
            TestPlayer7 = new Player {
                NickName = "TestPlayer7",
                Age      = "99",
                Role     = "Tester"
            };
            TestPlayer8 = new Player {
                NickName = "TestPlayer8",
                Age      = "99",
                Role     = "Tester"
            };
            TestPlayer9 = new Player {
                NickName = "TestPlayer9",
                Age      = "99",
                Role     = "Tester"
            };
            TestPlayer10 = new Player {
                NickName = "TestPlayer10",
                Age      = "99",
                Role     = "Tester"
            };

            //Team
            TestTeam1 = new Team {
                Name = "TeamTest1"
            };

            TestTeam2 = new Team {
                Name = "TeamTest2"
            };

            //Map
            TestMap = new Map {
                Name     = "TestMap",
                IsActive = true
            };

            //Match
            TestMatch = new Match {
                Format = "BOTest",
                Winner = TestTeam1
            };

            //Event
            TestEvent = new Event {
                Name     = "TestEvent",
                GameName = "TestGO",
                Type     = "Test",
                Held     = false
            };

            //Bet
            TestBet = new Bet {
                Amount       = 500.00M,
                Odds         = 1.78M,
                Type         = TestMatch,
                WinCondition = TestTeam1
            };

            //Create user
            UserController.CreateUser(TestUser);

            //Create teams
            testTeam1Id = TeamController.CreateTeam(TestTeam1);
            testTeam2Id = TeamController.CreateTeam(TestTeam2);

            //Add players to team 1
            TestTeam1.Players.Add(TestPlayer1);
            TestTeam1.Players.Add(TestPlayer2);
            TestTeam1.Players.Add(TestPlayer3);
            TestTeam1.Players.Add(TestPlayer4);
            TestTeam1.Players.Add(TestPlayer5);

            //Add team to players and create them
            foreach (Player p in TestTeam1.Players)
            {
                p.TeamId = testTeam1Id;
                p.Id     = PlayerController.CreatePlayer(p);
                Debug.WriteLine("T1: " + p.Id);
            }

            //Update team with players
            TeamController.EditTeam(TestTeam1);

            //Add players to team 2
            TestTeam2.Players.Add(TestPlayer6);
            TestTeam2.Players.Add(TestPlayer7);
            TestTeam2.Players.Add(TestPlayer8);
            TestTeam2.Players.Add(TestPlayer9);
            TestTeam2.Players.Add(TestPlayer10);

            //Add team to players and create them
            foreach (Player p in TestTeam2.Players)
            {
                p.TeamId = testTeam2Id;
                p.Id     = PlayerController.CreatePlayer(p);
                Debug.WriteLine("T2: " + p.Id);
            }

            //Update team with players
            TeamController.EditTeam(TestTeam2);

            //Persist map
            testMapId  = MatchController.CreateMap(TestMap);
            TestMap.Id = testMapId;

            //Add map to match
            TestMatch.Maps.Add(TestMap);
            TestMatch.Teams.Add(TestTeam1);
            TestMatch.Teams.Add(TestTeam2);

            //Persist event
            testEventId = EventController.CreateEvent(TestEvent);

            //Persist match
            TestMatch.EventId = testEventId;
            MatchController.CreateMatch(TestMatch);

            //Add match to event
            TestEvent.Matches.Add(TestMatch);
        }
Example #16
0
        public void TestInitialize()
        {
            _MatchController  = new MatchController();
            _EventController  = new EventController();
            _TeamController   = new TeamController();
            _PlayerController = new PlayerController();
            _TestEvent        = new Event {
                Name     = "testname",
                GameName = "testgame",
                Type     = "testtype"
            };
            _EventId = _EventController.CreateEvent(_TestEvent);

            _TestTeam1 = new Team {
                Name = "TestTeam"
            };

            _TestTeam2 = new Team {
                Name = "TestTeam2"
            };
            _TestTeam1Id      = _TeamController.CreateTeam(_TestTeam1);
            _TestTeam2Id      = _TeamController.CreateTeam(_TestTeam2);
            _TestTeam1Player1 = new Player {
                NickName = "TestPlayer",
                Age      = "123",
                Role     = "testRole",
                TeamId   = _TestTeam1Id
            };
            _PlayerController.CreatePlayer(_TestTeam1Player1);
            _TestTeam1Player2 = new Player {
                NickName = "TestPlayer",
                Age      = "123",
                Role     = "testRole",
                TeamId   = _TestTeam1Id
            };
            _PlayerController.CreatePlayer(_TestTeam1Player2);
            _TestTeam1Player3 = new Player {
                NickName = "TestPlayer",
                Age      = "123",
                Role     = "testRole",
                TeamId   = _TestTeam1Id
            };
            _PlayerController.CreatePlayer(_TestTeam1Player3);
            _TestTeam1Player4 = new Player {
                NickName = "TestPlayer",
                Age      = "123",
                Role     = "testRole",
                TeamId   = _TestTeam1Id
            };
            _PlayerController.CreatePlayer(_TestTeam1Player4);
            _TestTeam1Player5 = new Player {
                NickName = "TestPlayer",
                Age      = "123",
                Role     = "testRole",
                TeamId   = _TestTeam1Id
            };
            _PlayerController.CreatePlayer(_TestTeam1Player5);
            _TestTeam1.Players.Add(_TestTeam1Player1);
            _TestTeam1.Players.Add(_TestTeam1Player2);
            _TestTeam1.Players.Add(_TestTeam1Player3);
            _TestTeam1.Players.Add(_TestTeam1Player4);
            _TestTeam1.Players.Add(_TestTeam1Player5);

            _TestTeam2Player1 = new Player {
                NickName = "TestPlayer",
                Age      = "123",
                Role     = "testRole",
                TeamId   = _TestTeam2Id
            };
            _PlayerController.CreatePlayer(_TestTeam2Player1);
            _TestTeam2Player2 = new Player {
                NickName = "TestPlayer",
                Age      = "123",
                Role     = "testRole",
                TeamId   = _TestTeam2Id
            };
            _PlayerController.CreatePlayer(_TestTeam2Player2);
            _TestTeam2Player3 = new Player {
                NickName = "TestPlayer",
                Age      = "123",
                Role     = "testRole",
                TeamId   = _TestTeam2Id
            };
            _PlayerController.CreatePlayer(_TestTeam2Player3);
            _TestTeam2Player4 = new Player {
                NickName = "TestPlayer",
                Age      = "123",
                Role     = "testRole",
                TeamId   = _TestTeam2Id
            };
            _PlayerController.CreatePlayer(_TestTeam2Player4);
            _TestTeam2Player5 = new Player {
                NickName = "TestPlayer",
                Age      = "123",
                Role     = "testRole",
                TeamId   = _TestTeam2Id
            };
            _PlayerController.CreatePlayer(_TestTeam2Player5);
            _TestTeam2.Players.Add(_TestTeam2Player1);
            _TestTeam2.Players.Add(_TestTeam2Player2);
            _TestTeam2.Players.Add(_TestTeam2Player3);
            _TestTeam2.Players.Add(_TestTeam2Player4);
            _TestTeam2.Players.Add(_TestTeam2Player5);
            _TestMatch = new Match {
                Format  = "TestFormat",
                Winner  = null,
                EventId = _EventId
            };
            _TestMatch.Teams.Add(_TestTeam1);
            _TestMatch.Teams.Add(_TestTeam2);
            _TestMatch.GenerateName(_TestTeam1, _TestTeam2);

            _TestMap = new Map {
                Name     = "TestMap",
                IsActive = true
            };
            _TestMap.Id = _MatchController.CreateMap(_TestMap);
            _TestMatch.Maps.Add(_TestMap);
        }
Example #17
0
        // Team Operationcontracts Implemented

        /// <summary>
        /// Persists team
        /// </summary>
        /// <param name="team"></param>
        /// <returns>TeamId given to persisted team</returns>
        public int CreateTeam(Team team)
        {
            return(teamController.CreateTeam(team));
        }