public async Task CorrectRequestWithCustomClass() { var expected = new TestClassWithSomeData { Data = "test valaue", BoolData = true, NullableInt = 123, EmptyNullableDecimal = null }; var testApiEndpoint = new TestApiEndpoint(JsonConvert.SerializeObject(expected)); SetRequester(testApiEndpoint); var result = await _requester.GetAsync <TestClassWithSomeData>(new ServiceMethod("a", "b")); Assert.NotNull(result); Assert.Equal("test valaue", result.Data); Assert.True(result.BoolData); Assert.Equal(123, result.NullableInt); Assert.Null(result.EmptyNullableDecimal); var gotCookie = testApiEndpoint.GivenCoockie; Assert.Equal(CookieName, gotCookie.Name); Assert.Equal(CookieValue, gotCookie.Value); Assert.Equal(CookiePath, gotCookie.Path); Assert.Equal(CookieDomain, gotCookie.Domain); }
public async Task CookieWasNotSet() { var testCookieRetriever = new TestAuthDataRetriever(null); var testApiEndpoint = new TestApiEndpoint(JsonConvert.SerializeObject(true)); SetRequester(testApiEndpoint, testCookieRetriever); await _requester.GetAsync <bool>(new ServiceMethod("a", "b")); var gotCookie = testApiEndpoint.GivenCoockie; Assert.Null(gotCookie); }
public async Task CookieWasSetCorrectly() { var testApiEndpoint = new TestApiEndpoint(JsonConvert.SerializeObject(true)); SetRequester(testApiEndpoint); await _requester.GetAsync <bool>(new ServiceMethod("a", "b")); var gotCookie = testApiEndpoint.GivenCoockie; Assert.Equal(CookieName, gotCookie.Name); Assert.Equal(CookieValue, gotCookie.Value); Assert.Equal(CookiePath, gotCookie.Path); Assert.Equal(CookieDomain, gotCookie.Domain); }
public async Task CorrectUploadRequest() { var bytes = new byte[] { 200, 0, 1, 2, 3 }; var endpoint = new TestApiEndpoint(JsonConvert.SerializeObject(true)); SetRequester(endpoint); var files = new Dictionary <string, IEnumerable <Stream> > { { "data", new[] { new MemoryStream(bytes) } } }; var result = await _requester.PostAsync <bool>(new ServiceMethod("a", "b"), null, files); var expected = new List <byte>(bytes).ToArray(); Assert.Equal(expected, await endpoint.GivenData.ReadAsByteArrayAsync()); Assert.True(result); }
public async Task CorrectRequestWithArray_WithPostReq() { var data = new [] { "1", "2", "3", "4" }; var fieldName = "test"; var endpoint = new TestApiEndpoint(JsonConvert.SerializeObject(true)); SetRequester(endpoint); var args = new Dictionary <string, IEnumerable <string> > { { fieldName, data } }; var result = await _requester.PostAsync <bool>(new ServiceMethod("a", "b"), new MethodArgs(args)); var expected = data.Select(s => $"{fieldName}={s}").Aggregate((f, s) => $"{f}&{s}"); // -> test=1&test=2&test=3test=4 var actual = await((FormUrlEncodedContent)endpoint.GivenData).ReadAsStringAsync(); Assert.Equal(expected, actual); Assert.True(result); }
public async Task CorrectRequestWithArray_WithGetReq() { var data = new [] { "1", "2", "3", "4" }; var fieldName = "test"; var methodName = "b"; var endpoint = new TestApiEndpoint(JsonConvert.SerializeObject(true)); SetRequester(endpoint); var args = new Dictionary <string, IEnumerable <string> > { { fieldName, data } }; var result = await _requester.GetAsync <bool>(new ServiceMethod("a", methodName), new MethodArgs(args)); var expected = methodName + "?" + data.Select(s => $"{fieldName}={s}").Aggregate((f, s) => $"{f}&{s}"); // -> test=1&test=2&test=3test=4 var actual = endpoint.Path; Assert.Equal(expected, actual); Assert.True(result); }