Beispiel #1
0
        public async Task VoucherManagementManager_GetVoucherByCode_VoucherRetrieved()
        {
            EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory);

            await context.Vouchers.AddAsync(new Voucher
            {
                EstateId    = TestData.EstateId,
                VoucherId   = TestData.VoucherId,
                VoucherCode = TestData.VoucherCode
            });

            await context.SaveChangesAsync(CancellationToken.None);

            var dbContextFactory = this.GetMockDbContextFactory();

            dbContextFactory.Setup(d => d.GetContext(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(context);

            Mock <IAggregateRepository <VoucherAggregate, DomainEventRecord.DomainEvent> > voucherAggregateRepository = new Mock <IAggregateRepository <VoucherAggregate, DomainEventRecord.DomainEvent> >();

            voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(TestData.GetVoucherAggregateWithRecipientMobile);

            VoucherManagementManager manager = new VoucherManagementManager(dbContextFactory.Object, voucherAggregateRepository.Object);

            Models.Voucher voucher = await manager.GetVoucherByCode(TestData.EstateId, TestData.VoucherCode, CancellationToken.None);

            voucher.ShouldNotBeNull();
        }
Beispiel #2
0
        public async Task VoucherManagementManager_GetVoucherByCode_VoucherNotFound_ErrorThrown()
        {
            EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory);

            await context.SaveChangesAsync(CancellationToken.None);

            var dbContextFactory = this.GetMockDbContextFactory();

            dbContextFactory.Setup(d => d.GetContext(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(context);

            Mock <IAggregateRepository <VoucherAggregate, DomainEventRecord.DomainEvent> > voucherAggregateRepository = new Mock <IAggregateRepository <VoucherAggregate, DomainEventRecord.DomainEvent> >();

            VoucherManagementManager manager = new VoucherManagementManager(dbContextFactory.Object, voucherAggregateRepository.Object);

            Should.Throw <NotFoundException>(async() =>
            {
                await manager.GetVoucherByCode(TestData.EstateId, TestData.VoucherCode, CancellationToken.None);
            });
        }