public void Can_insert_and_delete_when_many_to_many()
            {
                using (var context = CreateContext())
                {
                    var tag = new FunctionalTests.FunctionsScenarioTests.ModificationFunctions.Tag
                    {
                        Products = new List <FunctionalTests.FunctionsScenarioTests.ModificationFunctions.ProductA>
                        {
                            new FunctionalTests.FunctionsScenarioTests.ModificationFunctions.ProductA()
                        }
                    };

                    Assert.Equal(0, context.Set <FunctionalTests.FunctionsScenarioTests.ModificationFunctions.Tag>().SelectMany(t => t.Products).Count());

                    // Insert
                    context.Set <FunctionalTests.FunctionsScenarioTests.ModificationFunctions.Tag>().Add(tag);
                    context.SaveChanges();

                    Assert.Equal(1, context.Set <FunctionalTests.FunctionsScenarioTests.ModificationFunctions.Tag>().SelectMany(t => t.Products).Count());

                    // Delete
                    tag.Products.Clear();
                    context.SaveChanges();

                    Assert.Equal(0, context.Set <FunctionalTests.FunctionsScenarioTests.ModificationFunctions.Tag>().SelectMany(t => t.Products).Count());
                }
            }
コード例 #2
0
            public void Can_insert_and_delete_when_many_to_many()
            {
                ExtendedSqlAzureExecutionStrategy.ExecuteNew(
                    () =>
                    {
                        using (new TransactionScope())
                        {
                            using (var context = CreateContext())
                            {
                                var tag = new FunctionalTests.FunctionsScenarioTests.ModificationFunctions.Tag
                                {
                                    Products = new List<FunctionalTests.FunctionsScenarioTests.ModificationFunctions.ProductA>
                                    {
                                        new FunctionalTests.FunctionsScenarioTests.ModificationFunctions.ProductA()
                                    }
                                };

                                Assert.Equal(
                                    0,
                                    context.Set<FunctionalTests.FunctionsScenarioTests.ModificationFunctions.Tag>()
                                        .SelectMany(t => t.Products)
                                        .Count());

                                // Insert
                                context.Set<FunctionalTests.FunctionsScenarioTests.ModificationFunctions.Tag>().Add(tag);
                                context.SaveChanges();

                                Assert.Equal(
                                    1,
                                    context.Set<FunctionalTests.FunctionsScenarioTests.ModificationFunctions.Tag>()
                                        .SelectMany(t => t.Products)
                                        .Count());

                                // Delete
                                tag.Products.Clear();
                                context.SaveChanges();

                                Assert.Equal(
                                    0,
                                    context.Set<FunctionalTests.FunctionsScenarioTests.ModificationFunctions.Tag>()
                                        .SelectMany(t => t.Products)
                                        .Count());
                            }
                        }
                    });
            }