コード例 #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);
        }