public void Service_ExpenseReportQuery_GetById_ReturnsNullWhenNotFound() { // Arrange int id = 3; IMap<ExpenseReport> map = new Map<ExpenseReport>(); List<ExpenseReport> reports = new List<ExpenseReport>() { new ExpenseReport { Id = 1, Title = "Report One" }, new ExpenseReport { Id = 2, Title = "Report Two" } }; Mock<ExpenseContext> mockContext = new ExpenseContextBuilder() .WithSet<ExpenseReport>(x => x.ExpenseReports, reports.AsQueryable()) .Build(); // Act ExpenseReportQueryService service = new ExpenseReportQueryService(mockContext.Object, map); var result = service.GetExpenseReportById(id); // Assert Assert.IsNull(result); }
public ExpenseReportEntryService(ExpenseContext context, ExpenseReportValidationService validationService, ExpenseReportQueryService queryService) { _data = context; _validationService = validationService; _queryService = queryService; }
public void Service_Map_ExpenseReport_ExpenseReportModel_CalculateTotal() { // Arrange int id = 1; IMap<ExpenseReport> map = new Map<ExpenseReport>(); List<ExpenseReport> reports = new List<ExpenseReport>() { new ExpenseReport { Id = 1, Title = "Report One", ExpenseItems = new List<ExpenseItem>() { new ExpenseItem { Id = 1, ExpenseAmount = 12.34m }, new ExpenseItem { Id = 1, ExpenseAmount = 12.34m } } } }; decimal sum = reports.First().ExpenseItems.Sum(x => x.ExpenseAmount); Mock<ExpenseContext> mockContext = new ExpenseContextBuilder() .WithSet<ExpenseReport>(x => x.ExpenseReports, reports.AsQueryable()) .Build(); // Act ExpenseReportQueryService service = new ExpenseReportQueryService(mockContext.Object, map); var result = service.GetExpenseReportById(id); // Assert Assert.AreEqual(sum, result.ExpenseTotal); }