Exemplo n.º 1
0
        public GuidesMongoDbPersistenceTest()
        {
            var mongoEnabled     = Environment.GetEnvironmentVariable("MONGO_ENABLED") ?? "true";
            var mongoDb          = Environment.GetEnvironmentVariable("MONGO_DB") ?? "test";
            var mongoCollection  = Environment.GetEnvironmentVariable("MONGO_COLLECTION") ?? "guides";
            var mongoServiceHost = Environment.GetEnvironmentVariable("MONGO_SERVICE_HOST") ?? "localhost";
            var mongoServicePort = Environment.GetEnvironmentVariable("MONGO_SERVICE_PORT") ?? "27017";
            var mongoServiceUri  = Environment.GetEnvironmentVariable("MONGO_SERVICE_URI");

            _enabled = BooleanConverter.ToBoolean(mongoEnabled);

            if (_enabled)
            {
                var config = ConfigParams.FromTuples(
                    "collection", mongoCollection,
                    "connection.database", mongoDb,
                    "connection.host", mongoServiceHost,
                    "connection.port", mongoServicePort,
                    "connection.uri", mongoServiceUri
                    );

                _persistence = new GuidesMongoDbPersistence();
                _persistence.Configure(config);
                _persistence.OpenAsync(null).Wait();
                _persistence.ClearAsync(null).Wait();

                _fixture = new GuidesPersistenceFixture(_persistence);
            }
        }
Exemplo n.º 2
0
        public void TestLookup()
        {
            var credentialResolver = new CredentialResolver();
            var credential         = credentialResolver.LookupAsync("correlationId").Result;

            Assert.Null(credential);

            var restConfigWithoutStoreKey = ConfigParams.FromTuples(
                "credential.username", "Negrienko",
                "credential.password", "qwerty",
                "credential.access_key", "key"
                );

            credentialResolver = new CredentialResolver(restConfigWithoutStoreKey);
            credential         = credentialResolver.LookupAsync("correlationId").Result;

            Assert.Equal(credential.Get("username"), "Negrienko");
            Assert.Equal(credential.Get("password"), "qwerty");
            Assert.Equal(credential.Get("access_key"), "key");
            Assert.Null(credential.Get("store_key"));

            credentialResolver = new CredentialResolver(RestConfig);
            credentialResolver.SetReferences(new References());
            try
            {
                credential = credentialResolver.LookupAsync("correlationId").Result;
            }
            catch (Exception ex)
            {
                //Assert.IsType<ReferenceException>(ex);
            }
        }
Exemplo n.º 3
0
        public ElasticSearchLoggerTest()
        {
            var ELASTICSEARCH_ENABLED      = Environment.GetEnvironmentVariable("ELASTICSEARCH_ENABLED") ?? "true";
            var ELASTICSEARCH_SERVICE_HOST = Environment.GetEnvironmentVariable("ELASTICSEARCH_SERVICE_HOST") ?? "localhost";
            var ELASTICSEARCH_SERVICE_PORT = Environment.GetEnvironmentVariable("ELASTICSEARCH_SERVICE_PORT") ?? "9200";

            _enabled = BooleanConverter.ToBoolean(ELASTICSEARCH_ENABLED);

            if (_enabled)
            {
                _logger = new TestElasticSearchLogger();
                _logger.Configure(ConfigParams.FromTuples(
                                      "level", "trace",
                                      "source", "test",
                                      "index", "log",
                                      "date_format", _dateFormat,
                                      "daily", true,
                                      "connection.host", ELASTICSEARCH_SERVICE_HOST,
                                      "connection.port", ELASTICSEARCH_SERVICE_PORT
                                      ));

                _fixture   = new LoggerFixture(_logger);
                _esFixture = new ElasticSearchLoggerFixture(_logger);

                _logger.OpenAsync(null).Wait();
                // _logger.OpenAsync(null).Wait();
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            try
            {
                var correlationId = "123";
                var config        = ConfigParams.FromTuples(
                    "connection.type", "http",
                    "connection.host", "localhost",
                    "connection.port", 8080
                    );
                var client = new StatisticsHttpClientV1();

                client.Configure(config);
                client.OpenAsync(correlationId);

                client.IncrementCounterAsync(null, "test", "value1", new DateTime(), "UTC", 1);
                //var set = client.ReadOneCounterAsync(null, "test", "value1", StatCounterTypeV1.Total, new DateTime(), new DateTime(), null);
                Console.WriteLine("Counter added and read");
                var page = client.GetCountersAsync(null, null, new PagingParams());
                Console.WriteLine("Page: " + page.Result);

                Console.WriteLine("Press ENTER to exit...");
                Console.ReadLine();

                client.CloseAsync(string.Empty);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        public override async Task OpenAsync(string correlationId, List <ConnectionParams> connections, CredentialParams credential)
        {
            try
            {
                var connection = connections?.FirstOrDefault();
                if (connection == null)
                {
                    throw new ArgumentNullException(nameof(connections));
                }

                _topicName        = connection.GetAsNullableString("topic") ?? Name;
                _tempSubscriber   = connection.Get("subscription") == null || connection.Get("Subscription") == null;
                _subscriptionName = connection.GetAsNullableString("subscription") ?? connection.Get("Subscription") ?? IdGenerator.NextLong(); // "AllMessages";

                _connectionString = ConfigParams.FromTuples(
                    "Endpoint", connection.GetAsNullableString("uri") ?? connection.GetAsNullableString("Endpoint"),
                    "SharedAccessKeyName", credential.AccessId ?? credential.GetAsNullableString("shared_access_key_name") ?? credential.GetAsNullableString("SharedAccessKeyName"),
                    "SharedAccessKey", credential.AccessKey ?? credential.GetAsNullableString("shared_access_key") ?? credential.GetAsNullableString("SharedAccessKey")
                    ).ToString();

                _namespaceManager = NamespaceManager.CreateFromConnectionString(_connectionString);
                _messageReceiver  = new MessageReceiver(_connectionString, EntityNameHelper.FormatSubscriptionPath(_topicName, _subscriptionName));
            }
            catch (Exception ex)
            {
                _namespaceManager = null;

                _logger.Error(correlationId, ex, $"Failed to open message topic '{Name}'.");
            }

            await Task.CompletedTask;
        }
Exemplo n.º 6
0
        public NatsMessageQueueTest()
        {
            var NATS_SERVICE_URI  = Environment.GetEnvironmentVariable("NATS_SERVICE_URI");
            var NATS_SERVICE_HOST = Environment.GetEnvironmentVariable("NATS_SERVICE_HOST") ?? "localhost";
            var NATS_SERVICE_PORT = Environment.GetEnvironmentVariable("NATS_SERVICE_PORT") ?? "4222";
            var NATS_QUEUE        = Environment.GetEnvironmentVariable("NATS_QUEUE") ?? "test";
            var NATS_USER         = Environment.GetEnvironmentVariable("NATS_USER"); // ?? "user";
            var NATS_PASS         = Environment.GetEnvironmentVariable("NATS_PASS"); // ?? "pass123";
            var NATS_TOKEN        = Environment.GetEnvironmentVariable("NATS_TOKEN");

            _enabled = !string.IsNullOrEmpty(NATS_SERVICE_URI) || !string.IsNullOrEmpty(NATS_SERVICE_HOST);
            if (!_enabled)
            {
                return;
            }

            _queue = new NatsMessageQueue();
            _queue.Configure(ConfigParams.FromTuples(
                                 "queue", NATS_QUEUE,
                                 "connection.protocol", "nats",
                                 "connection.uri", NATS_SERVICE_URI,
                                 "connection.host", NATS_SERVICE_HOST,
                                 "connection.port", NATS_SERVICE_PORT,
                                 "credential.username", NATS_USER,
                                 "credential.password", NATS_PASS,
                                 "credential.token", NATS_TOKEN,
                                 "options.autosubscribe", true
                                 ));

            _queue.OpenAsync(null).Wait();
            _queue.ClearAsync(null).Wait();

            _fixture = new MessageQueueFixture(_queue);
        }
Exemplo n.º 7
0
        public DummyGrpcServiceTest()
        {
            correlationId = IdGenerator.NextLong();

            var config = ConfigParams.FromTuples(
                "connection.protocol", "http",
                "connection.host", "localhost",
                "connection.port", 3000
                );

            client = new DummyGrpcClient();
            client.Configure(config);

            service = new DummyGrpcService();
            service.Configure(config);

            var references = References.FromTuples(
                new Descriptor("pip-services3-dummies", "controller", "default", "default", "1.0"), new DummyController()
                );

            service.SetReferences(references);
            service.OpenAsync(null).Wait();

            client.OpenAsync(null).Wait();
        }
Exemplo n.º 8
0
        public DummyHttpEndpointTest()
        {
            _ctrl      = new DummyController();
            _serviceV1 = new DummyCommandableHttpService();
            _serviceV2 = new DummyCommandableHttpService();

            _httpEndpoint = new HttpEndpoint();

            var references = References.FromTuples(
                new Descriptor("pip-services3-dummies", "controller", "default", "default", "1.0"), _ctrl,
                new Descriptor("pip-services3", "endpoint", "http", "default", "1.0"), _httpEndpoint
                );

            _serviceV1.Configure(ConfigParams.FromTuples(
                                     "base_route", "/api/v1/dummy"
                                     ));

            _serviceV2.Configure(ConfigParams.FromTuples(
                                     "base_route", "/api/v2/dummy"
                                     ));

            _httpEndpoint.Configure(RestConfig);

            _serviceV1.SetReferences(references);
            _serviceV2.SetReferences(references);

            _httpEndpoint.OpenAsync(null).Wait();
        }
        public PrometheusMetricsServiceTest()
        {
            var config = ConfigParams.FromTuples(
                "connection.protocol", "http",
                "connection.host", "localhost",
                "connection.port", "3000"
                );

            _service = new PrometheusMetricsService();
            _service.Configure(config);

            var contextInfo = new ContextInfo();

            contextInfo.Name        = "Test";
            contextInfo.Description = "This is a test container";

            _counters = new PrometheusCounters();

            var references = References.FromTuples(
                new Descriptor("pip-services3", "context-info", "default", "default", "1.0"), contextInfo,
                new Descriptor("pip-services3", "counters", "prometheus", "default", "1.0"), _counters,
                new Descriptor("pip-services3", "metrics-service", "prometheus", "default", "1.0"), _service
                );

            _service.SetReferences(references);


            _counters.OpenAsync(null).Wait();
            _service.OpenAsync(null).Wait();

            Task.Delay(500).Wait();
        }
        public CloudWatchLoggerTest()
        {
            var AWS_ENABLED    = Environment.GetEnvironmentVariable("AWS_ENABLED") ?? "true";
            var AWS_REGION     = Environment.GetEnvironmentVariable("AWS_REGION") ?? "us-east-1";
            var AWS_ACCOUNT    = Environment.GetEnvironmentVariable("AWS_ACCOUNT");
            var AWS_ACCESS_ID  = Environment.GetEnvironmentVariable("AWS_ACCESS_ID") ?? "AKIAI2B3PGHEAAK4BPUQ";
            var AWS_ACCESS_KEY = Environment.GetEnvironmentVariable("AWS_ACCESS_KEY") ?? "zQZGX0vGL6OD936fCcP1v6YmpiSdW28oUcezAnb7";

            _enabled = BooleanConverter.ToBoolean(AWS_ENABLED);

            if (_enabled)
            {
                _logger = new CloudWatchLogger();
                _logger.Configure(ConfigParams.FromTuples(
                                      "group", "TestGroup",
                                      "stream", "TestStream",
                                      "connection.region", AWS_REGION,
                                      "connection.account", AWS_ACCOUNT,
                                      "credential.access_id", AWS_ACCESS_ID,
                                      "credential.access_key", AWS_ACCESS_KEY
                                      ));

                _fixture = new LoggerFixture(_logger);

                try
                {
                    _logger.OpenAsync(null).Wait();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw ex;
                }
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            try
            {
                var correlationId = "123";
                var config        = ConfigParams.FromTuples(
                    "connection.type", "http",
                    "connection.host", "localhost",
                    "connection.port", 8080
                    );
                var client = new PerfMonHttpClientV1();
                client.Configure(config);
                CounterV1 counter1 = new CounterV1("counter1", "source1", CounterTypeV1.Statistics, 5, 2, 2, 5, 3.5);
                CounterV1 counter2 = new CounterV1("counter2", "source2", CounterTypeV1.Statistics, 5, 2, 2, 5, 3.5);
                client.OpenAsync(correlationId);
                //var counter = client.WriteCounterAsync(correlationId, counter1);
                client.WriteCountersAsync(null, new CounterV1[] { counter1, counter2 });
                var page = client.ReadCountersAsync(null, FilterParams.FromTuples("name", "counter1"), null);
                Console.WriteLine("Read counters: ");

                Console.WriteLine("Press ENTER to exit...");
                Console.ReadLine();

                client.CloseAsync(string.Empty);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 12
0
        public StatusRestServiceTest()
        {
            var config = ConfigParams.FromTuples(
                "connection.protocol", "http",
                "connection.host", "localhost",
                "connection.port", "3001"
                );

            _service = new StatusRestService();
            _service.Configure(config);

            var contextInfo = new ContextInfo();

            contextInfo.Name        = "Test";
            contextInfo.Description = "This is a test container";

            var references = References.FromTuples(
                new Descriptor("pip-services3", "context-info", "default", "default", "1.0"), contextInfo,
                new Descriptor("pip-services3", "status-service", "http", "default", "1.0"), _service
                );

            _service.SetReferences(references);

            _service.OpenAsync(null).Wait();
        }
        public PrometheusCountersTest()
        {
            var PUSHGATEWAY_ENABLED      = Environment.GetEnvironmentVariable("PUSHGATEWAY_ENABLED") ?? "true";
            var PUSHGATEWAY_SERVICE_HOST = Environment.GetEnvironmentVariable("PUSHGATEWAY_SERVICE_HOST") ?? "localhost";
            var PUSHGATEWAY_SERVICE_PORT = Environment.GetEnvironmentVariable("PUSHGATEWAY_SERVICE_PORT") ?? "9091";

            _enabled = BooleanConverter.ToBoolean(PUSHGATEWAY_ENABLED);
            if (_enabled)
            {
                _counters = new PrometheusCounters();
                _counters.Configure(ConfigParams.FromTuples(
                                        "interval", "5000",
                                        "connection.host", PUSHGATEWAY_SERVICE_HOST,
                                        "connection.port", PUSHGATEWAY_SERVICE_PORT
                                        ));

                var contextInfo = new ContextInfo();
                contextInfo.Name        = "Test";
                contextInfo.Description = "This is a test container";

                var references = References.FromTuples(
                    new Descriptor("pip-services", "context-info", "default", "default", "1.0"), contextInfo,
                    new Descriptor("pip-services", "counters", "prometheus", "default", "1.0"), _counters
                    );
                _counters.SetReferences(references);

                _fixture = new CountersFixture(_counters);

                _counters.OpenAsync(null).Wait();
            }
        }
Exemplo n.º 14
0
        public void TestConfigSections()
        {
            var config = ConfigParams.FromTuples(
                "Section1.Key1", "Value1",
                "Section1.Key2", "Value2",
                "Section1.Key3", "Value3"
                );

            Assert.Equal(3, config.Count);
            Assert.Equal("Value1", config.Get("Section1.Key1"));
            Assert.Equal("Value2", config.Get("Section1.Key2"));
            Assert.Equal("Value3", config.Get("Section1.Key3"));
            Assert.Null(config.Get("Section1.Key4"));

            var section2 = ConfigParams.FromTuples(
                "Key1", "ValueA",
                "Key2", "ValueB"
                );

            config.AddSection("Section2", section2);
            Assert.Equal(5, config.Count);
            Assert.Equal("ValueA", config.Get("Section2.Key1"));
            Assert.Equal("ValueB", config.Get("Section2.Key2"));

            var section1 = config.GetSection("Section1");

            Assert.Equal(3, section1.Count);
            Assert.Equal("Value1", section1.Get("Key1"));
            Assert.Equal("Value2", section1.Get("Key2"));
            Assert.Equal("Value3", section1.Get("Key3"));
        }
Exemplo n.º 15
0
        public void TestEmptyName()
        {
            var config = ConfigParams.FromTuples();
            var name   = NameResolver.Resolve(config);

            Assert.Null(name);
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            try
            {
                var correlationId = "123";
                var config        = ConfigParams.FromTuples(
                    "connection.type", "http",
                    "connection.host", "localhost",
                    "connection.port", 8080
                    );
                var client = new SettingsHttpClientV1();
                client.Configure(config);
                client.OpenAsync(correlationId);
                var parameters = client.SetSectionAsync(null, "test.1", ConfigParams.FromTuples(
                                                            "key1", "value11",
                                                            "key2", "value12"
                                                            ));
                var page = client.GetSectionsAsync(null, null, null);
                Console.WriteLine("Get sections: ");

                Console.WriteLine("Press ENTER to exit...");
                Console.ReadLine();

                client.CloseAsync(string.Empty);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        public async Task TestClusterConnectionWithAuthAsync()
        {
            var resolver = new NatsConnectionResolver();

            resolver.Configure(ConfigParams.FromTuples(
                                   "connections.0.protocol", "nats",
                                   "connections.0.host", "server1",
                                   "connections.0.port", 4222,
                                   "connections.1.protocol", "nats",
                                   "connections.1.host", "server2",
                                   "connections.1.port", 4222,
                                   "connections.2.protocol", "nats",
                                   "connections.2.host", "server3",
                                   "connections.2.port", 4222,
                                   "credential.username", "test",
                                   "credential.password", "pass123",
                                   "credential.token", "ABC"
                                   ));

            var connection = await resolver.ResolveAsync(null);

            Assert.Equal("nats://server1:4222,nats://server2:4222,nats://server3:4222", connection.GetAsString("uri"));
            Assert.Equal("test", connection.GetAsString("username"));
            Assert.Equal("pass123", connection.GetAsString("password"));
            Assert.Equal("ABC", connection.GetAsString("token"));
        }
        public RabbitMQMessageQueueTest()
        {
            var RABBITMQ_ENABLED  = Environment.GetEnvironmentVariable("RABBITMQ_ENABLED") ?? "true";
            var RABBITMQ_URI      = Environment.GetEnvironmentVariable("RABBITMQ_URI");
            var RABBITMQ_HOST     = Environment.GetEnvironmentVariable("RABBITMQ_HOST") ?? "localhost";
            var RABBITMQ_PORT     = Environment.GetEnvironmentVariable("RABBITMQ_PORT") ?? "5672";
            var RABBITMQ_QUEUE    = Environment.GetEnvironmentVariable("RABBITMQ_QUEUE") ?? "test";
            var RABBITMQ_EXCHANGE = Environment.GetEnvironmentVariable("RABBITMQ_EXCHANGE") ?? "test";
            var RABBITMQ_USER     = Environment.GetEnvironmentVariable("RABBITMQ_USER") ?? "user";
            var RABBITMQ_PASS     = Environment.GetEnvironmentVariable("RABBITMQ_PASS") ?? "pass123";

            _enabled = BooleanConverter.ToBoolean(RABBITMQ_ENABLED);

            if (_enabled)
            {
                _queue = new RabbitMQMessageQueue("TestQueue");
                _queue.Configure(ConfigParams.FromTuples(
                                     "exchange", RABBITMQ_EXCHANGE,
                                     "queue", RABBITMQ_QUEUE,
                                     "options.auto_create", true,
                                     "connection.uri", RABBITMQ_URI,
                                     "connection.host", RABBITMQ_HOST,
                                     "connection.port", RABBITMQ_PORT,
                                     "credential.username", RABBITMQ_USER,
                                     "credential.password", RABBITMQ_PASS
                                     ));
                _queue.Interval = 100;

                _queue.OpenAsync(null).Wait();
                _queue.ClearAsync(null).Wait();

                _fixture = new MessageQueueFixture(_queue);
            }
        }
        public async override Task OpenAsync(string correlationId, ConnectionParams connection, CredentialParams credential)
        {
            try
            {
                var connectionString = ConfigParams.FromTuples(
                    "DefaultEndpointsProtocol", connection.Protocol ?? connection.GetAsNullableString("DefaultEndpointsProtocol") ?? "https",
                    "AccountName", credential.AccessId ?? credential.GetAsNullableString("account_name") ?? credential.GetAsNullableString("AccountName"),
                    "AccountKey", credential.AccessKey ?? credential.GetAsNullableString("account_key") ?? credential.GetAsNullableString("AccountKey")
                    ).ToString();

                _logger.Info(null, "Connecting queue {0} to {1}", Name, connectionString);

                var storageAccount = CloudStorageAccount.Parse(connectionString);
                var client         = storageAccount.CreateCloudQueueClient();

                var queueName = connection.Get("queue") ?? Name;
                _queue = client.GetQueueReference(queueName);
                await _queue.CreateIfNotExistsAsync();

                var deadName = connection.Get("dead");
                _deadQueue = deadName != null?client.GetQueueReference(deadName) : null;
            }
            catch (Exception ex)
            {
                _queue = null;
                _logger.Error(correlationId, ex, $"Failed to open queue {Name}.");
            }

            await Task.Delay(0);
        }
Exemplo n.º 20
0
        public override async Task OpenAsync(string correlationId, List <ConnectionParams> connections, CredentialParams credential)
        {
            try
            {
                var connection = connections?.FirstOrDefault();
                if (connection == null)
                {
                    throw new ArgumentNullException(nameof(connections));
                }

                _queueName = connection.GetAsNullableString("queue") ?? Name;

                _connectionString = ConfigParams.FromTuples(
                    "Endpoint", connection.GetAsNullableString("uri") ?? connection.GetAsNullableString("Endpoint"),
                    "SharedAccessKeyName", credential.AccessId ?? credential.GetAsNullableString("SharedAccessKeyName"),
                    "SharedAccessKey", credential.AccessKey ?? credential.GetAsNullableString("SharedAccessKey")
                    ).ToString();

                _logger.Info(null, "Connecting queue {0} to {1}", Name, _connectionString);

                _queueClient      = new QueueClient(_connectionString, _queueName);
                _namespaceManager = NamespaceManager.CreateFromConnectionString(_connectionString);
                _messageReceiver  = new MessageReceiver(_connectionString, _queueName);
            }
            catch (Exception ex)
            {
                _queueClient      = null;
                _namespaceManager = null;
                _messageReceiver  = null;

                _logger.Error(correlationId, ex, $"Failed to open queue '{Name}'.");
            }

            await Task.CompletedTask;
        }
        public SettingsHttpServiceV1Test()
        {
            _persistence = new SettingsMemoryPersistence();
            _controller  = new SettingsController();

            var config = ConfigParams.FromTuples(
                "connection.protocol", "http",
                "connection.host", "localhost",
                "connection.port", "3000"
                );

            _service = new SettingsHttpServiceV1();
            _service.Configure(config);

            var references = References.FromTuples(
                new Descriptor("pip-services-settings", "persistence", "memory", "default", "1.0"), _persistence,
                new Descriptor("pip-services-settings", "controller", "default", "default", "1.0"), _controller,
                new Descriptor("pip-services-settings", "service", "http", "default", "1.0"), _service
                );

            _controller.SetReferences(references);
            _service.SetReferences(references);
            //_service.OpenAsync(null).Wait();

            // Todo: This is defect! Open shall not block the tread
            Task.Run(() => _service.OpenAsync(null));
            Thread.Sleep(1000); // Just let service a sec to be initialized
        }
Exemplo n.º 22
0
        public StarsMongoDbPersistenceTest()
        {
            var MONGO_ENABLED      = Environment.GetEnvironmentVariable("MONGO_ENABLED") ?? "true";
            var MONGO_DB           = Environment.GetEnvironmentVariable("MONGO_DB") ?? "test";
            var MONGO_COLLECTION   = Environment.GetEnvironmentVariable("MONGO_COLLECTION") ?? "stars";
            var MONGO_SERVICE_HOST = Environment.GetEnvironmentVariable("MONGO_SERVICE_HOST") ?? "localhost";
            var MONGO_SERVICE_PORT = Environment.GetEnvironmentVariable("MONGO_SERVICE_PORT") ?? "27017";
            var MONGO_SERVICE_URI  = Environment.GetEnvironmentVariable("MONGO_SERVICE_URI");

            _enabled = BooleanConverter.ToBoolean(MONGO_ENABLED);

            if (_enabled)
            {
                var config = ConfigParams.FromTuples(
                    "collection", MONGO_COLLECTION,
                    "connection.database", MONGO_DB,
                    "connection.host", MONGO_SERVICE_HOST,
                    "connection.port", MONGO_SERVICE_PORT,
                    "connection.uri", MONGO_SERVICE_URI
                    );

                _persistence = new StarsMongoDbPersistence();
                _persistence.Configure(config);
                _persistence.OpenAsync(null).Wait();
                _persistence.ClearAsync(null).Wait();

                _fixture = new StarsPersistenceFixture(_persistence);
            }
        }
        public BlobsAwsClientV1Test()
        {
            //var AWS_ENABLED = Environment.GetEnvironmentVariable("AWS_ENABLED") ?? "true";
            //var AWS_REGION = Environment.GetEnvironmentVariable("AWS_REGION") ?? "us-east-1";
            //var AWS_ACCOUNT = Environment.GetEnvironmentVariable("AWS_ACCOUNT");
            //var AWS_ACCESS_ID = Environment.GetEnvironmentVariable("AWS_ACCESS_ID") ?? "";
            //var AWS_ACCESS_KEY = Environment.GetEnvironmentVariable("AWS_ACCESS_KEY") ?? "";
            //var AWS_BUCKET = Environment.GetEnvironmentVariable("AWS_BUCKET") ?? "";

            //_enabled = BooleanConverter.ToBoolean(AWS_ENABLED);

            if (_enabled)
            {
                var config = ConfigParams.FromTuples(
                    //"connection.region", AWS_REGION,
                    //"connection.account", AWS_ACCOUNT,
                    //"connection.resource", AWS_BUCKET,
                    //"credential.access_id", AWS_ACCESS_ID,
                    //"credential.access_key", AWS_ACCESS_KEY
                    );

                _client = new BlobsAwsClientV1();
                _client.Configure(config);
                _client.OpenAsync(null).Wait();
                _client.ClearAsync(null).Wait();

                _fixture = new BlobsClientV1Fixture(_client);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                var correlationId = "123";
                var config        = ConfigParams.FromTuples(
                    "connection.type", "http",
                    "connection.host", "localhost",
                    "connection.port", 8080
                    );
                var client     = new SmsHttpClientV1();
                var parameters = ConfigParams.FromTuples(
                    "subject", "Test Sms To Address",
                    "text", "This is just a test"
                    );
                client.Configure(config);
                client.OpenAsync(correlationId);
                client.SendMessageAsync(correlationId, new SmsMessageV1()
                {
                    To   = "+15203452335",
                    Text = "{{text}}"
                },
                                        parameters);
                Console.WriteLine("Message send");

                Console.WriteLine("Press ENTER to exit...");
                Console.ReadLine();

                client.CloseAsync(string.Empty);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 25
0
        public PostgresPersistenceTest2()
        {
            postgresUri      = Environment.GetEnvironmentVariable("POSTGRES_URI");
            postgresHost     = Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "localhost";
            postgresPort     = Environment.GetEnvironmentVariable("POSTGRES_PORT") ?? "5432";
            postgresDatabase = Environment.GetEnvironmentVariable("POSTGRES_DB") ?? "test";
            postgresUsername = Environment.GetEnvironmentVariable("POSTGRES_USERNAME") ?? "postgres";
            postgresPassword = Environment.GetEnvironmentVariable("POSTGRES_PASSWORD") ?? "postgres";

            if (postgresUri == null && postgresHost == null)
            {
                return;
            }

            var dbConfig = ConfigParams.FromTuples(
                "connection.uri", postgresUri,
                "connection.host", postgresHost,
                "connection.port", postgresPort,
                "connection.database", postgresDatabase,
                "credential.username", postgresUsername,
                "credential.password", postgresPassword
                );

            persistence = new PostgresDummyPersistence2();
            persistence.Configure(dbConfig);

            fixture = new DummyPersistenceFixture2(persistence);

            persistence.OpenAsync(null).Wait();
            persistence.ClearAsync(null).Wait();
        }
Exemplo n.º 26
0
        public IdentifiableMongoDbPersistenceTest()
        {
            var mongoUri      = Environment.GetEnvironmentVariable("MONGO_URI") ?? "mongodb://localhost:27017/test";
            var mongoHost     = Environment.GetEnvironmentVariable("MONGO_HOST") ?? "localhost";
            var mongoPort     = Environment.GetEnvironmentVariable("MONGO_PORT") ?? "27017";
            var mongoDatabase = Environment.GetEnvironmentVariable("MONGO_DB") ?? "test";

            if (mongoUri == null && mongoHost == null)
            {
                return;
            }

            if (Db == null)
            {
                return;
            }

            Db.Configure(ConfigParams.FromTuples(
                             "connection.uri", mongoUri,
                             "connection.host", mongoHost,
                             "connection.port", mongoPort,
                             "connection.database", mongoDatabase
                             ));

            Db.OpenAsync(null).Wait();
            Db.ClearAsync(null).Wait();

            Fixture = new PersistenceFixture(Db);
        }
        public void TestResolve()
        {
            var connectionParams = _connectionResolver.ResolveAsync("correlationId").Result;

            Assert.Equal(connectionParams.Get("protocol"), "http");
            Assert.Equal(connectionParams.Get("host"), "localhost");
            Assert.Equal(connectionParams.Get("port"), "3000");

            var restConfigDiscovery = ConfigParams.FromTuples(
                "connection.protocol", "http",
                "connection.host", "localhost",
                "connection.port", 3000,
                "connection.discovery_key", "Discovery key value"
                );

            IReferences references = new References();

            _connectionResolver = new ConnectionResolver(restConfigDiscovery, references);
            try
            {
                _connectionResolver.ResolveAsync("correlationId").Wait();
            }
            catch (Exception ex)
            {
                Assert.IsType <ConfigException>(ex.InnerException);
            }
        }
        public MqttConnectionTest()
        {
            var MQTT_SERVICE_URI  = Environment.GetEnvironmentVariable("MQTT_SERVICE_URI");
            var MQTT_SERVICE_HOST = Environment.GetEnvironmentVariable("MQTT_SERVICE_HOST") ?? "localhost";
            var MQTT_SERVICE_PORT = Environment.GetEnvironmentVariable("MQTT_SERVICE_PORT") ?? "1883";
            var MQTT_TOPIC        = Environment.GetEnvironmentVariable("MQTT_TOPIC") ?? "test";
            var MQTT_USER         = Environment.GetEnvironmentVariable("MQTT_USER") ?? "user";
            var MQTT_PASS         = Environment.GetEnvironmentVariable("MQTT_PASS") ?? "pass123";

            _enabled = !string.IsNullOrEmpty(MQTT_SERVICE_URI) || !string.IsNullOrEmpty(MQTT_SERVICE_HOST);
            if (!_enabled)
            {
                return;
            }

            _connection = new MqttConnection();
            _connection.Configure(ConfigParams.FromTuples(
                                      "connection.uri", MQTT_SERVICE_URI,
                                      "connection.protocol", "tcp",
                                      "connection.host", MQTT_SERVICE_HOST,
                                      "connection.port", MQTT_SERVICE_PORT,
                                      "credential.username", MQTT_USER,
                                      "credential.password", MQTT_PASS
                                      ));
        }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            var controller = new DummyController();
            //var service = new DummyCommandableHttpService();
            var service = new DummyRestService();
            var logger  = new ConsoleLogger();

            service.Configure(ConfigParams.FromTuples(
                                  "connection.protocol", "http",
                                  "connection.host", "localhost",
                                  "connection.port", 3000,
                                  "swagger.enable", "true"
                                  ));

            service.SetReferences(References.FromTuples(
                                      new Descriptor("pip-services3-dummies", "controller", "default", "default", "1.0"), controller,
                                      new Descriptor("pip-services3-dummies", "service", "rest", "default", "1.0"), service,
                                      new Descriptor("pip-services3-commons", "logger", "console", "default", "1.0"), logger
                                      ));

            service.OpenAsync(null).Wait();

            Console.WriteLine("Press ENTER to exit...");
            Console.ReadLine();
        }
        public JsonSqlServerDummyPersistenceTest()
        {
            sqlserverUri      = Environment.GetEnvironmentVariable("SQLSERVER_URI");
            sqlserverHost     = Environment.GetEnvironmentVariable("SQLSERVER_SERVICE_HOST") ?? "localhost";
            sqlserverPort     = Environment.GetEnvironmentVariable("SQLSERVER_SERVICE_PORT") ?? "1433";
            sqlserverDatabase = Environment.GetEnvironmentVariable("SQLSERVER_DB") ?? "master";
            sqlserverUsername = Environment.GetEnvironmentVariable("SQLSERVER_USER") ?? "sa";
            sqlserverPassword = Environment.GetEnvironmentVariable("SQLSERVER_PASS") ?? "sqlserver_123";

            if (sqlserverUri == null && sqlserverHost == null)
            {
                return;
            }

            var dbConfig = ConfigParams.FromTuples(
                "connection.uri", sqlserverUri,
                "connection.host", sqlserverHost,
                "connection.port", sqlserverPort,
                "connection.database", sqlserverDatabase,
                "credential.username", sqlserverUsername,
                "credential.password", sqlserverPassword
                );

            persistence = new JsonSqlServerDummyPersistence();
            persistence.Configure(dbConfig);

            fixture = new DummyPersistenceFixture(persistence);

            persistence.OpenAsync(null).Wait();
            persistence.ClearAsync(null).Wait();
        }