コード例 #1
0
        public void EditQuota()
        {
            //Arrange
            int    userId = 1;
            int    qId    = 2;
            string login  = "******";
            var    mock   = new Mock <IDataBaseManager>();

            mock.Setup(o => o.GetAllQuotas(userId)).Returns(GetViewQuotas(userId));
            mock.Setup(o => o.GetAllCities()).Returns(GetTestCities());
            mock.Setup(o => o.GetUser(login)).Returns(GetTestUser(login));
            mock.Setup(o => o.GetQuota(qId)).Returns(GetTestQuota(qId));
            var controller  = new RefinanceApiController(mock.Object);
            var editedQuota = GetQuotas(userId).Single(o => o.Id == qId);

            editedQuota.Amount  = 450000M;
            editedQuota.Comment = "editedcomment";

            //Act
            var result = controller.Put(editedQuota);

            //Assert
            mock.Verify(r => r.EditQuota(editedQuota));
            Assert.IsType <OkObjectResult>(result);
        }
コード例 #2
0
        public void GetReportReturnsBadRequestResultWhenIdNull()
        {
            //Arrange
            var mock = new Mock <IDataBaseManager>();

            var controller = new RefinanceApiController(mock.Object);

            //Act
            var result = controller.GetReport(null);

            //Assert
            Assert.IsType <BadRequestResult>(result);
        }
コード例 #3
0
        public void GetQuotaReturnsNotFoundResultWhenQuotaNotFound()
        {
            //Arrange
            int testId = 1;
            var mock   = new Mock <IDataBaseManager>();

            mock.Setup(repo => repo.GetQuota(testId))
            .Returns(null as Quota);
            var controller = new RefinanceApiController(mock.Object);

            //Act
            var result = controller.GetQuota(testId);

            //Assert
            Assert.IsType <NotFoundResult>(result);
        }
コード例 #4
0
        public void DeleteNotFoundQuota()
        {
            //Arrange
            int    userId = 1;
            string login  = "******";
            var    mock   = new Mock <IDataBaseManager>();

            mock.Setup(o => o.GetAllQuotas(userId)).Returns(GetViewQuotas(userId));
            mock.Setup(o => o.GetAllCities()).Returns(GetTestCities());
            mock.Setup(o => o.GetUser(login)).Returns(GetTestUser(login));
            var controller = new RefinanceApiController(mock.Object);

            //Act
            var result = controller.Delete(100);

            //Assert
            Assert.IsType <NotFoundResult>(result);
        }
コード例 #5
0
        public void GetReportReturnsFileResult()
        {
            //Arrange
            int testId = 1;
            var testQ  = GetQuotas(1).Single(o => o.Id == testId);
            var mock   = new Mock <IDataBaseManager>();

            mock.Setup(repo => repo.GetQuota(testId))
            .Returns(testQ);
            var controller = new RefinanceApiController(mock.Object);

            //Act
            var result = controller.GetReport(testId);

            //Assert
            var fileResult = Assert.IsType <FileContentResult>(result);

            Assert.Equal("text/html", fileResult?.ContentType);
            Assert.Equal("report.html", fileResult?.FileDownloadName);
        }
コード例 #6
0
        public void DeleteQuota()
        {
            //Arrange
            int    userId = 1;
            int    qId    = 2;
            string login  = "******";
            var    mock   = new Mock <IDataBaseManager>();

            mock.Setup(o => o.GetAllQuotas(userId)).Returns(GetViewQuotas(userId));
            mock.Setup(o => o.GetAllCities()).Returns(GetTestCities());
            mock.Setup(o => o.GetUser(login)).Returns(GetTestUser(login));
            mock.Setup(o => o.GetQuota(qId)).Returns(GetTestQuota(qId));
            var controller = new RefinanceApiController(mock.Object);

            //Act
            var result = controller.Delete(qId);

            //Assert
            mock.Verify(r => r.DeleteQuota(qId));
            Assert.IsType <OkObjectResult>(result);
        }
コード例 #7
0
        public void GetList()
        {
            //Arrange
            int    userId = 1;
            string login  = "******";
            var    mock   = new Mock <IDataBaseManager>();

            mock.Setup(o => o.GetAllQuotas(userId)).Returns(GetViewQuotas(userId));
            mock.Setup(o => o.GetAllCities()).Returns(GetTestCities());
            mock.Setup(o => o.GetUser(login)).Returns(GetTestUser(login));
            var controller = new RefinanceApiController(mock.Object);

            //Act
            var result = controller.Get(1);

            //Assert
            var     jsonResult = Assert.IsType <JsonResult>(result);
            dynamic jsonObject = JObject.Parse(jsonResult.Value);
            int     page       = (int)jsonObject.pageViewModel.pageNumber;

            Assert.Equal(1, page);
        }
コード例 #8
0
        public void AddQuota()
        {
            //Arrange
            int    userId = 1;
            string login  = "******";
            var    mock   = new Mock <IDataBaseManager>();

            mock.Setup(o => o.GetAllQuotas(userId)).Returns(GetViewQuotas(userId));
            mock.Setup(o => o.GetAllCities()).Returns(GetTestCities());
            mock.Setup(o => o.GetUser(login)).Returns(GetTestUser(login));
            var controller = new RefinanceApiController(mock.Object);
            var newQuota   = new Quota()
            {
                CityId = 1, Purpose = DAL.Enums.Purpose.Mortgage, Amount = 2500000M, CreateDate = DateTime.Now, Comment = "Ипотека", UserId = 1
            };

            //Act
            var result = controller.Post(newQuota);

            //Assert
            mock.Verify(r => r.AddQuota(newQuota));
            Assert.IsType <OkObjectResult>(result);
        }