コード例 #1
0
        public async Task Should_log_writes()
        {
            var loggerFactory = new ListLoggerFactory();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <ILoggerFactory>(loggerFactory);

            var scopedServices = InMemoryTestHelpers.Instance.CreateContextServices(serviceCollection, CreateModel());

            var customer = new Customer
            {
                Id   = 42,
                Name = "Unikorn"
            };
            var entityEntry = scopedServices.GetRequiredService <IStateManager>().GetOrCreateEntry(customer);

            entityEntry.SetEntityState(EntityState.Added);

            var inMemoryDatabase = scopedServices.GetRequiredService <IInMemoryDatabase>();

            await inMemoryDatabase.SaveChangesAsync(new[] { entityEntry });

            var(Level, _, Message, _, _) = loggerFactory.Log.Single(t => t.Id.Id == InMemoryEventId.ChangesSaved.Id);

            Assert.Equal(LogLevel.Information, Level);
            Assert.Equal(InMemoryResources.LogSavedChanges(new TestLogger <InMemoryLoggingDefinitions>()).GenerateMessage(1), Message);
        }
コード例 #2
0
 private static void AssertThrows(Action action)
 => Assert.Equal(
     CoreStrings.WarningAsErrorTemplate(
         InMemoryEventId.TransactionIgnoredWarning,
         InMemoryResources.LogTransactionsNotSupported(new TestLogger <InMemoryLoggingDefinitions>()).GenerateMessage(),
         "InMemoryEventId.TransactionIgnoredWarning"),
     Assert.Throws <InvalidOperationException>(action).Message);
コード例 #3
0
ファイル: UserService.cs プロジェクト: roblapp/in-memory-oidc
        static UserService()
        {
            var users = InMemoryResources.GetUsers();

            foreach (var user in users)
            {
                Database.Add(user);
            }
        }
コード例 #4
0
        public static IIdentityServerBuilder Configure(this IIdentityServerBuilder identityServerBuilder)
        {
            identityServerBuilder
            .AddDeveloperSigningCredential()
            //.AddProfileService<>(),
            .AddInMemoryIdentityResources(InMemoryResources.GetIdentityResources())
            .AddInMemoryApiResources(InMemoryResources.GetApiResources())
            .AddInMemoryClients(InMemoryResources.GetClients())
            .AddExtensionGrantValidator <RFC7523GrantValidator>();

            return(identityServerBuilder);
        }
コード例 #5
0
ファイル: WarningsTest.cs プロジェクト: belav/csharpier-repos
        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);
        }
コード例 #6
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);
        }
    }
コード例 #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var connectionStr = Configuration.GetConnectionString("DefaultConnection");

            var migrationAssembly = this.GetType().GetTypeInfo().Assembly.GetName().Name;

            services.AddDbContext <AutenticacaoDbContext>(options => { options.UseSqlServer(connectionStr, sqlOptions => sqlOptions.MigrationsAssembly(migrationAssembly)); });

            services
            .AddIdentityServer()
            .AddOperationalStore(options => { options.ConfigureDbContext = x => x.UseSqlServer(connectionStr, sqlOptions => sqlOptions.MigrationsAssembly(migrationAssembly)); })
            //  .AddConfigurationStore(options => { options.ConfigureDbContext = x => x.UseSqlServer(connectionStr, sqlOptions => sqlOptions.MigrationsAssembly(migrationAssembly)); })
            .AddProfileService <ContaProfileService>()
            .AddResourceOwnerValidator <ContaPasswordValidator>()
            .AddInMemoryApiResources(InMemoryResources.GetAPIResources())
            .AddInMemoryIdentityResources(InMemoryResources.GetIdentityResources())
            .AddInMemoryClients(InMemoryClients.GetClients())
            .AddDeveloperSigningCredential();
        }
コード例 #8
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 ChangesSaved(
        this IDiagnosticsLogger <DbLoggerCategory.Update> diagnostics,
        IEnumerable <IUpdateEntry> entries,
        int rowsAffected)
    {
        var definition = InMemoryResources.LogSavedChanges(diagnostics);

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

        if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
        {
            var eventData = new SaveChangesEventData(
                definition,
                ChangesSaved,
                entries,
                rowsAffected);

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