-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ronny Birkeli
committed
Aug 17, 2023
1 parent
8f77876
commit 760ff0b
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
test/Altinn.App.Api.Tests/Controllers/OptionsControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System.Net; | ||
using Xunit; | ||
using Altinn.App.Core.Features; | ||
using Altinn.App.Core.Models; | ||
using FluentAssertions; | ||
|
||
namespace Altinn.App.Api.Tests.Controllers | ||
{ | ||
public class OptionsControllerTests : ApiTestBase, IClassFixture<WebApplicationFactory<Program>> | ||
{ | ||
public OptionsControllerTests(WebApplicationFactory<Program> factory) : base(factory) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task Get_ShouldReturnParametersInHeader() | ||
{ | ||
OverrideServicesForThisTest = (services) => | ||
{ | ||
services.AddTransient<IAppOptionsProvider, DummyProvider>(); | ||
}; | ||
|
||
string org = "tdd"; | ||
string app = "contributer-restriction"; | ||
HttpClient client = GetRootedClient(org, app); | ||
|
||
string url = $"/{org}/{app}/api/options/test"; | ||
HttpResponseMessage response = await client.GetAsync(url); | ||
|
||
var headerValue = response.Headers.GetValues("Altinn-DownstreamParameters"); | ||
response.StatusCode.Should().Be(HttpStatusCode.OK); | ||
headerValue.Should().Contain("lang=nb"); | ||
} | ||
} | ||
|
||
public class DummyProvider : IAppOptionsProvider | ||
{ | ||
public string Id => "test"; | ||
|
||
public Task<AppOptions> GetAppOptionsAsync(string language, Dictionary<string, string> keyValuePairs) | ||
{ | ||
AppOptions appOptions = new AppOptions() | ||
{ | ||
Parameters = new Dictionary<string, string>() | ||
{ | ||
{ "lang", "nb" } | ||
} | ||
}; | ||
|
||
return Task.FromResult(appOptions); | ||
} | ||
} | ||
} |