private ToDoService GetToDoService(MsSqlLiteDatabaseContext context, List <ToDoDbModel> toDos) { context.Database.OpenConnection(); context.Database.EnsureCreated(); context.ToDos.AddRange(toDos); context.SaveChanges(); var toDoRepository = new ToDoRepository(context, kernel.Get <IToDoEntityConverter>()); return(new ToDoService(toDoRepository)); }
public async Task GetToDosFromContext() { using MsSqlLiteDatabaseContext context = new MsSqlLiteDatabaseContext(optionsSnapShotMock.Object); var toDoService = GetToDoService(context, toDosForContextLoading); var toDo = await toDoService.GetToDoItemByIdAsync(id : 2); Assert.IsNotNull(toDo); Assert.AreEqual(2, toDo.Id); Assert.AreEqual("Second Task", toDo.Description); Assert.IsFalse(toDo.IsCompleted); context.Database.CloseConnection(); }
public async Task GetAllPagingTest() { using MsSqlLiteDatabaseContext context = new MsSqlLiteDatabaseContext(optionsSnapShotMock.Object); var toDoService = GetToDoService(context, toDosForPaging); var paging = new PagingDto { PageNumber = 2, PageSize = 5 }; int expectedToDosCount = 2; int actualToDosCount = (await toDoService.GetAllAsync(null, paging)).Count(); Assert.AreEqual(expectedToDosCount, actualToDosCount); context.Database.CloseConnection(); }
public async Task GetAllFilteringTest(int rowNumber, int expectedCount, int pageNumber, FilterDto filter) { using MsSqlLiteDatabaseContext context = new MsSqlLiteDatabaseContext(optionsSnapShotMock.Object); var toDoService = GetToDoService(context, toDosForFiltering); var paging = new PagingDto { PageNumber = pageNumber, PageSize = 5 }; int actualCount = (await toDoService.GetAllAsync(filter, paging)).Count(); Assert.AreEqual(expectedCount, actualCount); Debug.WriteLine($"TestCase row {rowNumber} completed."); context.Database.CloseConnection(); }
public ToDoRepository(MsSqlLiteDatabaseContext dbContext, IToDoEntityConverter toDoEntityConverter) { this.dbContext = dbContext; this.toDoEntityConverter = toDoEntityConverter; }
public TimeReportRepository(MsSqlLiteDatabaseContext dbContext, ITimeReportEntityConverter timeReportEntityConverter) { this.dbContext = dbContext; this.timeReportEntityConverter = timeReportEntityConverter; }