Пример #1
0
        public void ReturnDifferentBills_WhenIdUserIsNotValid()
        {
            // Arrange
            var contextMock        = this.ContextMock;
            var companyServiceMock = this.CompanyServiceMocked;

            var idUser = "******";
            var bills  = this.Bills;

            var billSetMock = QueryableDbSetMock.GetQueryableMockDbSet(bills);

            var expectedResult = bills.Where(b => b.IdUser == "idUser03");


            contextMock.Setup(c => c.Bills).Returns(billSetMock.Object);

            Bills.Services.BillService billService = new Bills.Services.BillService(contextMock.Object, companyServiceMock.Object);

            // Act
            var result = billService.GetBillsByIdUser(idUser);

            // Assert
            contextMock.Verify(b => b.Bills, Times.Once);
            CollectionAssert.IsNotEmpty(expectedResult);
            CollectionAssert.IsEmpty(result);
            CollectionAssert.AreNotEquivalent(expectedResult, result);
        }
Пример #2
0
        public void RemoveSpecificBill_WhenBillExist()
        {
            // Arrange
            var contextMock        = this.ContextMock;
            var companyServiceMock = this.CompanyServiceMocked;

            var expectedId = 2;
            var bills      = this.Bills;

            var billSetMock = QueryableDbSetMock.GetQueryableMockDbSetFromArray(bills);

            contextMock.Setup(c => c.Bills).Returns(billSetMock.Object);

            billSetMock.Setup(b => b.Remove(It.IsAny <Bill>())).Callback <Bill>((entity) => bills.Remove(entity));
            //contextMock.Setup(c => c.Bills.Remove(It.IsAny<Bill>())).Callback<Bill>((entity) => bills.Remove(entity));

            Bills.Services.BillService billService = new Bills.Services.BillService(contextMock.Object, companyServiceMock.Object);

            Bill bill = billSetMock.Object.First();

            // Act
            billService.RemoveBill(bill);

            // Assert
            Assert.AreEqual(billSetMock.Object.First().Id, expectedId);
        }
Пример #3
0
        public void ReturnAllBills()
        {
            // Arrange
            var contextMock        = this.ContextMock;
            var companyServiceMock = this.CompanyServiceMocked;

            var bills = this.Bills;

            var billSetMock = QueryableDbSetMock.GetQueryableMockDbSet(bills);

            contextMock.Setup(b => b.Bills).Returns(billSetMock.Object);

            Bills.Services.BillService billService = new Bills.Services.BillService(contextMock.Object, companyServiceMock.Object);

            // Act
            var result = billService.GetAllBills();

            // Assert
            contextMock.Verify(b => b.Bills, Times.Once);
            CollectionAssert.AreEquivalent(result, bills);
        }
Пример #4
0
        public void ReturnEmpty_WhenIdUserIsNotValid()
        {
            // Arrange
            var contextMock        = this.ContextMock;
            var companyServiceMock = this.CompanyServiceMocked;

            var idUser = "******";
            var bills  = this.Bills;

            var billSetMock = QueryableDbSetMock.GetQueryableMockDbSet(bills);

            contextMock.Setup(c => c.Bills).Returns(billSetMock.Object);

            Bills.Services.BillService billService = new Bills.Services.BillService(contextMock.Object, companyServiceMock.Object);

            // Act
            var result = billService.GetBillsByIdUser(idUser);

            // Assert
            contextMock.Verify(b => b.Bills, Times.Once);
            Assert.IsEmpty(result);
        }
Пример #5
0
        public void ReturnSpecificBill_WhenIdIsValid()
        {
            // Arrange
            var contextMock        = this.ContextMock;
            var companyServiceMock = this.CompanyServiceMocked;

            var expectedId = 2;
            var bills      = this.Bills;

            var billSetMock = QueryableDbSetMock.GetQueryableMockDbSet(bills);

            contextMock.Setup(c => c.Bills).Returns(billSetMock.Object);

            Bills.Services.BillService billService = new Bills.Services.BillService(contextMock.Object, companyServiceMock.Object);

            contextMock.Setup(b => b.Bills.Find(It.IsAny <object[]>())).Returns <object[]>(ids => billSetMock.Object.Where(d => d.Id == (int)ids[0]).First());

            // Act
            var result = billService.FindBillById(expectedId);

            Assert.AreEqual(expectedId, result.Id);
            contextMock.Verify(b => b.Bills.Find(expectedId), Times.Once);
        }