Exemplo n.º 1
0
        public void S_DataObject_Should_CRUD_An_Item_With_Shared_Transactional_Data_Context()
        {
            using (var context = new DataContext())
            {
                var dodge = new Manufacturer { Name = "Dodge", BuildYear = 1900 };
                manufacturerDataObject.Insert(dodge, context);

                dodge.BuildYear = 1915;
                manufacturerDataObject.Update(dodge, context);
                var updatedDodge = context.First<Manufacturer>("SELECT TOP 1 * FROM Le_Manufacturer WHERE Name = 'Dodge'");

                var m4s = new Car { Name = "M4S", ModelYear = 1984, Category = CarCategory.Prototype, ManufacturerId = dodge.TheId };
                carDataObject.Insert(m4s, context);
                var createdM4s = carDataObject.Select.With(context).First("WHERE Name = 'M4S'");

                carDataObject.Delete(m4s, context);
                var deletedM4s = carDataObject.Select.With(context).First("WHERE Name = 'M4S'");

                updatedDodge.BuildYear.Should().Be(1915);
                createdM4s.Should().NotBeNull();
                deletedM4s.Should().BeNull();

                context.Commit();
            }

            var createdDodgeOutsiteContext = manufacturerDataObject.Select.First("WHERE Name = 'Dodge'");
            createdDodgeOutsiteContext.Should().NotBeNull();
        }
Exemplo n.º 2
0
        public void L_DataContext_Should_Throws_An_Exeption_When_A_Constraint_Was_Broken()
        {
            using (var context = new DataContext())
            {
                var insertParameters = new Car
                {
                    Name = "AGL 1113",
                    ModelYear = 1964,
                    Mileage = 1567922,
                    ManufacturerId = 98765, // Invalid ManufacturerId
                    Category = CarCategory.Transport
                };

                context.Execute("INSERT INTO Car VALUES (@Name, @ModelYear, @CreatedAt, @Chassis, @Mileage, @Category, @ManufacturerId)", insertParameters);
            }
        }
Exemplo n.º 3
0
        public void M_DataObject_Should_Insert_Item_From_Database_And_Set_Primery_Key()
        {
            var car = new Car { Name = "Aventador", ModelYear = 2011, Category = CarCategory.Sport };
            carDataObject.Insert(car);

            car.Id.Should().BeGreaterThan(0);

            using (var context = new DataContext())
            {
                var query = "SELECT TOP 1 * FROM Car WHERE Name = 'Aventador'";
                var createdManufacturer = context.First<Car>(query);

                createdManufacturer.Should().NotBeNull();
            }
        }
Exemplo n.º 4
0
        public void F_DataContext_Should_Read_Data_With_One_Field_And_Insert_A_Data_With_Some_Parameters_Types()
        {
            using (var context = new DataContext())
            {
                var selectParameters = new { Name = "Lotus" };
                var manufacturer = context.First<Manufacturer>("SELECT TheId FROM Le_Manufacturer WHERE Name = @Name", selectParameters);

                var insertParameters = new Car
                {
                    Name = "Esprit Turbo",
                    ModelYear = 1981,
                    Mileage = 318.19850801,
                    ManufacturerId = manufacturer.TheId,
                    Category = CarCategory.Sport
                };

                context.Execute("INSERT INTO Car VALUES (@Name, @ModelYear, @CreatedAt, @Chassis, @Mileage, @Category, @ManufacturerId)", insertParameters);
                var car = context.First<Car>("SELECT TOP 1 * FROM Car");
                context.Commit();

                car.Id.Should().BeGreaterThan(0);
                car.Name.Should().Be("Esprit Turbo");
                car.ModelYear.Should().Be(1981);
                car.Mileage.Should().Be(318.19850801);
                car.ManufacturerId.Should().Be(manufacturer.TheId);
                car.CreatedAt.Date.Should().Be(DateTime.Today.Date);
                car.Category.Should().Be(CarCategory.Sport);
            }
        }