示例#1
0
        public async Task ThrowServiceException()
        {
            // arrange
            var exception = default(Exception);

            _endpoint = new HttpEndpoint
            {
                BaseAddress = "http://not-found.de/123",
                Request     = "",
                MethodName  = ""
            };

            // act
            try
            {
                _service = new GenericService(new HttpClient(), _endpoint);
                _service.CallResponded += (o, e) =>
                {
                    Log.Info($"Http responded with code: {e.StatusCode}");
                };
                var result = await _service.CallAsync <object>((s) => JsonIO.FromJsonString <object>(s));
            }
            catch (Exception ex)
            {
                Log.Fatal(ex);
                exception = ex;
            }

            // assert
            Assert.IsNotNull(exception);
        }
示例#2
0
        public void ExportInterfacesAndImportJson()
        {
            // assert
            var input = new InterfaceRepository();

            input.Add(new TestClassA());
            input.Add(new TestClassB());
            input.Add(new TestClassA());
            input.Add(new TestClassA());

            var binder = new TypedSerializationBinder(new List <Type> {
                typeof(TestClassA),
                typeof(TestClassB)
            });

            string json = JsonIO.ToJsonString(input, binder);

            // act
            var output = JsonIO.FromJsonString <InterfaceRepository>(json, binder);

            // Assert
            for (int i = 0; i < output.Count; i++)
            {
                Assert.AreEqual(output[i].Name, input[i].Name, $"Name property at {i} is not equal");
                Assert.AreEqual(output[i].Id, input[i].Id, $"Id property at {i} is not equal");
            }
        }
示例#3
0
        public async Task ServiceCallAsync()
        {
            // arrange
            _endpoint = new HttpEndpoint
            {
                BaseAddress = "https://api.abalin.net",
                Request     = "/get/today?country=de",
                MethodName  = "get"
            };
            _service = new GenericService(new HttpClient(), _endpoint);
            _service.CallResponded += (o, e) =>
            {
                Log.Info($"Http responded with code: {e.StatusCode}");
            };

            // act
            var result = await _service.CallAsync <object>((s) => JsonIO.FromJsonString <object>(s));

            // assert
            Assert.IsNotNull(result);
        }
示例#4
0
 public T As <T>() where T : new()
 {
     return(JsonIO.FromJsonString <T>(_importJson, _setting.Binder));
 }