Пример #1
0
        public void GetAllFail()
        {
            var carRepository = new Mock <ICarRepository>();

            carRepository.Setup(x => x.GetAll()).Returns(GetCars);
            var carBusiness = new CarBusiness(carRepository.Object);

            var result = carBusiness.GetAll();

            Assert.False(result.Count != 3);
        }
Пример #2
0
        public void GetAllSucess()
        {
            var carRepository = new Mock <ICarRepository>();

            carRepository.Setup(x => x.GetAll()).Returns(GetCars);
            var carBusiness = new CarBusiness(carRepository.Object);

            var result = carBusiness.GetAll();

            Assert.NotNull(result);
            Assert.True(result.Count == 3);
        }
Пример #3
0
 public Car[] GetAll()
 {
     try
     {
         using (var c = new CarBusiness())
         {
             return(c.GetAll().ToArray());
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(null);
     }
 }
Пример #4
0
 public IHttpActionResult Get(int id)
 {
     try
     {
         using (var c = new CarBusiness())
         {
             var temp = c.GetAll().Where(s => s.Id == id).FirstOrDefault();
             if (temp == null)
             {
                 return(NotFound());
             }
             return(Ok(temp));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest($"{ex}"));
     }
 }
Пример #5
0
 public IHttpActionResult Get()
 {
     try
     {
         using (var c = new CarBusiness())
         {
             var templist = c.GetAll().ToList();
             if (templist == null)
             {
                 return(NotFound());
             }
             return(Ok(templist));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest($"{ex}"));
     }
 }