Example #1
0
        public void PutUserNoDataAccessTest()
        {
            //Arrange.
            UpdateUserModelIn modelIn = new UpdateUserModelIn()
            {
                Name     = "name1",
                Surname  = "surname1",
                Password = "******",
                Email    = "*****@*****.**"
            };
            Exception internalEx = new DataInaccessibleException();
            Exception toThrow    = new ServiceException(internalEx.Message, ErrorType.DATA_INACCESSIBLE);

            service.Setup(us => us.ModifyUser(It.IsAny <UserDto>())).Throws(toThrow);

            //Act.
            IActionResult result = controller.Put("username", modelIn);
            ObjectResult  noData = result as ObjectResult;
            ErrorModelOut error  = noData.Value as ErrorModelOut;

            //Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(noData);
            Assert.AreEqual(500, noData.StatusCode);
            Assert.IsNotNull(error);
            Assert.AreEqual(toThrow.Message, error.ErrorMessage);
        }
        public void ShouldReturn500IfCantAccessData()
        {
            Exception internalEx = new DataInaccessibleException();
            Exception toThrow    = new ServiceException(internalEx.Message, ErrorType.DATA_INACCESSIBLE);

            fakeToursStorage.Setup(s => s.GetTourById(It.IsAny <int>())).Throws(toThrow);

            IActionResult result   = controller.Get(2);
            ObjectResult  notFound = result as ObjectResult;
            ErrorDto      error    = notFound.Value as ErrorDto;

            Assert.IsNotNull(result);
            Assert.IsNotNull(notFound);
            Assert.AreEqual(500, notFound.StatusCode);
            Assert.IsNotNull(error);
            Assert.AreEqual(toThrow.Message, error.ErrorMessage);
        }
        public void ShouldReturn500IfCantAccessDataInGET()
        {
            Exception internalEx = new DataInaccessibleException();
            Exception toThrow    = new ServiceException(internalEx.Message, ErrorType.DATA_INACCESSIBLE);

            fakeLandmarksService.Setup(s => s.GetLandmarkById(It.IsAny <int>())).Throws(toThrow);

            IActionResult result = controller.Get(2);
            ObjectResult  internalServerError = result as ObjectResult;
            ErrorDto      error = internalServerError.Value as ErrorDto;

            fakeLandmarksService.Verify(l => l.GetLandmarkById(2), Times.Once);
            Assert.IsNotNull(result);
            Assert.IsNotNull(internalServerError);
            Assert.AreEqual(500, internalServerError.StatusCode);
            Assert.IsNotNull(error);
            Assert.AreEqual(toThrow.Message, error.ErrorMessage);
        }
Example #4
0
        public void GetFollowedTeamsNoDataAccessTest()
        {
            //Arrange.
            Exception internalEx = new DataInaccessibleException();
            Exception toThrow    = new ServiceException(internalEx.Message, ErrorType.DATA_INACCESSIBLE);

            service.Setup(us => us.GetUserTeams(It.IsAny <string>())).Throws(toThrow);

            //Act.
            IActionResult result  = controller.GetFollowedTeams("username");
            ObjectResult  notData = result as ObjectResult;
            ErrorModelOut error   = notData.Value as ErrorModelOut;

            //Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(notData);
            Assert.AreEqual(500, notData.StatusCode);
            Assert.IsNotNull(error);
            Assert.AreEqual(toThrow.Message, error.ErrorMessage);
        }
Example #5
0
        public void DeleteNoDataAccessTest()
        {
            //Arrange.
            Exception internalEx = new DataInaccessibleException();
            Exception toThrow    = new ServiceException(internalEx.Message, ErrorType.DATA_INACCESSIBLE);

            sportsService.Setup(r => r.DeleteSport("Golf")).Throws(toThrow);

            //Act.
            IActionResult result = controllerToTest.Delete("Golf");
            ObjectResult  noData = result as ObjectResult;
            ErrorModelOut error  = noData.Value as ErrorModelOut;

            //Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(noData);
            Assert.AreEqual(500, noData.StatusCode);
            Assert.IsNotNull(error);
            Assert.AreEqual(toThrow.Message, error.ErrorMessage);
        }
        public void CreateNoDataAccessTest()
        {
            //Arrange.
            Exception toThrow = new DataInaccessibleException();

            teamsService.Setup(tr => tr.AddTeam(It.IsAny <TeamDto>())).Throws(new ServiceException(toThrow.Message, ErrorType.DATA_INACCESSIBLE));
            TeamModelIn input = CreateTeamModelIn();

            //Act.
            IActionResult result = controller.Post(input);
            ObjectResult  noData = result as ObjectResult;
            ErrorModelOut error  = noData.Value as ErrorModelOut;

            //Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(noData);
            Assert.AreEqual(500, noData.StatusCode);
            Assert.IsNotNull(error);
            Assert.AreEqual(toThrow.Message, error.ErrorMessage);
        }
        public void GetLogsNoDataAccessTest()
        {
            //Arrange.
            Exception internalEx = new DataInaccessibleException();
            Exception toThrow    = new ServiceException(internalEx.Message, ErrorType.DATA_INACCESSIBLE);

            Mock.Get(logger).Setup(l => l.GetAllLogs()).Throws(toThrow);

            //Act.
            IActionResult result = controller.GetAll(new DateTime(), new DateTime());
            ObjectResult  noData = result as ObjectResult;
            ErrorModelOut error  = noData.Value as ErrorModelOut;

            //Assert.
            Mock.Get(logger).Verify(s => s.GetAllLogs(), Times.Once);
            Assert.IsNotNull(result);
            Assert.IsNotNull(noData);
            Assert.AreEqual(500, noData.StatusCode);
            Assert.IsNotNull(error);
            Assert.AreEqual(toThrow.Message, error.ErrorMessage);
        }
Example #8
0
        public void CreateUserNoDataAccessTest()
        {
            //Arrange.
            Exception internalEx = new DataInaccessibleException();
            Exception toThrow    = new ServiceException(internalEx.Message, ErrorType.DATA_INACCESSIBLE);

            service.Setup(us => us.AddUser(It.IsAny <UserDto>())).Throws(toThrow);


            //Act.
            IActionResult result = controller.Post(input);
            ObjectResult  noData = result as ObjectResult;
            ErrorModelOut error  = noData.Value as ErrorModelOut;

            //Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(noData);
            Assert.AreEqual(500, noData.StatusCode);
            Assert.IsNotNull(error);
            Assert.AreEqual(toThrow.Message, error.ErrorMessage);
        }
Example #9
0
        public void LoginNoDataAccessTest()
        {
            //Arrange.
            Exception internalEx = new DataInaccessibleException();
            Exception toThrow    = new ServiceException(internalEx.Message, ErrorType.DATA_INACCESSIBLE);

            loginService.Setup(us => us.Login(It.IsAny <string>(), It.IsAny <string>())).Throws(toThrow);
            LoginModelIn credentials = new LoginModelIn()
            {
                Username = "******", Password = "******"
            };

            //Act.
            IActionResult result = controllerToTest.Authenticate(credentials);
            ObjectResult  noData = result as ObjectResult;
            ErrorModelOut error  = noData.Value as ErrorModelOut;

            //Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(noData);
            Assert.AreEqual(500, noData.StatusCode);
            Assert.IsNotNull(error);
            Assert.AreEqual(toThrow.Message, error.ErrorMessage);
        }
Example #10
0
        public void CreateSportNoDataAccessTest()
        {
            //Arrange.
            Exception internalEx = new DataInaccessibleException();
            Exception toThrow    = new ServiceException(internalEx.Message, ErrorType.DATA_INACCESSIBLE);

            sportsService.Setup(r => r.AddSport(It.IsAny <SportDto>())).Throws(toThrow);
            SportModelIn input = new SportModelIn()
            {
                Name = "Soccer"
            };

            //Act.
            IActionResult result = controllerToTest.Post(input);
            ObjectResult  noData = result as ObjectResult;
            ErrorModelOut error  = noData.Value as ErrorModelOut;

            //Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(noData);
            Assert.AreEqual(500, noData.StatusCode);
            Assert.IsNotNull(error);
            Assert.AreEqual(toThrow.Message, error.ErrorMessage);
        }