Esempio n. 1
0
        public async Task AddAsync__Argument_is_null__Should_throw_ArgumentNullException()
        {
            var service = new ActivityLogDbService(_dbContextMock.Object, _logger);

            Func <Task> result = async() => await service.AddAsync(null as ActivityLog);

            await result.Should().ThrowExactlyAsync <ArgumentNullException>("Because argument 'ActivityLog' is null.");
        }
Esempio n. 2
0
        public async Task AddAsync__Add_successful__Resource_contains_added_ActivityLog()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    var service = new ActivityLogDbService(context, _logger);

                    await service.AddAsync(_validActivityLog);

                    context.ActivityLogs.Contains(_validActivityLog).Should().BeTrue();
                }
            }
        }
Esempio n. 3
0
        public async Task AddAsync__Add_successful__Should_return_added_ActivityLog()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    var service = new ActivityLogDbService(context, _logger);

                    var result = await service.AddAsync(_validActivityLog);

                    result.Should().BeEquivalentTo(_validActivityLog);
                }
            }
        }
Esempio n. 4
0
        public async Task AddAsync__Add_successful__Resource_length_should_be_greater_by_1()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    int expectedLength = context.ActivityLogs.Count() + 1;
                    var service        = new ActivityLogDbService(context, _logger);

                    await service.AddAsync(_validActivityLog);

                    context.ActivityLogs.Count().Should().Be(expectedLength);
                }
            }
        }
Esempio n. 5
0
        public async Task AddAsync__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.AddAsync(_validActivityLog);

                    await action.Should().ThrowExactlyAsync <InternalDbServiceException>("Because resource reference is set to null");
                }
            }
        }
Esempio n. 6
0
        public async Task AddAsync__In_resource_exists_the_same_activity_log_as_this_one_to_be_added__Should_throw_InvalidOperationException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    context.ActivityLogs.Add(_validActivityLog);
                    await context.SaveChangesAsync();
                }

                using (var context = await factory.CreateContextAsync())
                {
                    var service = new ActivityLogDbService(context, _logger);

                    Func <Task> result = async() => await service.AddAsync(_validActivityLog);

                    await result.Should().ThrowExactlyAsync <InvalidOperationException>("Because in resource exists the same ActivityLog as this one to be added.");
                }
            }
        }
Esempio n. 7
0
        public async Task AddAsync__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.AddAsync(_validActivityLog);

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