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); }
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); }
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); }
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); }
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); }