Beispiel #1
0
        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.");
        }
Beispiel #2
0
        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.");
                }
            }
        }
Beispiel #3
0
        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");
                }
            }
        }
Beispiel #4
0
        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.");
                }
            }
        }
Beispiel #5
0
        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.");
                }
            }
        }
Beispiel #6
0
        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);
                }
            }
        }