Ejemplo n.º 1
0
        private static IMemoryCache AddMemoryCache(ArrangeBuilder arrangeBuilder)
        {
            if (arrangeBuilder.IsTypeCached <IMemoryCache>(out var result))
            {
                return(result);
            }

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddMemoryCache();
            var cache = serviceCollection.BuildServiceProvider().GetService <IMemoryCache>();

            arrangeBuilder.UseContainerBuilder((c) => c.Register(t => cache).As <IMemoryCache>());
            arrangeBuilder.AddTypeToCache(cache);

            return(cache);
        }
Ejemplo n.º 2
0
        private static TContext AddDbContext <TContext>(ArrangeBuilder arrangeBuilder)
            where TContext : DbContext
        {
            if (arrangeBuilder.IsTypeCached <TContext>(out var result))
            {
                return(result);
            }

            var root = new InMemoryDatabaseRoot();
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddDbContext <TContext>(config => config.UseInMemoryDatabase(arrangeBuilder.GetHashCode().ToString(), root)
                                                      .ConfigureWarnings(warnings => warnings.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning)));

            arrangeBuilder.UseContainerBuilder((c) => c.Populate(serviceCollection));

            var db = serviceCollection.BuildServiceProvider().GetService <TContext>();

            arrangeBuilder.AddTypeToCache(db);

            return(db);
        }