예제 #1
0
        public void CreateSportOkSportsController()
        {
            sportServicesMock.Setup(s => s.CreateSport(It.IsAny <SportDTO>()));
            ILoginServices login = new LoginServicesMock(mariano);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new SportsController(login, sportServicesMock.Object, encounterServicesMock.Object, encounterQueryServices.Object, positionServicesMock.Object, teamServicesMock.Object)
            {
                ControllerContext = controllerContext,
            };

            SportDTO footballIn = new SportDTO()
            {
                Name = "Futbol"
            };
            var result = controller.CreateSport(footballIn);

            sportServicesMock.Verify(s => s.CreateSport(It.IsAny <SportDTO>()), Times.AtMostOnce);
            var createdResult = result as CreatedAtRouteResult;
            var footballOut   = createdResult.Value as SportDTO;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual("GetSport", createdResult.RouteName);
            Assert.AreEqual(201, createdResult.StatusCode);
            Assert.AreEqual(footballIn.Name, footballOut.Name);
        }
예제 #2
0
        public void GetSportsByNameOkSportsController()
        {
            sportServicesMock.Setup(s => s.GetSport(football.Name)).Returns(football);



            ILoginServices login = new LoginServicesMock(mariano);

            var httpContext = new DefaultHttpContext();

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

            var obtainedResult = controller.GetSportById(football.Name) as ActionResult <SportModelOut>;
            var val            = obtainedResult.Value;

            sportServicesMock.Verify(s => s.GetSport(football.Name), Times.AtMostOnce);

            Assert.IsNotNull(obtainedResult);
            Assert.IsNotNull(obtainedResult.Value);
            SportModelOut sport = obtainedResult.Value;

            Assert.AreEqual(football.Name, sport.Name);
        }
예제 #3
0
        public void GetAllEncountersOfASpecificSport2()
        {
            string sportName          = "Tennis";
            var    expectedEncounters = new List <EncounterDTO>()
            {
            };

            var encounterQueryServicesMock = new Mock <IEncounterQueryServices>();

            encounterQueryServicesMock.Setup(s => s.GetEncountersBySport(sportName)).Returns(expectedEncounters);
            ILoginServices login = new LoginServicesMock(mariano);

            var httpContext = new DefaultHttpContext();

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

            var obtainedResult = controller.GetEncountersBySport("Tennis") as ActionResult <List <EncounterModelOut> >;
            var value          = obtainedResult.Result;

            encounterServicesMock.VerifyAll();
            Assert.IsNull(value);
        }
예제 #4
0
        public void GetAllSportsOkSportsController()
        {
            var expectedSports = new List <SportDTO>()
            {
                football, tennis
            };

            sportServicesMock.Setup(s => s.GetAllSports()).Returns(expectedSports);

            var encounterQueryServicesMock = new Mock <IEncounterQueryServices>();

            ILoginServices login = new LoginServicesMock(mariano);

            var httpContext = new DefaultHttpContext();

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

            var obtainedResult = controller.GetAllSports() as ActionResult <List <SportModelOut> >;
            var val            = obtainedResult.Value;

            sportServicesMock.Verify(s => s.GetAllSports(), Times.AtMostOnce);

            Assert.IsNotNull(obtainedResult);
            Assert.IsNotNull(obtainedResult.Value);
            Assert.AreEqual(expectedSports[0].Name, obtainedResult.Value[0].Name);
        }
        public void CatchServicesExceptionTryToGetAllEncounters()
        {
            ILoginServices loginServices = new LoginServicesMock(santiago);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };

            encounterServicesMock.Setup(m => m.GetAllEncounters()).Throws(new ServicesException());

            var controller = new EncountersController(loginServices, encounterServicesMock.Object, new LoggerStub(), encounterQueryServices.Object, fixtureGeneratorServices.Object, teamServices.Object)
            {
                ControllerContext = controllerContext,
            };

            var obtainedResult = controller.GetAllEncounters(new DateTime(), new DateTime()) as ActionResult <List <EncounterModelOut> >;

            encounterServicesMock.Verify(e => e.GetAllEncounters(), Times.AtMostOnce());
            var result = obtainedResult.Result as BadRequestObjectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(400, result.StatusCode);
        }
예제 #6
0
        public void GetUserOkUsersWithoutExistsController()
        {
            var expectedUser    = juan;
            var mockUserService = new Mock <IUserServices>();

            mockUserService.Setup(bl => bl.GetUser(expectedUser.UserName)).Throws(new ServicesException());
            ILoginServices loginServices = new LoginServicesMock(pablo);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new UsersController(loginServices, mockUserService.Object, encounterServices.Object, encounterQueryServices.Object)
            {
                ControllerContext = controllerContext,
            };

            mockUserService.Verify(m => m.GetUser(expectedUser.UserName), Times.AtMostOnce());
            var obtainedResult = controller.GetUserById(expectedUser.UserName);
            var result         = obtainedResult.Result as NotFoundObjectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(404, result.StatusCode);
        }
        public void CreateTeamWithoutPermissionTeamsController()
        {
            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(It.IsAny <TeamDTO>())).Throws(new InsufficientPermissionException());
            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(It.IsAny <TeamDTO>()), Times.AtMostOnce);
            var unauthorizedResult = result as UnauthorizedResult;

            Assert.IsNotNull(unauthorizedResult);
            Assert.AreEqual(401, unauthorizedResult.StatusCode);
        }
        public void GetAvailableFixtureGeneratorsTest()
        {
            ILoginServices loginServices = new LoginServicesMock(santiago);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            List <string> expected = new List <string>()
            {
                "RoundRobinFixture", "AllOnceFixture"
            };

            fixtureGeneratorServices.Setup(s => s.GetAvailableFixtureGenerators()).Returns(expected);
            var controller = new EncountersController(loginServices, encounterServicesMock.Object, new LoggerStub(), encounterQueryServices.Object, fixtureGeneratorServices.Object, teamServices.Object)
            {
                ControllerContext = controllerContext,
            };
            var actual = controller.GetAvailableFixtureGenerators();

            Assert.IsTrue(expected.Count() == actual.Value.Count);
            Assert.IsTrue(actual.Value.Contains("RoundRobinFixture"));
            Assert.IsTrue(actual.Value.Contains("AllOnceFixture"));
        }
        public void GenerateFixtureOkTest()
        {
            ILoginServices loginServices = new LoginServicesMock(santiago);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            List <EncounterDTO> expected = new List <EncounterDTO>()
            {
                new EncounterDTO()
                {
                    Id = IntToGuid(1)
                }, new EncounterDTO()
                {
                    Id = IntToGuid(2)
                }
            };

            fixtureGeneratorServices.Setup(s => s.CreateFixture("RoundRobinFixture", "Futbol", new DateTime(3000, 10, 10))).Returns(expected);
            var controller = new EncountersController(loginServices, encounterServicesMock.Object, new LoggerStub(), encounterQueryServices.Object, fixtureGeneratorServices.Object, teamServices.Object)
            {
                ControllerContext = controllerContext,
            };
            IActionResult actual = controller.CreateFixture(new FixtureModelIn()
            {
                CreationAlgorithmName = "RoundRobinFixture", SportName = "Futbol", StartingDate = new DateTime(3000, 10, 10)
            });

            Assert.IsInstanceOfType(actual, typeof(OkObjectResult));
        }
        public void GetCommentsOfEncounterWithoutExistsEncountersController()
        {
            ILoginServices loginServices = new LoginServicesMock(santiago);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };

            encounterQueryServices.Setup(m => m.GetAllCommentsToOneEncounter("1")).Throws(new ServicesException());

            var controller = new EncountersController(loginServices, encounterServicesMock.Object, new LoggerStub(), encounterQueryServices.Object, fixtureGeneratorServices.Object, teamServices.Object)
            {
                ControllerContext = controllerContext,
            };

            var obtainedResult = controller.GetEncounterComments("1") as ActionResult <IEnumerable <CommentDTO> >;

            encounterQueryServices.Verify(e => e.GetAllCommentsToOneEncounter("1"), Times.AtMostOnce());
            var result = obtainedResult.Result as BadRequestObjectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(400, result.StatusCode);
        }
예제 #11
0
        public void CreateUserAllreadyExistsUsersController()
        {
            var modelIn = new UserModelIn()
            {
                UserName = "******", Name = "Alberto", Surname = "Lacaze", Mail = "*****@*****.**", Password = "******", IsAdmin = true
            };
            var fakeUser = new UserDTO()
            {
                UserName = "******", Surname = "Avila", Name = "Pepe", Password = "******", Mail = "*****@*****.**", IsAdmin = true
            };

            var userServicesMock = new Mock <IUserServices>();

            userServicesMock.Setup(userService => userService.CreateUser(It.IsAny <UserDTO>())).Throws(new ServicesException());
            ILoginServices loginServices = new LoginServicesMock(pablo);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new UsersController(loginServices, userServicesMock.Object, encounterServices.Object, encounterQueryServices.Object)
            {
                ControllerContext = controllerContext,
            };

            userServicesMock.Verify(m => m.CreateUser(It.IsAny <UserDTO>()), Times.AtMostOnce());
            var result        = controller.CreateUser(modelIn);
            var createdResult = result as BadRequestObjectResult;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual(400, createdResult.StatusCode);
        }
예제 #12
0
        public void CreateSportAlreadyExistsSportsController()
        {
            sportServicesMock.Setup(s => s.CreateSport(It.IsAny <SportDTO>())).Throws(new ServicesException());


            ILoginServices login = new LoginServicesMock(rodolfo);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new SportsController(login, sportServicesMock.Object, encounterServicesMock.Object, encounterQueryServices.Object, positionServicesMock.Object, teamServicesMock.Object)
            {
                ControllerContext = controllerContext,
            };

            SportDTO footballIn = new SportDTO()
            {
                Name = "Futbol"
            };
            var result = controller.CreateSport(footballIn);

            sportServicesMock.Verify(s => s.CreateSport(It.IsAny <SportDTO>()), Times.AtMostOnce);
            var createdResult = result as BadRequestObjectResult;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual(400, createdResult.StatusCode);
        }
        public void ServicesExceptionWhenTryToGetAllTeamsOkTeamsController()
        {
            var teamServicesMock           = new Mock <ITeamServices>();
            var encounterServicesMock      = new Mock <IEncounterSimpleServices>();
            var encounterQueryServicesMock = new Mock <IEncounterQueryServices>();

            teamServicesMock.Setup(t => t.GetAllTeams()).Throws(new ServicesException());
            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.GetAllTeams();

            teamServicesMock.Verify(t => t.GetAllTeams(), Times.AtMostOnce);
            var value         = result as ActionResult <List <TeamModelOut> >;
            var resultRequest = result.Result as BadRequestObjectResult;

            Assert.IsNotNull(resultRequest);
            Assert.AreEqual(400, resultRequest.StatusCode);
        }
예제 #14
0
        public void GetAllUsersOkUsersController()
        {
            var expectedUsers = new List <UserDTO> {
                juan, roberto
            };

            var userServicesMock = new Mock <IUserServices>();

            userServicesMock.Setup(us => us.GetAllUsers()).Returns(expectedUsers);
            ILoginServices loginServices = new LoginServicesMock(pablo);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new UsersController(loginServices, userServicesMock.Object, encounterServices.Object, encounterQueryServices.Object)
            {
                ControllerContext = controllerContext,
            };

            var obtainedResult = controller.GetAllUsers() as ActionResult <List <UserModelOut> >;
            var value          = obtainedResult.Value;

            userServicesMock.Verify(us => us.GetAllUsers(), Times.AtMostOnce);

            Assert.IsNotNull(obtainedResult);
            Assert.IsNotNull(value);
            Assert.AreEqual(2, value.Count);
            Assert.AreEqual(juan.Name, value.ElementAt(0).Name);
            Assert.AreEqual(roberto.Name, value.ElementAt(1).Name);
        }
        public void GetEncountersByTeamWithoutExistsTeamTeamsController()
        {
            var teamServicesMock           = new Mock <ITeamServices>();
            var encounterServicesMock      = new Mock <IEncounterSimpleServices>();
            var encounterQueryServicesMock = new Mock <IEncounterQueryServices>();

            string teamName = "Team_Sport";

            encounterQueryServicesMock.Setup(e => e.GetEncountersByTeam(teamName)).Throws(new ServicesException());
            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.GetTeamEncounters(teamName);

            encounterQueryServicesMock.Verify(e => e.GetEncountersByTeam(teamName), Times.AtMostOnce);
            var value         = result as ActionResult <List <EncounterModelOut> >;
            var requestResult = value.Result as BadRequestObjectResult;

            Assert.IsNotNull(requestResult);
            Assert.AreEqual(400, requestResult.StatusCode);
        }
예제 #16
0
        public void ServicesExceptionGetAllUsersUsersController()
        {
            var expectedUsers = new List <UserDTO> {
                juan, roberto
            };

            var userServicesMock = new Mock <IUserServices>();

            userServicesMock.Setup(us => us.GetAllUsers()).Throws(new ServicesException());
            ILoginServices loginServices = new LoginServicesMock(pablo);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new UsersController(loginServices, userServicesMock.Object, encounterServices.Object, encounterQueryServices.Object)
            {
                ControllerContext = controllerContext,
            };

            var obtainedResult = controller.GetAllUsers() as ActionResult <List <UserModelOut> >;
            var value          = obtainedResult.Result as BadRequestObjectResult;

            userServicesMock.Verify(us => us.GetAllUsers(), Times.AtMostOnce);

            Assert.IsNotNull(obtainedResult);
            Assert.AreEqual(400, value.StatusCode);
        }
예제 #17
0
        public void ServicesExceptionTryToGetCommentariesOfLoggedUserUsersController()
        {
            var            userServicesMock           = new Mock <IUserServices>();
            var            encounterServicesMock      = new Mock <IEncounterSimpleServices>();
            var            encounterQueryServicesMock = new Mock <IEncounterQueryServices>();
            ILoginServices loginServices = new LoginServicesMock(pablo);

            encounterQueryServicesMock.Setup(e => e.GetAllEncountersWithFollowedTeams()).Throws(new ServicesException());

            var httpContext = new DefaultHttpContext();

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

            encounterQueryServicesMock.Verify(u => u.GetAllEncountersWithFollowedTeams(), Times.AtMostOnce);

            var obtainedResult = controller.GetFollowedTeamCommentariesOfLoggedUser();
            var resultRequest  = obtainedResult.Result as BadRequestObjectResult;

            Assert.IsNotNull(resultRequest);
            Assert.AreEqual(400, resultRequest.StatusCode);
        }
예제 #18
0
        public void DeleteUserWithoutPermissionUsersController()
        {
            var modelIn = new UserModelIn();

            var userServicesMock = new Mock <IUserServices>();

            string id = "pepe";

            userServicesMock.Setup(us => us.DeleteUser(id)).Throws(new InsufficientPermissionException());
            ILoginServices loginServices = new LoginServicesMock(pablo);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new UsersController(loginServices, userServicesMock.Object, encounterServices.Object, encounterQueryServices.Object)
            {
                ControllerContext = controllerContext,
            };

            userServicesMock.Verify(m => m.DeleteUser(id), Times.AtMostOnce());
            var result        = controller.DeleteUser(id);
            var createdResult = result as UnauthorizedResult;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual(401, createdResult.StatusCode);
        }
예제 #19
0
        public void GetLogedUserFollowedTeamsOkUsersController()
        {
            var userServicesMock = new Mock <IUserServices>();

            userServicesMock.Setup(services => services.GetFollowedTeams()).Returns(() => new List <TeamDTO>()
            {
                new TeamDTO()
                {
                    Name = "Atletics"
                }, new TeamDTO()
                {
                    Name = "Yankees"
                }
            });
            ILoginServices loginServices = new LoginServicesMock(pablo);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new UsersController(loginServices, userServicesMock.Object, encounterServices.Object, encounterQueryServices.Object)
            {
                ControllerContext = controllerContext,
            };

            List <string> result = controller.GetFollowedTeams().Value.Select(t => t.Name).ToList();

            Assert.AreEqual("Atletics", result[0]);
            Assert.AreEqual("Yankees", result[1]);
        }
예제 #20
0
        public void CreateBadModelInUsersController()
        {
            var modelIn = new UserModelIn();

            var            userService   = new Mock <IUserServices>();
            ILoginServices loginServices = new LoginServicesMock(pablo);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new UsersController(loginServices, userService.Object, encounterServices.Object, encounterQueryServices.Object)
            {
                ControllerContext = controllerContext,
            };

            controller.ModelState.AddModelError("", "Error");
            var result = controller.CreateUser(modelIn);

            var createdResult = result as BadRequestResult;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual(400, createdResult.StatusCode);
        }
        public void DeleteEncounterWithoutExistsEncountersController()
        {
            ILoginServices loginServices = new LoginServicesMock(santiago);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };

            encounterServicesMock.Setup(m => m.DeleteEncounter("1")).Throws(new ServicesException());

            var controller = new EncountersController(loginServices, encounterServicesMock.Object, new LoggerStub(), encounterQueryServices.Object, fixtureGeneratorServices.Object, teamServices.Object)
            {
                ControllerContext = controllerContext,
            };

            var obtainedResult = controller.DeleteEncounter("1") as BadRequestObjectResult;

            encounterServicesMock.Verify(e => e.DeleteEncounter("1"), Times.AtMostOnce());

            Assert.IsNotNull(obtainedResult);
            Assert.AreEqual(400, obtainedResult.StatusCode);
        }
예제 #22
0
        public void CreateUserWithoutPermissionUsersController()
        {
            var modelIn = new UserModelIn()
            {
                UserName = "******", Name = "Alberto", Surname = "Lacaze", Mail = "*****@*****.**", Password = "******", IsAdmin = false
            };

            var userServicesMock = new Mock <IUserServices>();

            userServicesMock.Setup(userService => userService.CreateUser(It.IsAny <UserDTO>())).Throws(new InsufficientPermissionException());
            ILoginServices loginServices = new LoginServicesMock(roberto);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new UsersController(loginServices, userServicesMock.Object, encounterServices.Object, encounterQueryServices.Object)
            {
                ControllerContext = controllerContext,
            };

            var result        = controller.CreateUser(modelIn);
            var createdResult = result as UnauthorizedResult;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual(401, createdResult.StatusCode);
        }
예제 #23
0
        public void DeleteSportWithoutPermissionSportsController()
        {
            string name    = "Futbol";
            var    modelIn = new SportDTO()
            {
                Name = name
            };


            sportServicesMock.Setup(s => s.DeleteSport(name)).Throws(new InsufficientPermissionException());



            ILoginServices loginServices = new LoginServicesMock(mariano);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new SportsController(loginServices, sportServicesMock.Object, encounterServicesMock.Object, encounterQueryServices.Object, positionServicesMock.Object, teamServicesMock.Object)
            {
                ControllerContext = controllerContext,
            };

            var result = controller.DeleteSport(name);

            sportServicesMock.Verify(s => s.DeleteSport(name), Times.AtMostOnce);
            var badRequestResult = result as UnauthorizedResult;

            Assert.AreEqual(401, badRequestResult.StatusCode);
        }
예제 #24
0
        public void GetUserOkUsersController()
        {
            var expectedUser    = juan;
            var mockUserService = new Mock <IUserServices>();

            mockUserService.Setup(bl => bl.GetUser(expectedUser.UserName)).Returns(expectedUser);
            ILoginServices loginServices = new LoginServicesMock(pablo);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new UsersController(loginServices, mockUserService.Object, encounterServices.Object, encounterQueryServices.Object)
            {
                ControllerContext = controllerContext,
            };

            mockUserService.Verify(m => m.GetUser(expectedUser.UserName), Times.AtMostOnce());
            var obtainedResult = controller.GetUserById(expectedUser.UserName) as ActionResult <UserModelOut>;

            Assert.IsNotNull(obtainedResult);
            Assert.IsNotNull(obtainedResult.Value);
            Assert.AreEqual(obtainedResult.Value, new UserModelOut(expectedUser));
        }
        public void TryToDeleteTeamWithoutExistsTeamsController()
        {
            var teamServicesMock           = new Mock <ITeamServices>();
            var encounterServicesMock      = new Mock <IEncounterSimpleServices>();
            var encounterQueryServicesMock = new Mock <IEncounterQueryServices>();

            string teamName = "Team_Sport";

            teamServicesMock.Setup(t => t.DeleteTeam(teamName)).Throws(new ServicesException());
            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.DeleteTeam(teamName);

            teamServicesMock.Verify(t => t.DeleteTeam(teamName), Times.AtMostOnce);
            var resultRequest = result as BadRequestObjectResult;

            Assert.IsNotNull(resultRequest);
            Assert.AreEqual(400, resultRequest.StatusCode);
        }
예제 #26
0
        public void GetCommentariesOfLoggedUserUsersController()
        {
            var            userServicesMock           = new Mock <IUserServices>();
            var            encounterServicesMock      = new Mock <IEncounterSimpleServices>();
            var            encounterQueryServicesMock = new Mock <IEncounterQueryServices>();
            ILoginServices loginServices = new LoginServicesMock(pablo);

            EncounterDTO encounter = new EncounterDTO()
            {
                SportName = "Futbol", DateTime = new DateTime(3018 / 08 / 08), TeamIds = new List <string>()
                {
                    "team1", "team2"
                }
            };
            List <EncounterDTO> encounters = new List <EncounterDTO>()
            {
                encounter
            };
            CommentDTO comment = new CommentDTO()
            {
                Message = "This is a test comment!", UserName = pablo.UserName, TimeStamp = new DateTime(2019 / 03 / 03)
            };
            List <CommentDTO> comments = new List <CommentDTO>()
            {
                comment
            };

            encounterQueryServicesMock.Setup(e => e.GetAllEncountersWithFollowedTeams()).Returns(encounters);
            encounterQueryServicesMock.Setup(e => e.GetAllCommentsToOneEncounter(It.IsAny <string>())).Returns(comments);

            var httpContext = new DefaultHttpContext();

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

            encounterQueryServicesMock.Verify(u => u.GetAllEncountersWithFollowedTeams(), Times.AtMostOnce);
            encounterQueryServicesMock.Verify(u => u.GetAllCommentsToOneEncounter(It.IsAny <string>()), Times.AtMostOnce);
            var obtainedResult = controller.GetFollowedTeamCommentariesOfLoggedUser();
            var commentaries   = obtainedResult.Value as List <CommentDTO>;

            Assert.IsNotNull(commentaries);
            Assert.AreEqual(comment.Message, commentaries[0].Message);
            Assert.AreEqual(comment.UserName, commentaries[0].UserName);
            Assert.AreEqual(comment.TimeStamp, commentaries[0].TimeStamp);
        }
        public void AddCommentToEncounterDoesNotExistsEncountersController()
        {
            var encounterServices        = new Mock <IEncounterSimpleServices>();
            var encounterQueryServices   = new Mock <IEncounterQueryServices>();
            var fixtureGeneratorServices = new Mock <IFixtureServices>();

            ILoginServices loginServices = new LoginServicesMock(santiago);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };

            EncounterDTO encounter = new EncounterDTO()
            {
                Id = IntToGuid(4), SportName = "Futbol", TeamIds = new List <string>()
                {
                    "Peñarol", "Nacional"
                }
            };
            IEnumerable <EncounterDTO> encounters = new List <EncounterDTO>()
            {
                encounter
            };

            encounterServices.Setup(e => e.AddComment(4 + "", "This is a test comment in a mock!")).Throws(new ServicesException());

            var controller = new EncountersController(loginServices, encounterServices.Object, new LoggerStub(), encounterQueryServices.Object, fixtureGeneratorServices.Object, teamServices.Object)
            {
                ControllerContext = controllerContext,
            };

            var comment = new CommentModelIn()
            {
                Message = "This is a test comment in a mock!"
            };
            var obtainedResult = controller.AddEncounterComment(4 + "", comment) as BadRequestObjectResult;

            encounterServices.Verify(m => m.AddComment(4 + "", "This is a test comment in a mock!"), Times.AtMostOnce());

            Assert.IsNotNull(obtainedResult);
            Assert.AreEqual(400, obtainedResult.StatusCode);
        }
        public void GetAllTeamsOkTeamsController()
        {
            var teamServicesMock           = new Mock <ITeamServices>();
            var encounterServicesMock      = new Mock <IEncounterSimpleServices>();
            var encounterQueryServicesMock = new Mock <IEncounterQueryServices>();

            TeamDTO team1 = new TeamDTO()
            {
                Name = "Team1", SportName = "Futbol"
            };
            TeamDTO team2 = new TeamDTO()
            {
                Name = "Team2", SportName = "Futbol"
            };
            List <TeamDTO> teams = new List <TeamDTO>()
            {
                team1, team2
            };

            teamServicesMock.Setup(t => t.GetAllTeams()).Returns(teams);
            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.GetAllTeams();

            teamServicesMock.Verify(t => t.GetAllTeams(), Times.AtMostOnce);
            var resultRequest = result as ActionResult <List <TeamModelOut> >;

            Assert.IsNotNull(resultRequest);
            Assert.IsNotNull(resultRequest.Value);
            Assert.AreEqual(team1.SportName, resultRequest.Value[0].SportName);
            Assert.AreEqual(team1.Name, resultRequest.Value[0].Name);
            Assert.AreEqual(team2.SportName, resultRequest.Value[1].SportName);
            Assert.AreEqual(team2.Name, resultRequest.Value[1].Name);
        }
        public void GetEncountersByTeamOkTeamsController()
        {
            var teamServicesMock           = new Mock <ITeamServices>();
            var encounterServicesMock      = new Mock <IEncounterSimpleServices>();
            var encounterQueryServicesMock = new Mock <IEncounterQueryServices>();

            EncounterDTO encounter = new EncounterDTO()
            {
                TeamIds = new List <string>()
                {
                    "team1", "team2"
                }, SportName = "Sport"
            };
            string teamName = "Team_Sport";
            List <EncounterDTO> encounters = new List <EncounterDTO>()
            {
                encounter
            };

            encounterQueryServicesMock.Setup(e => e.GetEncountersByTeam(teamName)).Returns(encounters);
            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.GetTeamEncounters(teamName);

            encounterQueryServicesMock.Verify(e => e.GetEncountersByTeam(teamName), Times.AtMostOnce);
            var resultRequest = result as ActionResult <List <EncounterModelOut> >;
            List <EncounterModelOut> obtaniedEncounters = resultRequest.Value;

            Assert.IsNotNull(result);
            Assert.IsNotNull(resultRequest);
            Assert.AreEqual(encounter.SportName, obtaniedEncounters[0].SportName);
            Assert.AreEqual(encounter.TeamIds.First(), obtaniedEncounters[0].TeamIds.First());
            Assert.AreEqual(encounter.TeamIds.Last(), obtaniedEncounters[0].TeamIds.Last());
        }
        public void GetAllEncountersOkEncountersController()
        {
            ILoginServices loginServices = new LoginServicesMock(santiago);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };

            DateTime encounterDate = new DateTime(2018, 12, 10);

            EncounterDTO enc = new EncounterDTO();

            enc.SportName = football.Name;
            enc.TeamIds   = new List <string>()
            {
                river.Name, boca.Name
            };
            enc.DateTime = encounterDate;

            List <EncounterDTO> encs = new List <EncounterDTO>()
            {
                enc
            };

            encounterServicesMock.Setup(m => m.GetAllEncounters()).Returns(encs);

            var controller = new EncountersController(loginServices, encounterServicesMock.Object, new LoggerStub(), encounterQueryServices.Object, fixtureGeneratorServices.Object, teamServices.Object)
            {
                ControllerContext = controllerContext,
            };

            var obtainedResult = controller.GetAllEncounters(new DateTime(), new DateTime()) as ActionResult <List <EncounterModelOut> >;

            encounterServicesMock.Verify(e => e.GetAllEncounters(), Times.AtMostOnce());


            Assert.IsNotNull(obtainedResult);
            Assert.AreEqual(enc.Id, obtainedResult.Value[0].Id);
            Assert.AreEqual(enc.SportName, obtainedResult.Value[0].SportName);
            Assert.AreEqual(enc.TeamIds.First(), obtainedResult.Value[0].TeamIds.First());
        }