示例#1
0
        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());
        }
示例#2
0
 public Bills()
 {
     InitializeComponent();
     c = (BillsController)DataContext;
     c.Model.PropertyChanged += Model_AddBill;
     c.Model.PropertyChanged += Model_DeleteBill;
 }
示例#3
0
        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>();
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#7
0
        public void Get_All_Bills_Should_Return_Bills()
        {
            BillsController    billsCtrl = new BillsController(_contextFixture.DbContext);
            IEnumerable <Bill> bills     = billsCtrl.GetBills();

            bills.Should().NotBeNull();
        }
示例#8
0
        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();
        }
示例#10
0
        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>();
        }
示例#11
0
        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();
        }
示例#12
0
        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>();
        }
示例#13
0
        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");
        }
示例#15
0
        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));
        }
示例#16
0
        public void PayBillActionWithIdReturnsJsonResult()
        {
            //arrange
            controller = new BillsController(mockBillService.Object, null, null);
            //act
            var result = controller.PayBill(1);

            //assert
            Assert.IsInstanceOfType(result, typeof(JsonResult));
        }
示例#17
0
        public void DetailsWithoutIdReturnsNotFound()
        {
            //arrange
            controller = new BillsController(null, null, null);
            //act
            var result = controller.Details(null);

            //assert
            Assert.IsInstanceOfType(result, typeof(HttpStatusCodeResult));
        }
示例#18
0
        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);
        }
示例#19
0
        public void CreateRecipientsListReturnsRecipientList()
        {
            //arrange
            controller = new BillsController(null, null, mockRecipientService.Object);
            //act
            var result = controller.CreateRecipientsList();

            //assert
            Assert.AreEqual(result[0].CompanyName, "Tauron");
        }
示例#20
0
        public void CreateTypesListReturnsBillTypeVmList()
        {
            //arrange
            controller = new BillsController(mockBillService.Object, null, null);
            //act
            var result = controller.CreateTypesList();

            //assert
            Assert.AreEqual(result[0].Name, "Prąd");
        }
示例#21
0
        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));
        }
示例#22
0
        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();
        }
示例#24
0
        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);
        }
示例#25
0
        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);
        }
示例#27
0
        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);
        }
示例#28
0
        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
        }
示例#29
0
        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));
        }
示例#30
0
        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");
        }