public void Can_generate_dynamic_delete_command_trees()
        {
            var model = TestContext.CreateDynamicUpdateModel();

            var commandTreeGenerator
                = new ModificationCommandTreeGenerator(model);

            var commandTrees
                = commandTreeGenerator
                  .GenerateDelete(GetType().Namespace + ".FunctionsModel.SpecialOrder")
                  .ToList();

            Assert.Equal(2, commandTrees.Count());

            var commandTree = (DbDeleteCommandTree)commandTrees.First();

            Assert.NotNull(commandTree.Predicate);
            Assert.Equal("special_orders", commandTree.Target.VariableType.EdmType.Name);

            commandTree = (DbDeleteCommandTree)commandTrees.Last();

            Assert.NotNull(commandTree.Predicate);
            Assert.Equal("Order", commandTree.Target.VariableType.EdmType.Name);

            commandTrees
                = commandTreeGenerator
                  .GenerateDelete(GetType().Namespace + ".FunctionsModel.Customer")
                  .ToList();

            Assert.Equal(1, commandTrees.Count());

            commandTree = (DbDeleteCommandTree)commandTrees.Single();

            Assert.NotNull(commandTree.Predicate);
            Assert.Equal("Customer", commandTree.Target.VariableType.EdmType.Name);
        }
Exemplo n.º 2
0
        public void Can_generate_delete_tree_when_self_ref_direct()
        {
            DbModel model;

            using (var context = new WorldContext_Identity())
            {
                model = context.InternalContext.CodeFirstModel.CachedModelBuilder.BuildDynamicUpdateModel(ProviderRegistry.Sql2008_ProviderInfo);
            }

            var commandTreeGenerator = new ModificationCommandTreeGenerator(model);

            var commandTrees = commandTreeGenerator.GenerateDelete(GetType().Namespace + ".Thing").ToList();

            Assert.Equal(1, commandTrees.Count());
        }
        public void Can_generate_delete_tree_when_one_to_one_self_ref()
        {
            DbModel model;

            using (var context = new GearsModelOneToOneSelfRef())
            {
                model
                    = context
                      .InternalContext
                      .CodeFirstModel
                      .CachedModelBuilder
                      .BuildDynamicUpdateModel(ProviderRegistry.Sql2008_ProviderInfo);
            }

            var commandTreeGenerator
                = new ModificationCommandTreeGenerator(model);

            var commandTrees
                = commandTreeGenerator
                  .GenerateDelete(GetType().Namespace + ".WeaponBase")
                  .ToList();

            Assert.Equal(1, commandTrees.Count());
        }
        public void Can_generate_delete_tree_when_ia_required_to_many()
        {
            DbModel model;

            using (var context = new ArubaContext())
            {
                model
                    = context
                      .InternalContext
                      .CodeFirstModel
                      .CachedModelBuilder
                      .BuildDynamicUpdateModel(ProviderRegistry.Sql2008_ProviderInfo);
            }

            var commandTreeGenerator
                = new ModificationCommandTreeGenerator(model);

            var commandTrees
                = commandTreeGenerator
                  .GenerateDelete(GetType().Namespace + ".ArubaTask")
                  .ToList();

            Assert.Equal(1, commandTrees.Count());
        }
        public void Can_generate_delete_tree_when_table_splitting_dependent()
        {
            DbModel model;

            using (var context = new TableSplittingContext())
            {
                model
                    = context
                      .InternalContext
                      .CodeFirstModel
                      .CachedModelBuilder
                      .BuildDynamicUpdateModel(ProviderRegistry.Sql2008_ProviderInfo);
            }

            var commandTreeGenerator
                = new ModificationCommandTreeGenerator(model);

            var commandTrees
                = commandTreeGenerator
                  .GenerateDelete(GetType().Namespace + ".StandingStone")
                  .ToList();

            Assert.Equal(0, commandTrees.Count());
        }
        public void Can_convert_delete_command_trees()
        {
            var model = TestContext.CreateDynamicUpdateModel();

            var modificationFunctionMapping
                = TestContext.GetModificationFunctionMapping("ExtraSpecialOrder");

            var converter
                = new DynamicToFunctionModificationCommandConverter(
                      modificationFunctionMapping.Item1, modificationFunctionMapping.Item2);

            var modificationCommandTreeGenerator
                = new ModificationCommandTreeGenerator(model);

            var commandTrees
                = modificationCommandTreeGenerator
                  .GenerateDelete(modificationFunctionMapping.Item1.EntityType.FullName);

            Assert.Equal(3, commandTrees.Count());

            var resultTrees = converter.Convert(commandTrees);

            Assert.Equal(3, resultTrees.Count());

            var lastCommandTree = resultTrees.Last();

            Assert.Equal(7, lastCommandTree.Parameters.Count());

            Assert.Equal("xid", lastCommandTree.Parameters.ElementAt(0).Key);
            Assert.Equal("key_for_delete", lastCommandTree.Parameters.ElementAt(1).Key);
            Assert.Equal("Code", lastCommandTree.Parameters.ElementAt(2).Key);
            Assert.Equal("Signature", lastCommandTree.Parameters.ElementAt(3).Key);
            Assert.Equal("Name_Original", lastCommandTree.Parameters.ElementAt(4).Key);
            Assert.Equal("RowVersion_Original", lastCommandTree.Parameters.ElementAt(5).Key);
            Assert.Equal("Customer_CustomerId", lastCommandTree.Parameters.ElementAt(6).Key);
        }