public async Task GetAsync__Id_is_null_or_empty__Should_throw_ArgumentException([Values(null, "")] string id) { var service = new ActivityLogDbService(_dbContextMock.Object, _logger); Func <Task> action = async() => await service.GetAsync(id); await action.Should().ThrowExactlyAsync <ArgumentException>("Because id cannot be null or empty string."); }
public async Task GetAsync__Found_zero_matching_activity_log__Should_throw_InvalidOperationException() { using (var factory = new DbContextFactory()) { using (var context = await factory.CreateContextAsync()) { var service = new ActivityLogDbService(context, _logger); Func <Task> action = async() => await service.GetAsync("-1"); await action.Should().ThrowExactlyAsync <InvalidOperationException>("Because ActivityLog not found."); } } }
public async Task GetAsync__Resource_is_null__Should_throw_InternalDbServiceException() { using (var factory = new DbContextFactory()) { using (var context = await factory.CreateContextAsync()) { context.ActivityLogs = null as DbSet <ActivityLog>; var service = new ActivityLogDbService(context, _logger); Func <Task> action = async() => await service.GetAsync("1"); await action.Should().ThrowExactlyAsync <InternalDbServiceException>("Because resource reference is set to null"); } } }
public async Task GetAsync__Resource_is_empty__Should_throw_InvalidOperationException() { using (var factory = new DbContextFactory()) { using (var context = await factory.CreateContextAsync()) { context.ActivityLogs.RemoveRange(await context.ActivityLogs.ToListAsync()); await context.SaveChangesAsync(); } using (var context = await factory.CreateContextAsync()) { var service = new ActivityLogDbService(context, _logger); Func <Task> action = async() => await service.GetAsync("1"); await action.Should().ThrowExactlyAsync <InvalidOperationException>("Because resource is empty and cannot get single instance of ActivityLog."); } } }
public async Task GetAsync__Resource_doesnt_exist__Should_throw_InternalDbServiceException() { using (var factory = new DbContextFactory()) { using (var context = await factory.CreateContextAsync()) { // Drop ActivityLogs table. context.Database.ExecuteSqlCommand("DROP TABLE [ActivityLogs]"); } using (var context = await factory.CreateContextAsync()) { var service = new ActivityLogDbService(context, _logger); Func <Task> action = async() => await service.GetAsync("1"); await action.Should().ThrowExactlyAsync <InternalDbServiceException>("Because resource doesnt exist and cannot get single instance of ActivityLog. " + "NOTE Excaption actually is type of 'SqLiteError' only if database provider is SQLite."); } } }
public async Task GetAsync__Activity_log_found__Should_return_this_ActivityLog() { ActivityLog expectedActivityLog; using (var factory = new DbContextFactory()) { using (var context = await factory.CreateContextAsync()) { expectedActivityLog = await context.ActivityLogs.FirstOrDefaultAsync(); } using (var context = await factory.CreateContextAsync()) { var service = new ActivityLogDbService(context, _logger); var result = await service.GetAsync(expectedActivityLog.Id); result.Should().BeEquivalentTo(expectedActivityLog); } } }