Neptunee.xApi 1.0.5

dotnet add package Neptunee.xApi --version 1.0.5                
NuGet\Install-Package Neptunee.xApi -Version 1.0.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Neptunee.xApi" Version="1.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Neptunee.xApi --version 1.0.5                
#r "nuget: Neptunee.xApi, 1.0.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Neptunee.xApi as a Cake Addin
#addin nuget:?package=Neptunee.xApi&version=1.0.5

// Install Neptunee.xApi as a Cake Tool
#tool nuget:?package=Neptunee.xApi&version=1.0.5                

xApi - Single line to test your api !

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Easy way to build integration test using xUnit & WebApplicationFactory

Basic Usage

 _fixture.Api.Rout<SampleControllerTest>(nameof(SampleControllerTest.GetAll))
    .FromQuery(nameof(name),name)
    .Send()
    .AssertSuccessStatusCode();
  • OR :
 _fixture.Api.Rout(HttpMethod.Get, "api/something/getbyid")
    .FromRoute(nameof(id),id)
    .Send()
    .AssertSuccessStatusCode();

Setup

create Fixture class to use it in all tests

public class IntegrationTestFixture : IntegrationTest<Startup>
{
    public IntegrationTestFixture()
    {
        Configure(webApplicationBuilder: builder => builder.UseEnvironment(Environments.Development),
            clientBuilder: options => options.AllowAutoRedirect = false);
    }
}

Example how to use IntegrationTestFixture for SampleControllerTest api testing


public class SampleControllerTest : IClassFixture<IntegrationTestFixture>
{
    private readonly IntegrationTestFixture _fixture;


    public SampleControllerTest(IntegrationTestFixture fixture, ITestOutputHelper output)
    {
        _fixture = fixture;
        _fixture.SetApiOutput(output); // to dispaly some info while sending apis (url , request , response , status code ..)
    }

    [Fact]
    public Task AnyApiTest()
    {
        // logic
    }
}

How To Send Query / Routes

var id = Guid.NewGuid();
_fixture.Api.Rout<SampleControllerTest>(nameof(SampleControllerTest.Get))
    .FromQuery(nameof(id),id) // key & value
    .FromQuery(new // anonymos object
    {
        id,
    })
    .FromQuery(new AnyDto() // object like dto, mv, ..etc
    {
        Id = id,
    })
    

same for Routes just use FromRoute() instead of FromQuery().

How To Send Json / FormData

_fixture.Api.Rout<SampleControllerTest>(nameof(SampleControllerTest.Add))
    .FromBody(new AddRequstClass // for Json body request
    {
        Id = Guid.NewGuid(),
        Email = "test@xapi.com",
    })
    .FromForm(new AddRequstClass // for Multipart Form Data body request
    {
        Name = "Simple Test",
        ImageFile = _fixture.FormFile("AssetsFolder/test.png")
    })    

Assert Status Code

**You can use this methods 😗*

  • AssertSuccessStatusCodeAsync() / AssertSuccessStatusCode() when its range 200-299.
  • AssertNotSuccessStatusCodeAsync() / AssertNotSuccessStatusCode() when its otherwise range 200-299.
  • AssertStatusCodeEqualsAsync(HttpStatusCode.OK) / AssertStatusCodeEquals(HttpStatusCode.OK)
  • AssertStatusCodeNotEqualsAsync(HttpStatusCode.Conflict) / AssertStatusCodeNotEquals(HttpStatusCode.Conflict)

Working With Files

You have FormFile() method in IntegrationTest<TStartup> to help you to send files as IFormFile with 3 overloads :

public IFormFile FormFile(string path, string? contentType = null)
 public IFormFile FormFile(Stream stream, string fileName, string? contentType = null)
public IFormFile FormFile(byte[] bytes, string fileName, string? contentType = null)

Note: the optional contentType parameter throw null exception if TryGetContentType() returns false, means contentType is unknown.

PS: can send empty Files with FakeFormFile() method.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 167 3/24/2024
1.0.4 250 2/13/2024
1.0.3 228 11/8/2023
1.0.2 528 6/26/2023
1.0.1 458 4/12/2023