public void Should_throw_by_default_when_transaction_enlisted()
        {
            var optionsBuilder
                = new DbContextOptionsBuilder()
                  .EnableServiceProviderCaching(false)
                  .UseInMemoryDatabase(Guid.NewGuid().ToString());

            using (var context = new DbContext(optionsBuilder.Options))
            {
                Assert.Equal(
                    CoreStrings.WarningAsErrorTemplate(
                        InMemoryEventId.TransactionIgnoredWarning,
                        InMemoryResources.LogTransactionsNotSupported(new TestLogger <InMemoryLoggingDefinitions>()).GenerateMessage(),
                        "InMemoryEventId.TransactionIgnoredWarning"),
                    Assert.Throws <InvalidOperationException>(
                        () => context.Database.EnlistTransaction(new CommittableTransaction())).Message);
            }
        }
Example #2
0
    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public static void TransactionIgnoredWarning(
        this IDiagnosticsLogger <DbLoggerCategory.Database.Transaction> diagnostics)
    {
        var definition = InMemoryResources.LogTransactionsNotSupported(diagnostics);

        if (diagnostics.ShouldLog(definition))
        {
            definition.Log(diagnostics);
        }

        if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
        {
            var eventData = new EventData(
                definition,
                (d, _) => ((EventDefinition)d).GenerateMessage());

            diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
        }
    }