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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }