Exemplo n.º 1
0
        public async Task Should_Update()
        {
            await using (var context = new DbContextFactory().CreateContext())
            {
                var service = new PromoServiceFactory().Create(context);

                var promo = await context.Promos.FirstAsync();

                promo.Should().NotBeNull();

                var newDate = promo.End.AddYears(1);

                var result = await service.Update(new UpdatePromoBody()
                {
                    Id       = promo.Id,
                    Active   = promo.Active,
                    Discount = promo.Discount,
                    End      = newDate,
                    Start    = promo.Start
                });

                result.Should().NotBeNull();

                var check = await context.Promos.FirstOrDefaultAsync(x => x.Id == promo.Id);

                check.Should().NotBeNull();
                check.End.Should().Be(newDate);
            }
        }
Exemplo n.º 2
0
        public async Task Should_Not_Find_Promo()
        {
            await using (var context = new DbContextFactory().CreateContext())
            {
                var service = new PromoServiceFactory().Create(context);

                FluentActions.Invoking(async() => await service.Update(new UpdatePromoBody()))
                .Should().Throw <PromoNotFoundException>();
            }
        }
Exemplo n.º 3
0
        public async Task Should_Destroy()
        {
            await using (var context = new DbContextFactory().CreateContext())
            {
                var service = new PromoServiceFactory().Create(context);

                var promo = await context.Promos.FirstAsync();

                promo.Should().NotBeNull();

                await service.Destroy(promo.Id);

                var check = await context.Promos.FirstOrDefaultAsync(x => x.Id == promo.Id);

                check.Should().BeNull();
            }
        }
Exemplo n.º 4
0
        public async Task Should_Create()
        {
            await using (var context = new DbContextFactory().CreateContext())
            {
                var service = new PromoServiceFactory().Create(context);

                var createPromoBody = Data.Data.FakeCreatePromoBody.Generate();
                var e = await context.Events.FirstAsync();

                e.Should().NotBeNull();
                createPromoBody.EventId = e.Id;

                var result = await service.Create(createPromoBody);

                result.Should().NotBeNull();

                var check = await context.Promos.FirstOrDefaultAsync(x => x.Id == result.Id);

                check.Should().NotBeNull();
            }
        }