GodelTech.XUnit.Auth 8.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package GodelTech.XUnit.Auth --version 8.0.0                
NuGet\Install-Package GodelTech.XUnit.Auth -Version 8.0.0                
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="GodelTech.XUnit.Auth" Version="8.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GodelTech.XUnit.Auth --version 8.0.0                
#r "nuget: GodelTech.XUnit.Auth, 8.0.0"                
#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 GodelTech.XUnit.Auth as a Cake Addin
#addin nuget:?package=GodelTech.XUnit.Auth&version=8.0.0

// Install GodelTech.XUnit.Auth as a Cake Tool
#tool nuget:?package=GodelTech.XUnit.Auth&version=8.0.0                

GodelTech.XUnit.Auth

Overview

GodelTech.XUnit.Auth contains helpers to assert routes in project.

Example of usage Test JSON Web Token

AppTestFixture.cs

    public class AppTestFixture : WebApplicationFactory<Startup>
    {
        protected override void ConfigureWebHost([NotNull] IWebHostBuilder builder)
        {
            builder
                .UseSetting("https_port", "8080")
                .ConfigureTestJwtToken(); // Configures Test JSON Web Token
        }
    }

ControllerTests.cs

    public sealed class FakeControllerTests : IDisposable
    {
        private readonly AppTestFixture _fixture;
        private readonly HttpClient _client;

        public FakeControllerTests(ITestOutputHelper output)
        {
            _fixture = new AppTestFixture
            {
                Output = output
            };

            _client = _fixture.CreateClient(
                new WebApplicationFactoryClientOptions
                {
                    BaseAddress = new Uri("https://localhost:8080")
                }
            );
        }

        public void Dispose()
        {
            _client.Dispose();
            _fixture.Dispose();
        }

        [Fact]
        public async Task GetListAsync_ReturnsOkWithList()
        {
            // Arrange
            var expectedResult = FakeController.Items;

            // Act
            var result = await _client
                .WithJwtBearerToken() // Adds Test JSON Web Token to HttpClient
                .GetAsync(new Uri("/fakes", UriKind.Relative));

            // Assert
            Assert.Equal(HttpStatusCode.OK, result.StatusCode);

            var resultValue = await result.Content.ReadFromJsonAsync<IList<FakeModel>>();
            Assert.NotNull(resultValue);
            Assert.Equal(2, resultValue.Count);
            resultValue.Should().BeEquivalentTo(expectedResult);
        }
    }

You can check example of usage in Integration Tests for this library here: https://github.com/GodelTech/GodelTech.XUnit.Auth/tree/main/test/GodelTech.XUnit.Auth.IntegrationTests.

Exmaple of usage RouteTests

    public sealed class RouteTests : IDisposable
    {
        private readonly AppTestFixture _fixture;
        private readonly HttpClient _client;

        public RouteTests(ITestOutputHelper output)
        {
            _fixture = new AppTestFixture
            {
                Output = output
            };

            _client = _fixture.CreateClient(
                new WebApplicationFactoryClientOptions
                {
                    BaseAddress = new Uri("https://localhost:8080"),
                    AllowAutoRedirect = false
                }
            );
        }

        public void Dispose()
        {
            _client.Dispose();
            _fixture.Dispose();
        }

        private static readonly IList<Routes.RouteBase> Routes = new List<Routes.RouteBase>
        {
            // fakes
            new AuthorizedRoute("/fakes", HttpMethod.Get),
            new AuthorizedRoute(
                "/fakes/{id}",
                HttpMethod.Get,
                new RouteValueDictionary
                {
                    { "id", 1 }
                }
            ),
            new AuthorizedRoute("/fakes", HttpMethod.Post),
            new AuthorizedRoute(
                "/fakes/{id}",
                HttpMethod.Put,
                new RouteValueDictionary
                {
                    { "id", 1 }
                }
            ),
            new AuthorizedRoute(
                "/fakes/{id}",
                HttpMethod.Delete,
                new RouteValueDictionary
                {
                    { "id", 1 }
                }
            ),
            // openFakes
            new AllowAnonymousRoute(
                "/openFakes",
                HttpMethod.Get
            )
        };

        public static IEnumerable<object[]> CheckRoutesMemberData => Routes
            .Select(
                route => new object[]
                {
                    route
                }
            );

        [Theory]
        [MemberData(nameof(CheckRoutesMemberData))]
        public async Task CheckRoutes(Routes.RouteBase route)
        {
            // Arrange & Act & Assert
            await AssertRoute.CheckAsync(
                route,
                _fixture.GetEndpoints(),
                _fixture.GeTemplateBinderFactory(),
                _client
            );
        }

        [Fact]
        public void CheckEndpoints()
        {
            // Arrange & Act & Assert
            AssertEndpoint.Check(
                _fixture.GetEndpoints(),
                Routes
            );
        }
    }

You can check example of usage in Integration Tests for this library here: https://github.com/GodelTech/GodelTech.XUnit.Auth/tree/main/test/GodelTech.XUnit.Auth.IntegrationTests.

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
8.1.0 155 7/2/2024
8.0.0 136 1/19/2024
1.0.0 404 11/8/2023
0.2.1 138 11/4/2023