예제 #1
0
        public PlaidClientTest()
        {
            VerifierSettings.DisableClipboard();
            VerifierSettings.ScrubLinesContaining(StringComparison.OrdinalIgnoreCase, "RequestId");
            VerifierSettings.UseStrictJson();

            var configuration = new ConfigurationBuilder()
                                .AddEnvironmentVariables()
                                .AddJsonFile("secrets.json", optional: true)
                                .Build();
            var plaidOptions = configuration.GetSection(PlaidOptions.SectionKey).Get <PlaidOptions>();

            if (string.IsNullOrWhiteSpace(plaidOptions?.ClientId))
            {
                throw new InvalidOperationException("Please provide ClientId configuration via PLAID__CLIENTID environment variable or Plaid:ClientId in secrets.json.");
            }
            if (string.IsNullOrWhiteSpace(plaidOptions?.Secret))
            {
                throw new InvalidOperationException("Please provide Secret configuration via PLAID__SECRET or Plaid:Secret in secrets.json.");
            }
            if (string.IsNullOrWhiteSpace(plaidOptions?.DefaultAccessToken))
            {
                throw new InvalidOperationException("Please provide DefaultAccessToken configuration via PLAID__DEFAULTACCESSTOKEN or Plaid:DefaultAccessToken in secrets.json.");
            }

            PlaidClient = new PlaidClient(
                MOptions.Create(plaidOptions));
        }
예제 #2
0
        public void SeperatePublishSubscribeTests()
        {
            var opts1 = Options.Create(new NatsOptions
            {
                Servers  = new[] { "nats://localhost:4222" },
                Exchange = "testEx",
                Client   = "tClient1"
            });

            var opts2 = Options.Create(new NatsOptions
            {
                Servers  = new[] { "nats://localhost:4222" },
                Exchange = "testEx",
                Client   = "tClient2"
            });

            var pConnLogger     = new Logger <NatsPersistentConnection>(new NullLoggerFactory());
            var pConn           = new NatsPersistentConnection(new ConnectionFactory(), opts1, pConnLogger);
            var eventProcessor1 = Substitute.For <IEventProcessor>();
            var eventProcessor2 = Substitute.For <IEventProcessor>();
            var busLogger       = new Logger <NatsEventBus>(new NullLoggerFactory());
            var bus1            = new NatsEventBus(opts1, pConn, eventProcessor1, new EventBusSubscriptionsManager(), busLogger);
            var bus2            = new NatsEventBus(opts2, pConn, eventProcessor2, new EventBusSubscriptionsManager(), busLogger);

            bus2.Subscribe <TestEvent, TestEventHandler>();
            bus1.Initialize();
            bus2.Initialize();
            bus1.Publish(new TestEvent());
            Thread.Sleep(1000);
            eventProcessor2.Received().ProcessEvent(typeof(TestEvent).Name, Arg.Any <byte[]>());
            eventProcessor1.DidNotReceive().ProcessEvent(typeof(TestEvent).Name, Arg.Any <byte[]>());
        }
예제 #3
0
        public static void CreateClient_Creates_Client_From_Service_Provider_With_Locations()
        {
            // Arrange
            var options = new UserStoreOptions()
            {
                ServiceUri      = new Uri("https://cosmosdb.azure.local"),
                AccessKey       = "bpfYUKmfV0arChaIPI3hU3+bn3w=",
                DatabaseName    = "my-database",
                CollectionName  = "my-collection",
                CurrentLocation = "UK South",
            };

            var services = new ServiceCollection()
                           .AddHttpClient()
                           .AddSingleton(Options.Create(new JsonOptions()))
                           .AddSingleton(options);

            using var serviceProvider = services.BuildServiceProvider();

            // Act
            using CosmosClient actual = DocumentHelpers.CreateClient(serviceProvider);

            // Assert
            actual.ShouldNotBeNull();
        }
예제 #4
0
        public static QueryParser <T> GetQueryParser <T>(RddOptions rddOptions = null)
            where T : class
        {
            var opt = Options.Create(rddOptions ?? new RddOptions());

            return(new QueryParser <T>(new WebFilterConverter <T>(), new PagingParser(opt), new FilterParser(new StringConverter(), new ExpressionParser()), new FieldsParser(new ExpressionParser()), new OrderByParser(new ExpressionParser()), new TypeFilterParser <T>()));
        }
예제 #5
0
        public SparkPostClientTests()
        {
            var options = new SparkPostOptions
            {
                ApiKey = Environment.GetEnvironmentVariable("SPARKPOST_APIKEY")
            };

            this.Client        = new SparkPostClient(Options.Create(options));
            this.SendingDomain = Environment.GetEnvironmentVariable("SPARKPOST_SENDINGDOMAIN");
        }
        public EnforceHttpsMiddlewareTests()
        {
            next = context =>
            {
                isNextCalled = true;

                return(TaskHelper.Done);
            };

            sut = new EnforceHttpsMiddleware(Options.Create(options));
        }
        public async Task Should_not_redirect_if_not_required()
        {
            var httpContext = CreateHttpContext("http");

            var sut = new EnforceHttpsMiddleware(next, Options.Create(new MyUrlsOptions {
                EnforceHTTPS = false
            }));

            await sut.Invoke(httpContext);

            Assert.True(isNextCalled);
            Assert.Null((string)httpContext.Response.Headers["Location"]);
        }
        public async Task Should_make_permanent_redirect_if_redirect_is_required()
        {
            var httpContext = CreateHttpContext();

            var sut = new EnforceHttpsMiddleware(next, Options.Create(new MyUrlsOptions {
                EnforceHTTPS = true
            }));

            await sut.Invoke(httpContext);

            Assert.False(isNextCalled);
            Assert.Equal("https://squidex.local/path?query=1", httpContext.Response.Headers["Location"]);
        }
예제 #9
0
 public DistributedCache(
     ICacheSerializer serializer,
     ICacheDeserializer deserializer,
     ISystemClock clock,
     Func <DateTimeOffset> timestamps)
 {
     _serializer   = serializer;
     _deserializer = deserializer;
     _cache        = new MemoryDistributedCache(SysOptions.Create(new MemoryDistributedCacheOptions
     {
         CompactionPercentage    = 0.05,
         ExpirationScanFrequency = TimeSpan.FromMinutes(1.0),
         SizeLimit = null,
         Clock     = clock ?? new DelegatedSystemClock(timestamps)
     }));
 }
예제 #10
0
        public void SamePublishSubscribeTests()
        {
            var opts = Options.Create(new NatsOptions
            {
                Servers  = new [] { "nats://localhost:4222" },
                Exchange = "testEx",
                Client   = "tClient"
            });
            var pConnLogger    = new Logger <NatsPersistentConnection>(new NullLoggerFactory());
            var pConn          = new NatsPersistentConnection(new ConnectionFactory(), opts, pConnLogger);
            var eventProcessor = Substitute.For <IEventProcessor>();
            var busLogger      = new Logger <NatsEventBus>(new NullLoggerFactory());
            var bus            = new NatsEventBus(opts, pConn, eventProcessor, new EventBusSubscriptionsManager(), busLogger);

            bus.Initialize();
            bus.Publish(new TestEvent());
            Thread.Sleep(1000);
            eventProcessor.Received().ProcessEvent(typeof(TestEvent).Name, Arg.Any <byte[]>());
        }
예제 #11
0
 /// <summary>
 /// 尝试添加配置项
 /// </summary>
 /// <typeparam name="TOptions"></typeparam>
 /// <param name="services"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IServiceCollection TryAddOptions <TOptions>(this IServiceCollection services, TOptions options) where TOptions : class, new()
 {
     services.TryAddSingleton(MSEXOptions.Create(options));
     return(services);
 }