Esempio n. 1
0
        public async Task TcpCheckAttribute_IsInvalidPortValue()
        {
            const string host = "127.0.0.1";
            const int    port = 5672;

            var settings = await SettingsProcessor.ProcessAsync <TestTcpCheckModel>($"{{'HostInfo': {{'HostPort': '{host}:{port}'}} }}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Contains("Failed", message);

            settings = await SettingsProcessor.ProcessAsync <TestTcpCheckModel>($"{{'Host': '{host}', 'Port': 'not a port'}}");

            message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.NotNull(message);
            Assert.Equal($"Check of the 'Host' field value [{host}] is failed: Invalid port value in property 'Port'", message);

            settings = await SettingsProcessor.ProcessAsync <TestTcpCheckModel>($"{{'Host': '{host}', 'Port': '{port}'}}");

            message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Contains("Failed", message);

            settings = await SettingsProcessor.ProcessAsync <TestTcpCheckModel>($"{{'Server': '{host}'}}");

            message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Contains("Failed", message);
        }
Esempio n. 2
0
        public async Task OkWithOptionalJson()
        {
            var model = await SettingsProcessor.ProcessAsync <TestOptionAttrModel>(_jsonTest);

            CheckModel(model);
            Assert.Null(model.Test4);
            Assert.Null(model.SubObjectOptional);
        }
Esempio n. 3
0
        public async Task AmqpCheckAttribute_IsInvalidConnectionString()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestAmqpCheckModel>(
                "{'ConnStr': 'amqp://*****:*****@localhost:5672', 'Rabbit': {'ConnString': 'rabbit-registration.lykke-service.svc.cluster.local:5672'}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Contains("Failed", message);
        }
Esempio n. 4
0
        public async Task TcpCheckAttribute_WrongPortProperty()
        {
            var settings = await SettingsProcessor.ProcessAsync <WrongTestTcpCheckModel>("{'Host': '127.0.0.1', 'Port': '5672'}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.NotNull(message);
            Assert.Equal("Check of the 'Host' field value [127.0.0.1] is failed: Property 'ServicePort' not found", message);
        }
Esempio n. 5
0
        public async Task HttpCheckAttribute_IsEmptyField()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestHttpCheckModel>(
                $"{{'Service': {{'ServiceUrl': '{ServiceUrl}'}}, 'Url': '', 'Port':5672, 'Num': 1234}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Contains("Empty setting value", message);
        }
Esempio n. 6
0
        public async Task HttpCheckAttribute_IsOk()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestHttpCheckModel>(
                $"{{'Service': {{'ServiceUrl': '{ServiceUrl}'}}, 'Url': '{ServiceUrl}', 'Port':5672, 'Num': 1234}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Null(message);
        }
Esempio n. 7
0
        public async Task HttpCheckAttribute_IsInvalidUrl()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestHttpCheckModel>(
                $"{{'Service': {{'ServiceUrl': 'not_url_at_all'}}, 'Url': '{ServiceUrl}/', 'Port':5672, 'Num': 1234}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Contains("Failed", message);
        }
Esempio n. 8
0
        public async Task HttpCheckAttribute_IsListOk()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestHttpCheckListModel>(
                $"{{'Services': ['{ServiceUrl}'],'List': ['{ServiceUrl}'],'IList': ['{ServiceUrl}']," +
                $"'RoList': ['{ServiceUrl}'],'RoCollection': ['{ServiceUrl}'],'Enumerable': ['{ServiceUrl}']}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Null(message);
        }
Esempio n. 9
0
        public async Task TcpCheckAttribute_IsInvalidPort()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestTcpCheckModel>(
                "{'HostInfo': {'HostPort': '127.0.0.1:zzz'}, 'Host': '127.0.0.1', 'Port': 5672, 'Server': '127.0.0.1'}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.NotNull(message);
            Assert.Contains("Invalid port", message);
        }
Esempio n. 10
0
        public async Task TcpCheckAttribute_IsDictionaryOk()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestTcpCheckDictionaryModel>("{'Endpoints': {'first': {'HostPort': '127.0.0.1:5672'}}," +
                                                                                              "'IDict': {'first': {'HostPort': '127.0.0.1:5672'}}," +

                                                                                              "'RoDict': {'first': {'HostPort': '127.0.0.1:5672'}}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Null(message);
        }
Esempio n. 11
0
        public async Task HttpCheckAttribute_IsDictionaryOk()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestHttpCheckDictioinaryModel>(
                $"{{'Services': {{'first': {{'ServiceUrl': '{ServiceUrl}'}} }}," +
                $"'IDict': {{'first': {{'ServiceUrl': '{ServiceUrl}'}} }}," +
                $"'RoDict': {{'first': {{'ServiceUrl': '{ServiceUrl}'}} }} }}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Null(message);
        }
Esempio n. 12
0
        public async Task AmqpCheckAttribute_IsDictionaryOk()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestAmqpCheckDictionaryModel>("{'Rabbits': {'first': {'ConnString': 'amqp://*****:*****@localhost:5672'}}," +
                                                                                               "'IDict': {'first': {'ConnString': 'amqp://*****:*****@localhost:5672'}}," +

                                                                                               "'RoDict': {'first': {'ConnString': 'amqp://*****:*****@localhost:5672'}}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Null(message);
        }
Esempio n. 13
0
        public static TestSettings <TValue> FormatJsonString(string value)
        {
            if (null == value)
            {
                return(SettingsProcessor.ProcessAsync <TestSettings <TValue> >("{ 'value': null }").GetAwaiter().GetResult());
            }

            value = value
                    .Replace(@"\", @"\\")
                    .Replace(@"""", @"\\""")
                    .Replace(@"'", @"\\'");
            value = "\"" + value + "\"";
            return(FormatJson(value));
        }
Esempio n. 14
0
        public async Task Test_NegativeNumbers_IsOk()
        {
            string json = "{'Int': -1234, " +
                          "'Double': -10.4, " +
                          "'Float': -10.4, " +
                          "'Decimal': -10.2}";

            var model = await SettingsProcessor.ProcessAsync <TestConvert>(json);

            Assert.Equal(-1234, model.Int);
            Assert.Equal(-10.4, Math.Round(model.Double, 2));
            Assert.Equal(-10.4, Math.Round(model.Float, 2));
            Assert.Equal((decimal) - 10.2, model.Decimal);
        }
Esempio n. 15
0
        public async Task AmqpCheckAttribute_IsListOk()
        {
            var checkList = new List <(string, string)>
            {
                ("Rabbits", "amqp://*****:*****@localhost:5672"),
                ("List", "amqp://*****:*****@localhost:5672"),
                ("IList", "amqp://*****:*****@localhost:5672"),
                ("RoList", "amqp://*****:*****@localhost:5672"),
                ("RoCollection", "amqp://*****:*****@localhost:5672"),
                ("Enumerable", "amqp://*****:*****@localhost:5672")
            };

            foreach (var pair in checkList)
            {
                var settings = await SettingsProcessor.ProcessAsync <TestAmqpCheckListModel>($"{{'{pair.Item1}': ['{pair.Item2}'] }}");

                string message = await SettingsProcessor.CheckDependenciesAsync(settings);

                Assert.Contains("Failed", message);
            }
        }
Esempio n. 16
0
        public async Task TcpCheckAttribute_IsArrayOk()
        {
            var checkList = new List <(string, string)>
            {
                ("Endpoints", "127.0.0.1:5672"),
                ("List", "127.0.0.1:5672"),
                ("IList", "127.0.0.1:5672"),
                ("RoList", "127.0.0.1:5672"),
                ("RoCollection", "127.0.0.1:5672"),
                ("Enumerable", "127.0.0.1:5672")
            };

            foreach (var pair in checkList)
            {
                var settings = await SettingsProcessor.ProcessAsync <TestTcpCheckArrayModel>($"{{'{pair.Item1}': [{{'HostPort': '{pair.Item2}'}}] }}");

                string message = await SettingsProcessor.CheckDependenciesAsync(settings);

                Assert.Contains("Failed", message);
            }
        }
Esempio n. 17
0
        public async Task GetSetting()
        {
            var settingsServiceMock = new Mock <ISettingsService>();

            settingsServiceMock.Setup(x => x.GetSetting(It.IsAny <string>())).Returns("value").Verifiable();

            var processor = new SettingsProcessor(settingsServiceMock.Object);

            var result = await processor.ProcessAsync("getsetting", "key");

            settingsServiceMock.Verify(x => x.GetSetting(It.Is <string>(key => key == "key")));

            Assert.NotNull(result);
            Assert.True(result.IsSuccess);

            var dto = result.Content as SettingValueDto;

            Assert.NotNull(dto);
            Assert.Equal("key", dto.Key);
            Assert.Equal("value", dto.Value);
        }
Esempio n. 18
0
 public static TestSettings <TValue> FormatJson(string value)
 {
     return(null == value
         ? SettingsProcessor.ProcessAsync <TestSettings <TValue> >("{ 'value': null }").GetAwaiter().GetResult()
         : SettingsProcessor.ProcessAsync <TestSettings <TValue> >("{ 'value': " + value + " }").GetAwaiter().GetResult());
 }
Esempio n. 19
0
 public async Task EmptyJson()
 {
     await Assert.ThrowsAsync <JsonStringEmptyException>(async() => await SettingsProcessor.ProcessAsync <TestModel>(string.Empty));
 }
Esempio n. 20
0
        public async Task SubFieldArrayMissJson()
        {
            var ex = await Assert.ThrowsAsync <RequiredFieldEmptyException>(async() => await SettingsProcessor.ProcessAsync <TestModel>(_jsonTest.Replace(@"""test2"":24,", String.Empty)));

            Assert.Equal("SubArray.2.Test2", ex.FieldName);
        }
Esempio n. 21
0
        public async Task OkJson()
        {
            var model = await SettingsProcessor.ProcessAsync <TestModel>(_jsonTest);

            CheckModel(model);
        }
Esempio n. 22
0
 public async Task IncorrectJson()
 {
     await Assert.ThrowsAsync <IncorrectJsonFormatException>(async() => await SettingsProcessor.ProcessAsync <TestModel>(_jsonTest.Substring(10)));
 }