public async void PayBillBillIsNull_BadRequest() { // Arrange Bill bill = new Bill { Id = 3 }; Mock <BillRepository> mockBillRepository = new Mock <BillRepository>(); mockBillRepository .Setup(br => br.GetAsync(It.IsAny <int>(), It.IsAny <string>())) .Returns(Task.FromResult(null as Bill)); Mock <IUnitOfWork> mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork .Setup(u => u.GetRepository <Bill, BillRepository>()) .Returns(mockBillRepository.Object); BillsController controller = new BillsController(mockUnitOfWork.Object); // Act IActionResult result = await controller.PayBill(bill.Id); // Assert Assert.NotNull(result); BadRequestObjectResult badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result); Assert.Equal("There is no such bill", badRequestObjectResult.Value.ToString()); }
public Bills() { InitializeComponent(); c = (BillsController)DataContext; c.Model.PropertyChanged += Model_AddBill; c.Model.PropertyChanged += Model_DeleteBill; }
public void Get_With_Invalid_Id_Should_Return_Exception() { BillsController billsCtrl = new BillsController(_contextFixture.DbContext); Action result = () => billsCtrl.GetBill("32423-234324"); result.Should().ThrowExactly <ArgumentException>(); }
public async Task Get_shouldTakeEmptyBillList() { List <Bill> bills = new List <Bill>() { new Bill { DueDate = DateTime.Now.AddDays(3), PersonId = "51417973099", Value = 20 }, new Bill { DueDate = DateTime.Now.AddDays(3), PersonId = "50947938028", Value = 22 } }; Moq.Mock <IBillService> mockBillService = new Moq.Mock <IBillService>(); mockBillService.Setup( billService => billService .GetAsync(It.IsAny <string>(), It.IsAny <int?>())) .Returns(() => GetBillListAsyncly(bills)); var billsController = new BillsController(mockBillService.Object); var response = billsController.GetBills(null, null); int count = 0; await foreach (Bill b in response) { count++; } Assert.IsAssignableFrom <IAsyncEnumerable <Bill> >(response); Assert.Equal(0, count); }
public async Task Get_shouldTakeBillsByPersonId() { List <Bill> expectedBills = new List <Bill>() { new Bill { DueDate = DateTime.Now.AddDays(3), PersonId = "51417973099", Value = 20 } }; List <Bill> actualBills = new List <Bill>(); Moq.Mock <IBillService> mockBillService = new Moq.Mock <IBillService>(); mockBillService.Setup( billService => billService .GetAsync(It.IsAny <string>(), It.IsAny <int?>())) .Returns(() => GetBillListAsyncly(expectedBills)); var billsController = new BillsController(mockBillService.Object); await foreach (Bill b in billsController.GetBills(cpf: "51417973099")) { actualBills.Add(b); } Assert.Equal(expectedBills, actualBills); }
public async void UpdateBill_OkResult() { // Arrange Bill bill = new Bill { Id = 1, Renter = new User { Id = 1 } }; Mock <GenericRepository <Bill> > mockBillRepository = new Mock <GenericRepository <Bill> >(); mockBillRepository .Setup(br => br.GetAsync(It.IsAny <int>(), It.IsAny <string>())) .Returns(System.Threading.Tasks.Task.FromResult(bill)); Mock <GenericRepository <Notification> > mockNotificationRepository = new Mock <GenericRepository <Notification> >(); Mock <IUnitOfWork> mockIUnitOfWork = new Mock <IUnitOfWork>(); mockIUnitOfWork .Setup(u => u.GetRepository <Bill, GenericRepository <Bill> >()) .Returns(mockBillRepository.Object); mockIUnitOfWork .Setup(u => u.GetRepository <Notification, GenericRepository <Notification> >()) .Returns(mockNotificationRepository.Object); BillsController controller = new BillsController(mockIUnitOfWork.Object); // Act IActionResult result = await controller.UpdateBill(bill.Id, DataAccess.Enums.PaymentStatus.Paid, new DateTime()); // Assert Assert.NotNull(result); Assert.IsType <OkResult>(result); }
public void Get_All_Bills_Should_Return_Bills() { BillsController billsCtrl = new BillsController(_contextFixture.DbContext); IEnumerable <Bill> bills = billsCtrl.GetBills(); bills.Should().NotBeNull(); }
public async void PayBill_OkResult() { // Arrange Bill bill = new Bill { Id = 3, Apartment = new Apartment() }; Mock <BillRepository> mockBillRepository = new Mock <BillRepository>(); mockBillRepository .Setup(br => br.GetAsync(It.IsAny <int>(), It.IsAny <string>())) .Returns(Task.FromResult(bill)); Mock <IUnitOfWork> mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork .Setup(u => u.GetRepository <Bill, BillRepository>()) .Returns(mockBillRepository.Object); BillsController controller = new BillsController(mockUnitOfWork.Object); // Act IActionResult result = await controller.PayBill(bill.Id); // Assert Assert.NotNull(result); Assert.IsType <OkResult>(result); }
public BillsView(BillsController controller) : this() { _controller = controller; _controller.ListChanged += ListChanged; ListChanged(); }
public void Get_With_Saved_Id_Should_Return_OkResult() { BillsController billsCtrl = new BillsController(_contextFixture.DbContext); var firstBill = billsCtrl.GetBills().First(); var okObjectResult = billsCtrl.GetBill(firstBill.Id.ToString()) as OkObjectResult; okObjectResult.Should().BeOfType <OkObjectResult>(); }
public void Get_With_Given_Id_Should_Return_Bill() { BillsController billsCtrl = new BillsController(_contextFixture.DbContext); var firstBill = billsCtrl.GetBills().First(); var okObjectResult = billsCtrl.GetBill(firstBill.Id.ToString()) as OkObjectResult; okObjectResult.Value.Should().NotBeNull(); }
public void Get_With_Random_Id_Should_Return_NotFoundResult() { BillsController billsCtrl = new BillsController(_contextFixture.DbContext); string randomGuid = Guid.NewGuid().ToString(); var result = billsCtrl.GetBill(randomGuid); result.Should().BeOfType <NotFoundResult>(); }
public BillAddView(BillsController controller, BillDto entity) : this() { Entity = entity; _controller = controller; MainStackPanel.DataContext = Entity; }
public async Task Index_should_return_default_view() { var controller = new BillsController(_applicationDbContext); var viewResult = await controller.Index(); var viewName = ((ViewResult)viewResult).ViewName; Assert.True(string.IsNullOrEmpty(viewName) || viewName == "Index"); }
public void CreatePostActionWithValidModelCreatesBillAndRedirectToIndex() { //arrange controller = new BillsController(mockBillService.Object, mockBillFactory.Object, mockRecipientService.Object); //act var result = controller.Create(new CreateBillVM()); //assert Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); }
public void PayBillActionWithIdReturnsJsonResult() { //arrange controller = new BillsController(mockBillService.Object, null, null); //act var result = controller.PayBill(1); //assert Assert.IsInstanceOfType(result, typeof(JsonResult)); }
public void DetailsWithoutIdReturnsNotFound() { //arrange controller = new BillsController(null, null, null); //act var result = controller.Details(null); //assert Assert.IsInstanceOfType(result, typeof(HttpStatusCodeResult)); }
public void IndexReturnsBillsListToView() { //arrange controller = new BillsController(mockBillService.Object, null, null); //act var result = ((controller.Index() as ViewResult).Model) as List <CreateBillVM>; //assert Assert.AreEqual(result.Count, 3); }
public void CreateRecipientsListReturnsRecipientList() { //arrange controller = new BillsController(null, null, mockRecipientService.Object); //act var result = controller.CreateRecipientsList(); //assert Assert.AreEqual(result[0].CompanyName, "Tauron"); }
public void CreateTypesListReturnsBillTypeVmList() { //arrange controller = new BillsController(mockBillService.Object, null, null); //act var result = controller.CreateTypesList(); //assert Assert.AreEqual(result[0].Name, "Prąd"); }
public void DetailsActionReturnsViewWithBillVM() { //arrange controller = new BillsController(mockBillService.Object, null, null); //act var result = controller.Details(1) as ViewResult; //assert Assert.IsInstanceOfType(result.Model, typeof(CreateBillVM)); }
public void EditGetActionWithIdReturnsEditViewWithProperVM() { //arrange controller = new BillsController(mockBillService.Object, mockBillFactory.Object, mockRecipientService.Object); //act var result = controller.Edit(1) as ViewResult; //assert mockBillService.Verify(m => m.GetBill(It.IsAny <int>()), Times.Once); Assert.IsInstanceOfType(result.Model, typeof(CreateBillVM)); }
public void GetBudgets() { var listOfBills = new CoreBudgets(); var a = Mapper.MapBudgets(listOfBills); Mock <IBillsRepository> mockBillRepository = new Mock <IBillsRepository>(); mockBillRepository.Setup(x => x.GetBillsAsync(null)).Verifiable(); var billController = new BillsController(mockBillRepository.Object); billController.Should().NotBeNull(); }
public void EditGetActionWithoutIdDoesntInvokeService() { //arrange controller = new BillsController(mockBillService.Object, mockBillFactory.Object, mockRecipientService.Object); //act int?nullValue = null; var result = controller.Edit(nullValue); //assert mockBillService.Verify(m => m.GetBill(It.IsAny <int>()), Times.Never); }
public void DeleteGetActionWithIdReturnsDeleteViewWithModel() { //arrange controller = new BillsController(mockBillService.Object, null, null); //act var result = controller.Delete(1) as ViewResult; //assert mockBillService.Verify(m => m.GetBill(It.IsAny <int>()), Times.Once); Assert.IsInstanceOfType(result.Model, typeof(CreateBillVM)); }
private void OpenBills() { //TOOD: Move to controller var controller = new BillsController(_ctx); controller.BillLoaded += BillLoaded; controller.RemoveDialogRequested += ShowRemoveDialog; FrameOpt.Content = new BillsView(controller); }
public void CreateGetActionReturnsViewWithBillVM() { //arrange controller = new BillsController(mockBillService.Object, null, mockRecipientService.Object); //act var result = controller.Create() as ViewResult; //assert Assert.IsInstanceOfType(result.Model, typeof(CreateBillVM)); Assert.IsNotNull(result); }
public void CreatePostActionWithInvalidModelReturnsCreateView() { //arrange controller = new BillsController(mockBillService.Object, mockBillFactory.Object, mockRecipientService.Object); controller.ModelState.AddModelError("test", "test"); //act var result = controller.Create(new CreateBillVM()) as ViewResult; //assert mockBillService.Verify(m => m.CreateBill(It.IsAny <IBill>()), Times.Never); Assert.IsInstanceOfType(result.Model, typeof(CreateBillVM)); //returns model to correct errors }
public void DeleteGetActionWithoutIdReturns404() { //arrange controller = new BillsController(mockBillService.Object, null, null); int?nullvalue = null; //act var result = controller.Delete(nullvalue); //assert mockBillService.Verify(m => m.GetBill(It.IsAny <int>()), Times.Never); Assert.IsInstanceOfType(result, typeof(HttpStatusCodeResult)); }
public void EditPostActionWithValidModelUpdatesBillAndRedirectsToIndexView() { //arrange controller = new BillsController(mockBillService.Object, mockBillFactory.Object, null); //act var result = controller.Edit(new CreateBillVM()) as RedirectToRouteResult; //assert mockBillService.Verify(m => m.UpdateBill(It.IsAny <IBill>()), Times.Once); Assert.AreEqual(result.RouteValues["action"], "Index"); }