Exemplo n.º 1
0
        public async Task GetByAsync__Argument_predicate_is_null__Should_throw_ArgumentNullException()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    var service = new TicketDbService(context, _logger);

                    Func <Task> action = async() => await service.GetByAsync(null);

                    await action.Should().ThrowExactlyAsync <ArgumentNullException>();
                }
            }
        }
Exemplo n.º 2
0
        public async Task GetByAsync__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.GetByAsync(_predicate);

                    await action.Should().ThrowExactlyAsync <InternalDbServiceException>("Because resource reference is set to null");
                }
            }
        }
Exemplo n.º 3
0
        public async Task GetByAsync__None_ticket_tariffs_satisfy_predicate__Should_return_empty_IEnumerable()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    var service = new TicketDbService(context, _logger);

                    // This predicate filters tariffs with CreatedAt equals DateTime.MaxValue. It will none tariffs.
                    var result = await service.GetByAsync(x => x.CreatedAt == DateTime.MaxValue);

                    result.Count().Should().Be(0);
                }
            }
        }
Exemplo n.º 4
0
        public async Task GetByAsync__At_least_one_ticket_tariffs_found__Should_return_IEnumerable_for_this_tarifs()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    int expectedLength = context.Tickets.ToArray().Length;
                    var service        = new TicketDbService(context, _logger);

                    // This predicate filters tariffs with CreatedAt after DateTime.MinValue. It will be all of tariffs.
                    var result = await service.GetByAsync(_predicate);

                    result.Count().Should().Be(expectedLength);
                }
            }
        }
Exemplo n.º 5
0
        public async Task GetByAsync__Resource_is_empty__Should_return_empty_IEnumerable()
        {
            using (var factory = new DbContextFactory())
            {
                using (var context = await factory.CreateContextAsync())
                {
                    context.Tickets.RemoveRange(await context.Tickets.ToArrayAsync());
                    await context.SaveChangesAsync();
                }

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

                    var result = await service.GetByAsync(_predicate);

                    result.Count().Should().Be(0);
                }
            }
        }
Exemplo n.º 6
0
        public async Task GetByAsync__Resource_does_not_exist__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.GetByAsync(_predicate);

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