Skip to content

Commit

Permalink
Merge pull request #36 from lucassklp/improve-request-options
Browse files Browse the repository at this point in the history
feature: Improvements and bumps
  • Loading branch information
lucassklp authored Jul 3, 2024
2 parents b93063f + f488d11 commit c09c5d1
Show file tree
Hide file tree
Showing 24 changed files with 293 additions and 83 deletions.
Binary file removed .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.400
dotnet-version: 8.0.302
- name: Install dependencies
run: dotnet restore

Expand All @@ -26,7 +26,7 @@ jobs:

- name: Moving test coverage result to root folder
run: |
mv Tests/TestResults/**/coverage.cobertura.xml ./
mv Rx.Http.Tests/TestResults/**/coverage.cobertura.xml ./
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.400
dotnet-version: 8.0.302
source-url: https://nuget.pkg.github.com/lucassklp/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
Expand All @@ -26,7 +26,7 @@ jobs:

- name: Moving test coverage result to root folder
run: |
mv Tests/TestResults/**/coverage.cobertura.xml ./
mv Rx.Http.Tests/TestResults/**/coverage.cobertura.xml ./
- name: Send test coverage to Codacy
uses: codacy/codacy-coverage-reporter-action@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.idea
.vs
.vscode
.DS_Store
13 changes: 2 additions & 11 deletions Models/Consumers/PostmanConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,15 @@ public PostmanConsumer(HttpClient httpClient) : base(httpClient, null)
httpClient.BaseAddress = new Uri("https://postman-echo.com");
}

public IObservable<EchoResponse> GetWithQueryString(IDictionary<string, string> query)
public IObservable<EchoResponse> GetWithQueryString<T>(IDictionary<string, T> query)
{
return Get<EchoResponse>("get", opts =>
{
opts.AddQueryString(query);
});
}

public IObservable<EchoResponse> GetWithQueryString(IDictionary<string, List<string>> query)
{
return Get<EchoResponse>("get", opts =>
{
opts.AddQueryString(query);
});
}


public IObservable<EchoResponse> GetWithHeaders(IDictionary<string, string> headers)
public IObservable<EchoResponse> GetWithHeaders<T>(IDictionary<string, T> headers)
{
return Get<EchoResponse>("get", opts =>
{
Expand Down
2 changes: 1 addition & 1 deletion Models/Models.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ A lightweight library that is inpired in [Angular 2+ Http Client](https://angula
If you are using Package Manager:

```bash
Install-Package Rx.Http -Version 2.0.3
Install-Package Rx.Http -Version 2.1.0
```

If you are using .NET CLI

```bash
dotnet add package Rx.Http --version 2.0.3
dotnet add package Rx.Http --version 2.1.0
```

## Example of use
Expand Down
116 changes: 116 additions & 0 deletions Rx.Http.Tests/ConsumersTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using Models;
using Models.Consumers;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Rx.Http.Tests
{
public class ConsumersTests
{
private readonly Injector injector;
public ConsumersTests()
{
injector = new Injector();
}

[Fact]
public async Task CheckIfRequestIsWorking()
{
var tmdbConsumer = injector.Get<TheMovieDatabaseConsumer>();
var response = await tmdbConsumer.ListMovies();

Assert.NotNull(response);
}

[Fact]
public async Task CheckSameRequestTwice()
{
var tmdbConsumer = injector.Get<TheMovieDatabaseConsumer>();
var response1 = await tmdbConsumer.ListMovies();
var response2 = await tmdbConsumer.ListMovies();

Assert.NotNull(response1);
Assert.NotNull(response2);
}

[Fact]
public async Task TestPostWithBody()
{
var postmanConsumer = injector.Get<PostmanConsumer>();

var todo = new Todo
{
Id = 12,
Title = "Testing with special characters: àáç~ã*+ü?<>!ºªª",
IsCompleted = true,
UserId = 20
};
var response = await postmanConsumer.Post(todo);

Assert.True(response.Data.Equals(todo));
}

[Fact]
public async Task TestQueryStrings()
{
var postmanConsumer = injector.Get<PostmanConsumer>();

var queryStrings = new Dictionary<string, object>
{
{ "Foo", "Bar" },
{ "User", "John Doe" },
{ "Characters", "*&�%6dbajs&@#chv73*(#Y" },
{ "Boolean", true },
{ "Int", 1 },
{ "Float", 1.8129f },
{ "Double", 1.8129d },
};

var headers = await postmanConsumer.GetWithQueryString(queryStrings);

Assert.Equal(headers.Args, new Dictionary<string, string>
{
{ "Foo", "Bar" },
{ "User", "John Doe" },
{ "Characters", "*&�%6dbajs&@#chv73*(#Y" },
{ "Boolean", "true" },
{ "Int", "1" },
{ "Float", "1.8129" },
{ "Double", "1.8129" },
});
}

[Fact]
public async Task TestHeaders()
{
var postmanConsumer = injector.Get<PostmanConsumer>();

var headers = new Dictionary<string, object>
{
{ "Foo", "Bar" },
{ "User", "John Doe" },
{ "Boolean", true },
{ "Int", 1 },
{ "Float", 1.8129f },
{ "Double", 1.8129d },
};

var expected = new Dictionary<string, string>
{
{ "foo", "Bar" },
{ "user", "John Doe" },
{ "boolean", "true" },
{ "int", "1" },
{ "float", "1.8129" },
{ "double", "1.8129" },
};

var response = await postmanConsumer.GetWithHeaders(headers);
var valid = expected.All(pair => response.Headers.ContainsKey(pair.Key) && response.Headers[pair.Key] == pair.Value);
Assert.True(valid);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Text;
using Xunit;

namespace Tests
namespace Rx.Http.Tests
{
public class HttpLoggerBaseTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Rx.Http;
using Xunit;

namespace Tests
namespace Rx.Http.Tests
{
public class InjectionTests
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Injector.cs → Rx.Http.Tests/Injector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Rx.Http.Extensions;
using Rx.Http.Logging;

namespace Tests
namespace Rx.Http.Tests
{
class Injector
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Rx.Http;
using Xunit;

namespace Tests
namespace Rx.Http.Tests
{
public class NavigatorTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Xunit;
using Rx.Http.Extensions;

namespace Tests
namespace Rx.Http.Tests
{
public class PostmanEchoTests
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/RequestTests.cs → Rx.Http.Tests/RequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Xunit;
using System.IO;

namespace Tests
namespace Rx.Http.Tests
{
public class RequestTests
{
Expand Down
26 changes: 26 additions & 0 deletions Rx.Http.Tests/Rx.Http.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Models\Models.csproj" />
<ProjectReference Include="..\Rx.Http\Rx.Http.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Rx.Http.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{7D26E97A-BA89-446C-BD25-363C9A047D6C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rx.Http.Tests", "Rx.Http.Tests\Rx.Http.Tests.csproj", "{7D26E97A-BA89-446C-BD25-363C9A047D6C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples", "Samples\Samples.csproj", "{4C43BBB8-042C-4623-A1ED-14A578B23AB3}"
EndProject
Expand Down
20 changes: 10 additions & 10 deletions Rx.Http/Rx.Http.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<Version>2.0.3</Version>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors>Lucas Simas</Authors>
<Description>A lightweight library that is inpired in Angular Http Client built on top of .NET HttpClient that and help programmers to make asynchronous http requests.</Description>
<PackageProjectUrl>https://github.com/lucassklp/Rx.Http</PackageProjectUrl>
<RepositoryUrl>https://github.com/lucassklp/Rx.Http</RepositoryUrl>
<PackageIcon>rx.http.icon.png</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<TargetFrameworks>net8.0</TargetFrameworks>
<Version>2.1.0</Version>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors>Lucas Simas</Authors>
<Description>A lightweight library that is inpired in Angular Http Client built on top of .NET HttpClient that and help programmers to make asynchronous http requests.</Description>
<PackageProjectUrl>https://github.com/lucassklp/Rx.Http</PackageProjectUrl>
<RepositoryUrl>https://github.com/lucassklp/Rx.Http</RepositoryUrl>
<PackageIcon>rx.http.icon.png</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>

<ItemGroup>
Expand Down
40 changes: 40 additions & 0 deletions Rx.Http/RxHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,46 @@ public IObservable<T> Post<T>(string url, Action<RxHttpRequestOptions> options)
return Request<T>(url, options, HttpMethod.Post);
}

public IObservable<RxHttpResponse> Patch(string url)
{
return Request(url, HttpMethod.Patch);
}

public IObservable<RxHttpResponse> Patch(string url, object content)
{
return Request(url, content, HttpMethod.Patch);
}

public IObservable<RxHttpResponse> Patch(string url, object content, Action<RxHttpRequestOptions> options)
{
return Request(url, content, options, HttpMethod.Patch);
}

public IObservable<RxHttpResponse> Patch(string url, Action<RxHttpRequestOptions> options)
{
return Request(url, options, HttpMethod.Patch);
}

public IObservable<T> Patch<T>(string url)
{
return Request<T>(url, HttpMethod.Patch);
}

public IObservable<T> Patch<T>(string url, object content)
{
return Request<T>(url, content, HttpMethod.Patch);
}

public IObservable<T> Patch<T>(string url, object content, Action<RxHttpRequestOptions> options)
{
return Request<T>(url, content, options, HttpMethod.Patch);
}

public IObservable<T> Patch<T>(string url, Action<RxHttpRequestOptions> options)
{
return Request<T>(url, options, HttpMethod.Patch);
}

public IObservable<RxHttpResponse> Put(string url)
{
return Request(url, HttpMethod.Put);
Expand Down
Loading

0 comments on commit c09c5d1

Please sign in to comment.