Пример #1
0
        public void TestCarCreate()
        {
            using (RaceContext context = new RaceContext())
            {
                using (CarCRUD CarCRUD = new CarCRUD(new RaceContext()))
                {
                    var Car = new Cars {
                        Name = "Test", DriverName = "Test"
                    };

                    Assert.NotNull(context.Cars.Where(a => a.Id == CarCRUD.Create(Car)).FirstOrDefault());
                }
            }
        }
Пример #2
0
        public void Create_given_car_returns_id()
        {
            var cc = new CarCRUD(context);

            var car = new Car {
                Name = "Car One", DriverName = "Driver One"
            };

            int expected = car.CarId;
            int actual   = cc.Create(car);

            Assert.Equal(expected, actual);
            context.Remove(car);
            context.SaveChanges();
        }
Пример #3
0
 public void TestDisposed()
 {
     using (CarCRUD CarCRUD = new CarCRUD(new RaceContext()))
     {
         CarCRUD.Dispose();
         try
         {
             CarCRUD.Create(new Cars {
                 Name = "hello", DriverName = "hn"
             });
             Assert.True(false);
         }
         catch (Exception e)
         {
             Assert.True(true);
         }
     }
 }
Пример #4
0
        public void Delete_given_carid_deletes_car()
        {
            var cc = new CarCRUD(context);

            var car = new Car {
                Name = "Car Four", DriverName = "Driver Four"
            };

            cc.Create(car);

            var carToDelete = new Car {
                Name = "Car Four", DriverName = "Driver Four"
            };

            cc.Delete(carToDelete.CarId);
            bool notDeleted = context.Car.Any(c => c.CarId == carToDelete.CarId);

            Assert.False(notDeleted);
        }
Пример #5
0
        public void FindById_given_id_returns_car()
        {
            var cc = new CarCRUD(context);

            var car = new Car {
                Name = "Car Two", DriverName = "Driver Two"
            };

            cc.Create(car);

            var expected = car;
            var actual   = cc.FindById(car.CarId);

            Assert.Equal(expected.CarId, actual.CarId);
            Assert.Equal(expected.Name, actual.Name);
            Assert.Equal(expected.DriverName, actual.DriverName);
            context.Remove(car);
            context.SaveChanges();
        }
Пример #6
0
        public void Update_given_car_updates_car()
        {
            var cc = new CarCRUD(context);

            var car = new Car {
                Name = "Car Three", DriverName = "Driver Three"
            };

            cc.Create(car);

            car.Name = "Super Awesome Car";
            cc.Update(car);

            var expected = "Super Awesome Car";
            var actual   = car.Name;

            Assert.Equal(expected, actual);
            context.Remove(car);
            context.SaveChanges();
        }