Exemplo n.º 1
0
        public void Throw_When_InvalidId()
        {
            var options     = Utils.GetOptions(nameof(Throw_When_InvalidId));
            var mockService = new Mock <IAddressService>();

            using (var actContext = new DeliverItContext(options))
            {
                var sut = new WarehouseService(actContext, mockService.Object);
                Assert.ThrowsException <ArgumentException>(() => sut.Get(1));
            }
        }
 public IActionResult Get(string id)
 {
     if (id != null)
     {
         Warehouse warehouse = service.Get(id);
         if (warehouse != null)
         {
             return(Ok(warehouse));
         }
     }
     return(BadRequest());
 }
Exemplo n.º 3
0
        public async Task <IActionResult> Get(int id)
        {
            try
            {
                var warehouse = await wahoServ.Get(id);

                if (warehouse == null)
                {
                    return(NotFound());
                }
                else
                {
                    return(Ok(warehouse));
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                return(StatusCode(500));
            }
        }
Exemplo n.º 4
0
        public void ReturnWarehouseById()
        {
            var options     = Utils.GetOptions(nameof(ReturnWarehouseById));
            var mockService = new Mock <IAddressService>();

            using (var arrContext = new DeliverItContext(options))
            {
                arrContext.Warehouses.AddRange(Utils.SeedWarehouses());
                arrContext.Addresses.AddRange(Utils.SeedAddresses());
                arrContext.Cities.AddRange(Utils.SeedCities());
                arrContext.SaveChanges();
            }
            using (var actContext = new DeliverItContext(options))
            {
                var sut       = new WarehouseService(actContext, mockService.Object);
                var result    = sut.Get(1);
                var warehouse = actContext.Warehouses.FirstOrDefault(w => w.Id == 1);
                Assert.AreEqual(warehouse.Address.StreetName + ", " + warehouse.Address.City.Name, result.Address);
                Assert.IsInstanceOfType(result, typeof(WarehouseDTO));
            }
        }