From 760ff0b02ecd1b3eea47602c943d0c574a80cba4 Mon Sep 17 00:00:00 2001 From: Ronny Birkeli Date: Thu, 17 Aug 2023 12:25:34 +0200 Subject: [PATCH] Add controller test --- .../Controllers/OptionsControllerTests.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/Altinn.App.Api.Tests/Controllers/OptionsControllerTests.cs diff --git a/test/Altinn.App.Api.Tests/Controllers/OptionsControllerTests.cs b/test/Altinn.App.Api.Tests/Controllers/OptionsControllerTests.cs new file mode 100644 index 000000000..259d82673 --- /dev/null +++ b/test/Altinn.App.Api.Tests/Controllers/OptionsControllerTests.cs @@ -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> + { + public OptionsControllerTests(WebApplicationFactory factory) : base(factory) + { + } + + [Fact] + public async Task Get_ShouldReturnParametersInHeader() + { + OverrideServicesForThisTest = (services) => + { + services.AddTransient(); + }; + + 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 GetAppOptionsAsync(string language, Dictionary keyValuePairs) + { + AppOptions appOptions = new AppOptions() + { + Parameters = new Dictionary() + { + { "lang", "nb" } + } + }; + + return Task.FromResult(appOptions); + } + } +}