public async Task GetAllAsync_EmptyData_ExpectedCalls() { ClientResponse <IList <ModelBase> > mockPage1Response = GetListResponse(new List <ModelBase>(), 3); ClientResponse <IList <ModelBase> > mockPage2Response = GetListResponse(new List <ModelBase>(), 3); ClientResponse <IList <ModelBase> > mockPage3Response = GetListResponse(new List <ModelBase>(), 3); IUKFastClient mockClient = Substitute.For <IUKFastClient>(); mockClient.GetPaginatedAsync <ModelBase>("testresource", Arg.Is <ClientRequestParameters>(x => x.Pagination.Page == 2)).Returns(x => { return(Task.Run(() => new Paginated <ModelBase>(mockClient, "testresource", x.ArgAt <ClientRequestParameters>(1), mockPage2Response))); }); mockClient.GetPaginatedAsync <ModelBase>("testresource", Arg.Is <ClientRequestParameters>(x => x.Pagination.Page == 3)).Returns(x => { return(Task.Run(() => new Paginated <ModelBase>(mockClient, "testresource", x.ArgAt <ClientRequestParameters>(1), mockPage3Response))); }); IUKFastClient client = new TestUKFastClient(null); IList <ModelBase> items = await client.GetAllAsync(async (ClientRequestParameters p) => new Paginated <ModelBase>(mockClient, "testresource", p, mockPage1Response), new ClientRequestParameters() { Pagination = new ClientRequestPagination() }); Assert.AreEqual(0, items.Count); }
public void GetDataOrDefault_NullBody_ReturnsNull() { var response = new ClientResponse <ModelBase>() { Body = null }; TestUKFastClient client = new TestUKFastClient(null); var result = client.GetDataOrDefault_Exposed(response); Assert.IsNull(result); }
public async Task DeleteAsync_ExpectedCall() { IConnection connection = NSubstitute.Substitute.For <IConnection>(); connection.DeleteAsync <object>("testresource").Returns(Task.Run(() => new ClientResponse <object>() { StatusCode = 200 })); TestUKFastClient client = new TestUKFastClient(connection); await client.DeleteAsync("testresource"); await connection.Received().DeleteAsync <object>("testresource"); }
public void GetDataOrDefault_PopulatedBody_ReturnsBodyData() { var model = new ModelBase(); var response = new ClientResponse <ModelBase>() { Body = new ClientResponseBody <ModelBase>() { Data = model } }; TestUKFastClient client = new TestUKFastClient(null); var result = client.GetDataOrDefault_Exposed(response); Assert.AreEqual(model, result); }
public async Task GetAsync_ExpectedData() { var mockResponse = GetSingleResponse(new ModelBase(), 3); mockResponse.StatusCode = 200; IConnection connection = NSubstitute.Substitute.For <IConnection>(); connection.GetAsync <ModelBase>("testresource").Returns(Task.Run(() => mockResponse)); TestUKFastClient client = new TestUKFastClient(connection); var result = await client.GetAsync <ModelBase>("testresource"); Assert.AreEqual(mockResponse.Body.Data, result); }
public async Task GetAllAsync_NullParameters_ExpectedConfiguredParameters() { ClientResponse <IList <ModelBase> > mockPage1Response = GetListResponse(null, 2); ClientResponse <IList <ModelBase> > mockPage2Response = GetListResponse(null, 2); IUKFastClient mockClient = Substitute.For <IUKFastClient>(); mockClient.GetPaginatedAsync <ModelBase>("testresource", Arg.Is <ClientRequestParameters>(x => x.Pagination.Page == 2 && x.Pagination.PerPage == 99)).Returns(Task.Run(() => new Paginated <ModelBase>(mockClient, "testresource", null, mockPage2Response))); IUKFastClient client = new TestUKFastClient(null, new ClientConfig() { PaginationDefaultPerPage = 99 }); await client.GetAllAsync(async (ClientRequestParameters p) => new Paginated <ModelBase>(mockClient, "testresource", p, mockPage1Response), null); await mockClient.Received().GetPaginatedAsync <ModelBase>("testresource", Arg.Is <ClientRequestParameters>(x => x.Pagination.PerPage == 99)); }
public async Task DeleteAsyncGeneric_ExpectedCall() { ModelBase model = new ModelBase(); var mockResponse = GetSingleResponse(model, 0); mockResponse.StatusCode = 200; IConnection connection = NSubstitute.Substitute.For <IConnection>(); connection.DeleteAsync <ModelBase>("testresource").Returns(Task.Run(() => mockResponse)); TestUKFastClient client = new TestUKFastClient(connection); var result = await client.DeleteAsync <ModelBase>("testresource"); Assert.AreEqual(model, result); await connection.Received().DeleteAsync <ModelBase>("testresource"); }
public async Task GetPaginatedResponseAsync_NullParameters_ExpectedConfiguredParameters() { var mockResponse = GetListResponse(new List <ModelBase>(), 3); mockResponse.StatusCode = 200; IConnection connection = NSubstitute.Substitute.For <IConnection>(); connection.GetAsync <IList <ModelBase> >("testresource", Arg.Any <ClientRequestParameters>()).Returns(Task.Run(() => mockResponse)); TestUKFastClient client = new TestUKFastClient(connection, new ClientConfig() { PaginationDefaultPerPage = 99 }); await client.GetPaginatedAsync <ModelBase>("testresource"); await connection.Received().GetAsync <IList <ModelBase> >("testresource", Arg.Is <ClientRequestParameters>(x => x.Pagination.PerPage == 99)); }
public async Task GetPaginatedResponseAsync_ExpectedResult() { var mockResponse = GetListResponse(new List <ModelBase>() { new ModelBase(), new ModelBase() }, 3); mockResponse.StatusCode = 200; IConnection connection = NSubstitute.Substitute.For <IConnection>(); connection.GetAsync <IList <ModelBase> >("testresource", Arg.Any <ClientRequestParameters>()).Returns(Task.Run(() => mockResponse)); TestUKFastClient client = new TestUKFastClient(connection); var result = await client.GetPaginatedAsync <ModelBase>("testresource"); Assert.AreEqual(2, result.Items.Count); Assert.AreEqual(3, result.TotalPages); }