public void CreateTeamOkTeamsController()
        {
            var teamServicesMock           = new Mock <ITeamServices>();
            var encounterServicesMock      = new Mock <IEncounterSimpleServices>();
            var encounterQueryServicesMock = new Mock <IEncounterQueryServices>();

            TeamModelIn teamIn = new TeamModelIn()
            {
                Name = "Cavaliers", SportName = "Futbol"
            };

            teamServicesMock.Setup(t => t.CreateTeam(teamIn.Map())).Returns(new TeamDTO()
            {
                Name = "Cavaliers", SportName = "Futbol"
            });
            ILoginServices login = new LoginServicesMock(mariano);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new TeamsController(login, teamServicesMock.Object, encounterServicesMock.Object, encounterQueryServicesMock.Object)
            {
                ControllerContext = controllerContext,
            };

            var result = controller.CreateTeam(teamIn);

            teamServicesMock.Verify(t => t.CreateTeam(teamIn.Map()), Times.AtMostOnce);
            var createdResult = result as CreatedAtRouteResult;
            var teamOut       = createdResult.Value as TeamDTO;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual("GetTeam", createdResult.RouteName);
            Assert.AreEqual(201, createdResult.StatusCode);
            Assert.AreEqual(teamIn.Name, teamOut.Name);
        }
        public void UpdateTeamOkTeamsController()
        {
            var teamServicesMock           = new Mock <ITeamServices>();
            var encounterServicesMock      = new Mock <IEncounterSimpleServices>();
            var encounterQueryServicesMock = new Mock <IEncounterQueryServices>();

            TeamModelIn team1 = new TeamModelIn()
            {
                Name = "Team1", SportName = "Futbol"
            };

            string teamId = "Team1_Futbol";

            teamServicesMock.Setup(t => t.UpdateTeam(team1.Map()));
            ILoginServices login = new LoginServicesMock(mariano);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new TeamsController(login, teamServicesMock.Object, encounterServicesMock.Object, encounterQueryServicesMock.Object)
            {
                ControllerContext = controllerContext,
            };

            var result = controller.ModifyTeam(teamId, team1);

            teamServicesMock.Verify(t => t.UpdateTeam(team1.Map()), Times.AtMostOnce);
            var resultRequest = result as OkResult;

            Assert.IsNotNull(resultRequest);
            Assert.AreEqual(200, resultRequest.StatusCode);
        }
示例#3
0
 public IActionResult ModifyTeam(string id, [FromBody] TeamModelIn team)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     try
     {
         return(TryToUpdate(team.Map()));
     }
     catch (InsufficientPermissionException)
     {
         return(Unauthorized());
     }
 }
示例#4
0
 public IActionResult CreateTeam(TeamModelIn team)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     try
     {
         CreateSession();
         return(TryToCreate(team.Map()));
     }
     catch (InsufficientPermissionException)
     {
         return(Unauthorized());
     }
 }