public void AddAsync_throws_if_model_is_null()
        {
            IInventoryRepository repository = new InventoryRepository(_context);


            Cupcake cupcake = null;

            Assert.ThrowsAsync <ArgumentException>(() => repository.AddAsync(cupcake));
        }
        public async Task AddAsync_inserts_model_into_repository()
        {
            IInventoryRepository repository = new InventoryRepository(_context);

            Cupcake cupcake = new Cupcake {
                Name = "FooBar Sprinkles"
            };

            await repository.AddAsync(cupcake);

            var savedCupcake = Assert.Single(_context.Cupcakes);

            Assert.Equal(cupcake.Name, savedCupcake.Name);
        }
Esempio n. 3
0
        public async Task <ActionResult <InventoryDto> > CreateAsync([FromBody] InventoryDto dto, CancellationToken cancellationToken)
        {
            var itemDto = dto.Item;

            var item = itemDto.MapItem();


            var inventory = new Inventory
            {
                Quantity  = dto.Quantity,
                UnitPrice = dto.UnitPrice,
                Item      = item
            };

            inventory = await _repo.AddAsync(inventory, cancellationToken);

            return(Ok(inventory));
        }