コード例 #1
0
        public void Batch_command_throws_on_commands_with_circular_dependencies()
        {
            var model         = CreateCyclicFKModel();
            var configuration = CreateContextServices(model);
            var stateManager  = configuration.GetRequiredService <IStateManager>();

            var fakeEntry = stateManager.GetOrCreateEntry(new FakeEntity {
                Id = 42, RelatedId = 1
            });

            fakeEntry.SetEntityState(EntityState.Added);

            var relatedFakeEntry = stateManager.GetOrCreateEntry(new RelatedFakeEntity {
                Id = 1, RelatedId = 42
            });

            relatedFakeEntry.SetEntityState(EntityState.Added);

            Assert.Equal(
                CoreStrings.CircularDependency(
                    string.Join(", ",
                                model.GetEntityType(typeof(RelatedFakeEntity)).GetForeignKeys().First(),
                                model.GetEntityType(typeof(FakeEntity)).GetForeignKeys().First())),
                Assert.Throws <InvalidOperationException>(
                    () => { var commandBatches = CreateCommandBatchPreparer().BatchCommands(new[] { fakeEntry, relatedFakeEntry }, new DbContextOptions <DbContext>()).ToArray(); }).Message);
        }