Exemple #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 EntityOptions <DbContext>()).ToArray(); }).Message);
        }
Exemple #2
0
        public void Throws_for_unsupported_combinations()
        {
            var model      = BuildModel();
            var entityType = model.GetEntityType(typeof(AnEntity));

            var selector = InMemoryTestHelpers.Instance.CreateContextServices(model).GetRequiredService <IValueGeneratorSelector>();

            Assert.Equal(
                CoreStrings.NoValueGenerator("Random", "AnEntity", typeof(Random).Name),
                Assert.Throws <NotSupportedException>(() => selector.Select(entityType.GetProperty("Random"), entityType)).Message);
        }
Exemple #3
0
        public void Configure_throws_if_MaxBatchSize_specified_in_raw_options_is_invalid()
        {
            var rawOptions = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { MaxBatchSizeKey, "one" }
            };

            Assert.Equal(
                CoreStrings.IntegerConfigurationValueFormatError(MaxBatchSizeKey, "one"),
                Assert.Throws <InvalidOperationException>(() => new TestRelationalOptionsExtension().Configure(rawOptions)).Message);
        }
Exemple #4
0
        public void Throws_for_unsupported_combinations()
        {
            var selector = new InMemoryValueGeneratorSelector(
                new SimpleValueGeneratorFactory <GuidValueGenerator>(),
                new SimpleValueGeneratorFactory <InMemoryValueGenerator>());

            var typeMock = new Mock <IEntityType>();

            typeMock.Setup(m => m.Name).Returns("AnEntity");

            var property = CreateProperty(typeof(double));

            Assert.Equal(
                CoreStrings.NoValueGenerator("MyProperty", "MyType", "Double"),
                Assert.Throws <NotSupportedException>(() => selector.Select(property)).Message);
        }
        public void Throws_for_unsupported_combinations()
        {
            var selector = new SqlServerValueGeneratorSelector(
                new SimpleValueGeneratorFactory <GuidValueGenerator>(),
                new SimpleValueGeneratorFactory <TemporaryValueGenerator>(),
                new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory())),
                new SimpleValueGeneratorFactory <SequentialGuidValueGenerator>());

            var property = new BasicModelBuilder()
                           .Entity <Robot>()
                           .Property(e => e.String)
                           .GenerateValueOnAdd()
                           .Metadata;

            Assert.Equal(
                CoreStrings.NoValueGenerator("String", typeof(Robot).FullName, "String"),
                Assert.Throws <NotSupportedException>(() => selector.Select(property)).Message);
        }