Beispiel #1
0
        public async Task EnsureInvoiceCreated()
        {
            var model = new InvoiceModelBuilder().Default;

            using (var ctx = CreateContext())
            {
                var repo     = new CustomerRepository(ctx);
                var customer = Mapper.Map <Customer>(new CustomerModelBuilder().Default);
                await repo.AddAsync(customer);

                var first = ctx.Customers.First();
                model.CustomerId = first.Id;
                var invoiceRepository = new InvoiceRepository(ctx);
                await invoiceRepository.AddAsync(Mapper.Map <Invoice>(model));
            }

            using (var ctx = CreateContext())
            {
                var repo     = new CustomerRepository(ctx);
                var customer = await repo.GetAsync(model.CustomerId);

                var invoices = customer.Invoices;
                invoices.Count.ShouldBe(1);
            }
        }
Beispiel #2
0
        public async Task WhenWeAskToAdd_ShouldBeAskedToStoreInCosmosDB()
        {
            var newEntity = DomainGenerator.InvoiceGenerator().Generate();

            var updatedEntity = await _sut.AddAsync(newEntity);

            await _genericRepo.Received().CreateAsync(Arg.Any <Invoice>());
        }
        public async Task <ActionResult> PostInvoice(Invoice invoiceDTO)
        {
            try
            {
                await _invoiceRepository.AddAsync(invoiceDTO);

                return(StatusCode(StatusCodes.Status201Created));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }