Files
continuousimprovement/tests/Strata.ContinuousImprovement.Api.Test.Integration/Tests/TestConfigurationsController.cs
T

171 lines
7.6 KiB
C#

using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
using System.Net.Http.Json;
using System.Text.RegularExpressions;
namespace Strata.ContinuousImprovement.Api.Test.Integration.Tests
{
[ExcludeFromCodeCoverage]
[TestFixture, Category("Integration"), Category("API")]
public partial class TestConfigurationsController : ApiTestBase
{
protected const string ConfigurationsEndpoint = "api/v1/configurations";
[Test]
public async Task TestConfigurations()
{
//arrange
var request = new HttpRequestMessage(HttpMethod.Get, ConfigurationsEndpoint);
// act
var response = await HttpClient.SendAsync(request, CancellationToken.None);
// assert
response.EnsureSuccessStatusCode();
response.AssertIsValid();
}
[Test]
[Ignore("Test database needs to be rolled over to the new year")]
public async Task TestDfltConfiguration()
{
//arrange
var request = new HttpRequestMessage(HttpMethod.Get, ConfigurationsEndpoint);
// act
var response = await HttpClient.SendAsync(request, CancellationToken.None);
response.EnsureSuccessStatusCode();
var configurations = await response.Content.ReadFromJsonAsync<IEnumerable<Info.ConfigurationInfo>>();
configurations = configurations?.OrderBy(x => x.DisplayOrder);
var configuration = configurations?.FirstOrDefault();
// assert
Assert.Multiple(() =>
{
response.AssertIsValid();
Assert.That(configurations, Is.Not.Null.And.Not.Empty);
Assert.That(configuration, Is.Not.Null);
var expectedFiscalYearId = DateTime.Now.Year;
Assert.That(configuration.FiscalYearId, Is.InRange(expectedFiscalYearId - 1, expectedFiscalYearId), "Test database fiscal year configuration must be updated for the current year.");
});
}
[Test]
public async Task TestEntityConfiguration()
{
//arrange
var request = new HttpRequestMessage(HttpMethod.Get, ConfigurationsEndpoint);
// act
var response = await HttpClient.SendAsync(request, CancellationToken.None);
response.EnsureSuccessStatusCode();
var configurations = await response.Content.ReadFromJsonAsync<IEnumerable<Info.ConfigurationInfo>>();
configurations = configurations?.OrderBy(x => x.DisplayOrder);
var configuration = configurations?.FirstOrDefault(c => c.EntityIdsCsv != "" && !c.IsUsingCustomEntityDimension);
// assert
Assert.Multiple(() =>
{
response.AssertIsValid();
Assert.That(configurations, Is.Not.Null.And.Not.Empty);
Assert.That(configuration, Is.Not.Null);
Assert.That(configuration.IsUsingCustomEntityDimension, Is.False);
Assert.That(configuration.EntityIdsCsv, Is.Not.Empty);
});
}
[Test]
public async Task TestConfigurationEntities()
{
//arrange
var configurations = await GetConfigurations();
var configurationGuid = configurations?.FirstOrDefault(c => c.EntityIdsCsv != "" && !c.IsUsingCustomEntityDimension)?.ConfigurationGuid ?? Guid.Empty;
var configurationsEndpoint = ConfigurationsEndpoint + $"/{configurationGuid}/configuration-entities";
var request = new HttpRequestMessage(HttpMethod.Get, configurationsEndpoint);
// act
var response = await HttpClient.SendAsync(request, CancellationToken.None);
response.EnsureSuccessStatusCode();
var configurationEntities = await response.Content.ReadFromJsonAsync<IEnumerable<Info.EntityIdInfo>>();
configurationEntities = configurationEntities?.OrderBy(x => x.EntityName);
var configurationEntity = configurationEntities?.FirstOrDefault();
// assert
Assert.Multiple(() =>
{
response.AssertIsValid();
Assert.That(configurationEntities, Is.Not.Null.And.Not.Empty);
Assert.That(configurationEntity, Is.Not.Null);
});
}
[Test]
public async Task TestConfigurationServiceLineInfo()
{
//arrange
var configurations = await GetConfigurations();
var configurationGuid = configurations?.FirstOrDefault()?.ConfigurationGuid ?? Guid.Empty;
var configurationsEndpoint = ConfigurationsEndpoint + $"/{configurationGuid}/configuration-service-line-info";
var request = new HttpRequestMessage(HttpMethod.Get, configurationsEndpoint);
var guidRegex = GuidRegex();
var serviceLineRegex = new Regex("w*Service Lines?");
// act
var response = await HttpClient.SendAsync(request, CancellationToken.None);
response.EnsureSuccessStatusCode();
var configurationServiceLine = await response.Content.ReadFromJsonAsync<Info.ServiceLineInfo>();
// assert
Assert.Multiple(() =>
{
response.AssertIsValid();
Assert.That(configurationServiceLine, Is.Not.Null);
Assert.That(configurationServiceLine.ServiceLineGlobalId, Is.Not.Null);
Assert.That(configurationServiceLine.ServiceLineTitle, Is.Not.Null.And.Not.Empty);
Assert.That(configurationServiceLine.ServiceLineName, Is.Not.Null.And.Not.Empty);
Assert.That(guidRegex.IsMatch(configurationServiceLine.ServiceLineDimensionGuid), Is.True);
Assert.That(guidRegex.IsMatch(configurationServiceLine.ServiceLineHierarchicalGuid), Is.True);
Assert.That(serviceLineRegex.IsMatch(configurationServiceLine.ServiceLineTitle), Is.True);
Assert.That(serviceLineRegex.IsMatch(configurationServiceLine.ServiceLineName), Is.True);
});
}
[Test]
public async Task TestConfigurationEntityInfo()
{
//arrange
var configurations = await GetConfigurations();
var configurationGuid = configurations?.FirstOrDefault()?.ConfigurationGuid ?? Guid.Empty;
var configurationsEndpoint = ConfigurationsEndpoint + $"/{configurationGuid}/configuration-entity-info";
var request = new HttpRequestMessage(HttpMethod.Get, configurationsEndpoint);
var guidRegex = GuidRegex();
// act
var response = await HttpClient.SendAsync(request, CancellationToken.None);
response.EnsureSuccessStatusCode();
var configurationServiceLine = await response.Content.ReadFromJsonAsync<Info.EntityInfo>();
// assert
Assert.Multiple(() =>
{
response.AssertIsValid();
Assert.That(configurationServiceLine, Is.Not.Null);
Assert.That(configurationServiceLine.DepartmentRollupGlobalId, Is.Not.Null.And.Not.Empty);
Assert.That(configurationServiceLine.EntityTitle, Is.Not.Null.And.Not.Empty);
Assert.That(configurationServiceLine.EntityLabel, Is.Not.Null.And.Not.Empty);
Assert.That(configurationServiceLine.EntityText, Is.Not.Null.And.Not.Empty);
Assert.That(guidRegex.IsMatch(configurationServiceLine.HierarchicalGuid), Is.True);
});
}
[GeneratedRegex("[({]?[a-fA-F0-9]{8}[\\-]?([a-fA-F0-9]{4}[\\-]?){3}[a-fA-F0-9]{12}[})]?")]
private static partial Regex GuidRegex();
}
}