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

            var commandTreeGenerator
                = new ModificationCommandTreeGenerator(model);

            var commandTrees
                = commandTreeGenerator
                  .GenerateAssociationInsert(GetType().Namespace + ".FunctionsModel.OrderThing_Orders")
                  .ToList();

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

            var commandTree = commandTrees.First();

            Assert.Equal(5, commandTree.SetClauses.Count);
            Assert.Equal("OrderThingOrder", commandTree.Target.VariableType.EdmType.Name);
            Assert.Null(commandTree.Returning);
        }
        public void Can_generate_insert_association_tree_when_many_to_many_with_abstract_target_end()
        {
            DbModel model;

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

            var commandTreeGenerator
                = new ModificationCommandTreeGenerator(model);

            var commandTrees
                = commandTreeGenerator
                  .GenerateAssociationInsert(GetType().Namespace + ".GearBase_Weapons")
                  .ToList();

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

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

            var commandTreeGenerator
                = new ModificationCommandTreeGenerator(model);

            var commandTrees
                = commandTreeGenerator
                  .GenerateAssociationInsert(GetType().Namespace + ".ArubaPerson_Children")
                  .ToList();

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

            var modificationFunctionMapping
                = TestContext.GetAssociationModificationFunctionMapping("OrderThing_Orders");

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

            var modificationCommandTreeGenerator
                = new ModificationCommandTreeGenerator(model);

            var commandTrees
                = modificationCommandTreeGenerator
                  .GenerateAssociationInsert(modificationFunctionMapping.Item1.AssociationSet.ElementType.FullName);

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

            var resultTrees = converter.Convert(commandTrees);

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

            var commandTree = resultTrees.First();

            Assert.Equal(5, commandTree.Parameters.Count());
            Assert.Equal(5, commandTree.SetClauses.Count());

            Assert.Equal("order_thing_id", commandTree.Parameters.ElementAt(0).Key);
            Assert.Equal("Order_Id", commandTree.Parameters.ElementAt(1).Key);
            Assert.Equal("Order_Key", commandTree.Parameters.ElementAt(2).Key);
            Assert.Equal("teh_codez_bro", commandTree.Parameters.ElementAt(3).Key);
            Assert.Equal("Order_Signature", commandTree.Parameters.ElementAt(4).Key);
            Assert.Null(commandTree.Returning);
        }