Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void Get_All_Bills_Should_Return_Bills()
        {
            BillsController    billsCtrl = new BillsController(_contextFixture.DbContext);
            IEnumerable <Bill> bills     = billsCtrl.GetBills();

            bills.Should().NotBeNull();
        }
Exemplo n.º 4
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>();
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
        public void GetAllBillsReturnsEverythingInRepository()
        {
            var allBills = new[]
            {
                new Bill()
                {
                    Amount   = 1000,
                    BillId   = 1,
                    Supplier = new Supplier()
                    {
                        Name       = "ANTEL",
                        Commission = 2,
                        SupplierId = 1
                    },
                },
                new Bill()
                {
                    Amount   = 1000,
                    BillId   = 1,
                    Supplier = new Supplier()
                    {
                        Name       = "ANTEL",
                        Commission = 2,
                        SupplierId = 2
                    },
                }
            };

            var mockBillService = new Mock <IBillService>();

            mockBillService.Setup(x => x.GetAllBills()).Returns(allBills);

            var controller = new BillsController(mockBillService.Object);

            IHttpActionResult actionResult = controller.GetBills();

            OkNegotiatedContentResult <IEnumerable <Bill> > contentResult = Assert.IsType <OkNegotiatedContentResult <IEnumerable <Bill> > >(actionResult);

            Assert.NotNull(contentResult);
            Assert.NotNull(contentResult.Content);
            Assert.Same(allBills, contentResult.Content);
        }
Exemplo n.º 7
0
        public void TestBills()
        {
            var listOfBills = new CoreBills();

            listOfBills = new CoreBills
            {
                Id           = 1,
                UserId       = 2,
                PurchaseName = "Mock",
                Quantity     = 2,
                Cost         = 3,
                BillDate     = new DateTime(),
                Location     = "Mock Location",
            };
            var bills = new Bills
            {
                Id           = 1,
                UserId       = 2,
                PurchaseName = "Mock",
                Quantity     = 2,
                Cost         = 3,
                BillDate     = new DateTime(),
                Location     = "Mock Location",
            };
            var a = Mapper.MapBills(listOfBills);
            Mock <IBillsRepository> mockBillRepository = new Mock <IBillsRepository>();

            mockBillRepository.Setup(x => x.GetBillsAsync(null)).Verifiable();
            var billController = new BillsController(mockBillRepository.Object);
            var bill           = billController.GetBills();
            var bill2          = billController.GetUserBills(1);
            var bill3          = billController.PostBills(bills);
            var bill4          = billController.PutBills(1, bills);
            var bill5          = billController.DeleteBills(1);

            billController.Should().NotBeNull();
        }