Skip to content

Commit

Permalink
Add controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronny Birkeli committed Aug 17, 2023
1 parent 8f77876 commit 760ff0b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/Altinn.App.Api.Tests/Controllers/OptionsControllerTests.cs
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);
}
}
}

0 comments on commit 760ff0b

Please sign in to comment.