Example #1
0
        public async Task GetAsync__Id_is_null_or_empty__Should_throw_ArgumentException([Values(null, "")] string id)
        {
            var service = new TicketDbService(_dbContextMock.Object, _logger);

            Func <Task> action = async() => await service.GetAsync(id);

            await action.Should().ThrowExactlyAsync <ArgumentException>("Because id cannot be null or empty string.");
        }
Example #2
0
        public async Task GetAsync__Found_zero_matching_ticket__Should_throw_InvalidOperationException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    var service = new TicketDbService(context, _logger);

                    Func <Task> action = async() => await service.GetAsync("a");

                    await action.Should().ThrowExactlyAsync <InvalidOperationException>("Because Ticket not found.");
                }
            }
        }
Example #3
0
        public async Task GetAsync__Resource_is_null__Should_throw_InternalDbServiceException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    context.Tickets = null as DbSet <Ticket>;
                    var service = new TicketDbService(context, _logger);

                    Func <Task> action = async() => await service.GetAsync("a");

                    await action.Should().ThrowExactlyAsync <InternalDbServiceException>("Because resource reference is set to null");
                }
            }
        }
Example #4
0
        public async Task GetAsync__Resource_is_empty__Should_throw_InvalidOperationException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    context.Tickets.RemoveRange(await context.Tickets.ToListAsync());
                    await context.SaveChangesAsync();
                }

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

                    Func <Task> action = async() => await service.GetAsync("a");

                    await action.Should().ThrowExactlyAsync <InvalidOperationException>("Because resource is empty and cannot get single instance of Ticket.");
                }
            }
        }
Example #5
0
        public async Task GetAsync__Ticket_found__Should_return_this_ticket()
        {
            Ticket expectedTicket;

            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    expectedTicket = await context.Tickets.FirstOrDefaultAsync();
                }

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

                    var result = await service.GetAsync(expectedTicket.Id);

                    result.Should().BeEquivalentTo(expectedTicket);
                }
            }
        }
Example #6
0
        public async Task GetAsync__Resource_does_not_exit__Should_throw_InternalDbServiceException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    // Drop Tickets table.
                    context.Database.ExecuteSqlCommand("DROP TABLE [Tickets]");
                }

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

                    Func <Task> action = async() => await service.GetAsync("a");

                    await action.Should().ThrowExactlyAsync <InternalDbServiceException>("Because resource doesnt exist and cannot get single instance of Ticket. " +
                                                                                         "NOTE Excaption actually is type of 'SqLiteError' only if database provider is SQLite.");
                }
            }
        }