示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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");
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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));
        }
示例#7
0
        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");
        }
示例#8
0
        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));
        }
示例#9
0
        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);
        }