Ejemplo n.º 1
0
 public Car Add(Car item)
 {
     var newCar = (Car)item.Clone();
     newCar.Id = !_cars.Any() ? 1 : _cars.Max(car => car.Id) + 1;
     _cars.Add(newCar);
     return (Car)newCar.Clone();
 }
        public void AddTest()
        {
            var brand = Guid.NewGuid().ToString();
            var model = Guid.NewGuid().ToString();
            var typ = Guid.NewGuid().ToString();
            var fuelType = Guid.NewGuid().ToString();

            var newGroup = new Car
            {
                Brand = brand,
                Model = model,
                CarType = typ,
                FuelType = fuelType
            };

            var addedGroupTask = service.AddAsync(newGroup);

            var addedGroup = addedGroupTask.Result;

            Assert.IsNotNull(addedGroup);
            Assert.IsTrue(addedGroup.Id > 0);
            Assert.AreEqual(addedGroup.Brand, brand);
            Assert.AreEqual(addedGroup.Model, model);
            Assert.AreEqual(addedGroup.CarType, typ);
            Assert.AreEqual(addedGroup.FuelType, fuelType);
        }
Ejemplo n.º 3
0
 public Car Update(Car item)
 {
     var returnCar = _cars.SingleOrDefault(car => car.Id == item.Id);
     if (returnCar == null)
     {
         throw new NullReferenceException();
     }
     returnCar.Brand = item.Brand;
     return (Car)returnCar.Clone();
 }