Exemplo n.º 1
0
 internal DynamicWrapperLoadException(string wrapperName, Exception inner)
     : base(CoreResources.GetString("dynamic_wrapper_loading_failed", wrapperName), inner)
 {
 }
Exemplo n.º 2
0
        public virtual object __construct(ScriptContext context, [Optional] object message, [Optional] object code, [Optional] object previous)
        {
            this.message.Value = (message == Arg.Default || message == Type.Missing) ? CoreResources.GetString("default_exception_message") : message;
            this.code.Value    = (code == Arg.Default || code == Type.Missing) ? 0 : code;
            this.previous      = (previous == Arg.Default || previous == Type.Missing) ? null : previous;

            Debug.Assert(this.previous == null || (this.previous is DObject && ((DObject)this.previous).RealObject is Exception));

            // stack is already captured by CLR ctor //

            return(null);
        }
            public virtual void Index_removed_when_covered_by_an_inherited_foreign_key()
            {
                var modelBuilder = CreateModelBuilder();

                modelBuilder.Ignore <CustomerDetails>();
                modelBuilder.Ignore <OrderDetails>();
                modelBuilder.Ignore <BackOrder>();
                modelBuilder.Ignore <SpecialCustomer>();

                var principalEntityBuilder        = modelBuilder.Entity <Customer>();
                var derivedPrincipalEntityBuilder = modelBuilder.Entity <OtherCustomer>();
                var dependentEntityBuilder        = modelBuilder.Entity <Order>();
                var derivedDependentEntityBuilder = modelBuilder.Entity <BackOrder>();

                var dependentEntityType        = dependentEntityBuilder.Metadata;
                var derivedDependentEntityType = derivedDependentEntityBuilder.Metadata;

                Assert.Empty(derivedDependentEntityType.GetDeclaredIndexes());

                principalEntityBuilder.HasMany(c => c.Orders).WithOne(o => o.Customer)
                .HasForeignKey(
                    o => new { o.CustomerId, o.AnotherCustomerId })
                .HasPrincipalKey(
                    c => new { c.Id, c.AlternateKey });

                Assert.Empty(derivedDependentEntityType.GetDeclaredIndexes());

                derivedPrincipalEntityBuilder.HasMany <BackOrder>().WithOne()
                .HasForeignKey(
                    o => new { o.CustomerId })
                .HasPrincipalKey(
                    c => new { c.Id });

                var fk = dependentEntityType.GetForeignKeys().Single();

                Assert.Equal(1, dependentEntityType.GetIndexes().Count());
                Assert.False(dependentEntityType.FindIndex(fk.Properties).IsUnique);
                Assert.False(derivedDependentEntityType.GetDeclaredForeignKeys().Single().IsUnique);
                Assert.Empty(derivedDependentEntityType.GetDeclaredIndexes());

                var backOrderClone     = modelBuilder.Model.Clone().FindEntityType(derivedDependentEntityType.Name);
                var initialProperties  = backOrderClone.GetProperties().ToList();
                var initialKeys        = backOrderClone.GetKeys().ToList();
                var initialIndexes     = backOrderClone.GetIndexes().ToList();
                var initialForeignKeys = backOrderClone.GetForeignKeys().ToList();

                derivedDependentEntityBuilder.HasBaseType(null);

                var derivedFk = derivedDependentEntityType.GetForeignKeys()
                                .Single(foreignKey => foreignKey.PrincipalEntityType == derivedPrincipalEntityBuilder.Metadata);

                Assert.Equal(2, derivedDependentEntityType.GetIndexes().Count());
                Assert.False(derivedDependentEntityType.FindIndex(derivedFk.Properties).IsUnique);

                derivedDependentEntityBuilder.HasBaseType <Order>();

                fk = dependentEntityType.GetForeignKeys().Single();
                Assert.Equal(1, dependentEntityType.GetIndexes().Count());
                Assert.False(dependentEntityType.FindIndex(fk.Properties).IsUnique);

                AssertEqual(initialProperties, derivedDependentEntityType.GetProperties(), new PropertyComparer(compareAnnotations: false));
                AssertEqual(initialKeys, derivedDependentEntityType.GetKeys());
                AssertEqual(initialIndexes, derivedDependentEntityType.GetIndexes());
                AssertEqual(initialForeignKeys, derivedDependentEntityType.GetForeignKeys());

                principalEntityBuilder.HasOne <Order>().WithOne()
                .HasPrincipalKey <Customer>(
                    c => new { c.Id })
                .HasForeignKey <Order>(
                    o => new { o.CustomerId });

                modelBuilder.FinalizeModel();

                var(Level, _, Message, _, _) = modelBuilder.ModelLoggerFactory.Log.Single(e => e.Id == CoreEventId.RedundantIndexRemoved);
                Assert.Equal(LogLevel.Debug, Level);
                Assert.Equal(
                    CoreResources.LogRedundantIndexRemoved(new TestLogger <TestLoggingDefinitions>()).GenerateMessage(
                        "{'CustomerId'}", nameof(Order), "{'CustomerId', 'AnotherCustomerId'}"), Message);

                fk = dependentEntityType.GetForeignKeys().Single(foreignKey => foreignKey.DependentToPrincipal == null);
                Assert.Equal(2, dependentEntityType.GetIndexes().Count());
                Assert.True(dependentEntityType.FindIndex(fk.Properties).IsUnique);
                Assert.Empty(derivedDependentEntityType.GetDeclaredIndexes());
            }
            public virtual void Index_removed_when_covered_by_an_inherited_index()
            {
                var modelBuilder = CreateModelBuilder();

                modelBuilder.Ignore <CustomerDetails>();
                modelBuilder.Ignore <OrderDetails>();
                modelBuilder.Ignore <BackOrder>();
                modelBuilder.Ignore <SpecialCustomer>();

                modelBuilder.Entity <Customer>();
                var derivedPrincipalEntityBuilder = modelBuilder.Entity <OtherCustomer>();
                var dependentEntityBuilder        = modelBuilder.Entity <Order>();
                var derivedDependentEntityBuilder = modelBuilder.Entity <BackOrder>();

                dependentEntityBuilder.HasIndex(
                    o => new { o.CustomerId, o.AnotherCustomerId })
                .IsUnique();

                derivedPrincipalEntityBuilder.HasMany <BackOrder>().WithOne()
                .HasPrincipalKey(
                    c => new { c.Id })
                .HasForeignKey(
                    o => new { o.CustomerId });

                var dependentEntityType        = dependentEntityBuilder.Metadata;
                var derivedDependentEntityType = derivedDependentEntityBuilder.Metadata;
                var index = dependentEntityType.FindIndex(dependentEntityType.GetForeignKeys().Single().Properties);

                Assert.False(index.IsUnique);
                Assert.True(dependentEntityType.GetIndexes().Single(i => i != index).IsUnique);
                Assert.False(derivedDependentEntityType.GetDeclaredForeignKeys().Single().IsUnique);
                Assert.Empty(derivedDependentEntityType.GetDeclaredIndexes());

                var backOrderClone     = modelBuilder.Model.Clone().FindEntityType(derivedDependentEntityType.Name);
                var initialProperties  = backOrderClone.GetProperties().ToList();
                var initialKeys        = backOrderClone.GetKeys().ToList();
                var initialIndexes     = backOrderClone.GetIndexes().ToList();
                var initialForeignKeys = backOrderClone.GetForeignKeys().ToList();

                derivedDependentEntityBuilder.HasBaseType(null);

                var derivedFk = derivedDependentEntityType.GetForeignKeys()
                                .Single(foreignKey => foreignKey.PrincipalEntityType == derivedPrincipalEntityBuilder.Metadata);

                Assert.Equal(2, derivedDependentEntityType.GetIndexes().Count());
                Assert.False(derivedDependentEntityType.FindIndex(derivedFk.Properties).IsUnique);

                derivedDependentEntityBuilder.HasBaseType <Order>();

                modelBuilder.FinalizeModel();

                var indexRemoveMessage =
                    CoreResources.LogRedundantIndexRemoved(new TestLogger <TestLoggingDefinitions>()).GenerateMessage(
                        "{'CustomerId'}", nameof(Order), "{'CustomerId', 'AnotherCustomerId'}");

                Assert.Equal(1, modelBuilder.ModelLoggerFactory.Log.Count(l => l.Message == indexRemoveMessage));

                var baseFK    = dependentEntityType.GetForeignKeys().Single();
                var baseIndex = dependentEntityType.FindIndex(baseFK.Properties);

                Assert.False(baseIndex.IsUnique);
                Assert.True(dependentEntityType.GetIndexes().Single(i => i != baseIndex).IsUnique);
                Assert.False(derivedDependentEntityType.GetDeclaredForeignKeys().Single().IsUnique);
                Assert.Empty(derivedDependentEntityType.GetDeclaredIndexes());

                AssertEqual(initialProperties, derivedDependentEntityType.GetProperties(), new PropertyComparer(false));
                AssertEqual(initialKeys, derivedDependentEntityType.GetKeys());
                AssertEqual(initialIndexes, derivedDependentEntityType.GetIndexes());
                AssertEqual(initialForeignKeys, derivedDependentEntityType.GetForeignKeys());
            }
Exemplo n.º 5
0
 protected virtual string ExpectedMessage(string optionsFragment)
 => CoreResources.LogContextInitialized(new TestLogger <TestLoggingDefinitions>()).GenerateMessage(
     ProductInfo.GetVersion(),
     nameof(LoggingContext),
     ProviderName,
     optionsFragment ?? "None").Trim();
        public void Reports_debug_info_for_most_similar_existing_service_provider()
        {
            // Do this a bunch of times since in the past this exposed issues with cache collisions
            for (var i = 0; i < 1000; i++)
            {
                var loggerFactory = new ListLoggerFactory();

                var config1 = new DbContextOptionsBuilder(CreateOptions <CoreOptionsExtension>(loggerFactory))
                              .EnableDetailedErrors()
                              .EnableSensitiveDataLogging()
                              .ConfigureWarnings(w => w.Throw(CoreEventId.CascadeDelete))
                              .Options;

                var config2 = new DbContextOptionsBuilder(CreateOptions <CoreOptionsExtension>(loggerFactory))
                              .EnableDetailedErrors()
                              .EnableSensitiveDataLogging()
                              .ConfigureWarnings(w => w.Throw(CoreEventId.CascadeDeleteOrphan))
                              .Options;

                var config3 = new DbContextOptionsBuilder(CreateOptions <CoreOptionsExtension>(loggerFactory))
                              .EnableDetailedErrors()
                              .ConfigureWarnings(w => w.Throw(CoreEventId.CascadeDelete))
                              .Options;

                var config4 = new DbContextOptionsBuilder(CreateOptions <CoreOptionsExtension>(loggerFactory))
                              .EnableSensitiveDataLogging()
                              .ConfigureWarnings(w => w.Throw(CoreEventId.ContextDisposed))
                              .Options;

                var cache = new ServiceProviderCache();

                var first  = cache.GetOrAdd(config1, true);
                var second = cache.GetOrAdd(config2, true);
                var third  = cache.GetOrAdd(config3, true);
                var forth  = cache.GetOrAdd(config4, true);

                Assert.NotSame(first, second);
                Assert.NotSame(first, third);
                Assert.NotSame(first, forth);
                Assert.NotSame(second, third);
                Assert.NotSame(second, forth);
                Assert.NotSame(third, forth);

                Assert.Equal(4, loggerFactory.Log.Count);

                Assert.Equal(
                    CoreResources.LogServiceProviderCreated(new TestLogger <TestLoggingDefinitions>()).GenerateMessage(),
                    loggerFactory.Log[0].Message);

                Assert.Equal(
                    CoreResources.LogServiceProviderDebugInfo(new TestLogger <TestLoggingDefinitions>()).GenerateMessage(
                        CoreStrings.ServiceProviderConfigChanged("Core:ConfigureWarnings")),
                    loggerFactory.Log[1].Message);

                Assert.Equal(
                    CoreResources.LogServiceProviderDebugInfo(new TestLogger <TestLoggingDefinitions>()).GenerateMessage(
                        CoreStrings.ServiceProviderConfigChanged("Core:EnableSensitiveDataLogging")),
                    loggerFactory.Log[2].Message);

                Assert.Equal(
                    CoreResources.LogServiceProviderDebugInfo(new TestLogger <TestLoggingDefinitions>()).GenerateMessage(
                        string.Join(
                            ", ",
                            CoreStrings.ServiceProviderConfigChanged("Core:EnableDetailedErrors"),
                            CoreStrings.ServiceProviderConfigChanged("Core:ConfigureWarnings"))),
                    loggerFactory.Log[3].Message);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a JSON HTTP client.
 /// </summary>
 /// <typeparam name="TResult">The type of response.</typeparam>
 /// <param name="callback">An optional callback raised on data received.</param>
 /// <returns>A new JSON HTTP client.</returns>
 public virtual JsonHttpClient <TResult> CreateHttp <TResult>(Action <ReceivedEventArgs <TResult> > callback = null) => CoreResources.Create(callback);
Exemplo n.º 8
0
 /// <summary>
 /// Combines path to root to generate a URI.
 /// </summary>
 /// <param name="query">The optional query data.</param>
 /// <returns>A URI.</returns>
 public Uri GetUri(QueryData query = null) => CoreResources.GetUri(RelativePath, query);
Exemplo n.º 9
0
 internal InvalidScriptAssemblyException(Assembly /*!*/ assembly)
     : base(CoreResources.GetString("invalid_script_assembly", assembly.Location))
 {
 }