Template
136 lines
5.2 KiB
C#
136 lines
5.2 KiB
C#
using Strata.ApiCommunication.Http;
|
|
using Strata.ContinuousImprovement.Api.Test.Integration.Info;
|
|
using System.Net.Http.Json;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Strata.ContinuousImprovement.Api.Test.Integration.Tests
|
|
{
|
|
[TestFixture(), Category("Integration"), Category("API")]
|
|
public class TestInitiativesController_Export : ApiTestBase
|
|
{
|
|
protected const string InitiativesEndpoint = "api/v1/initiatives";
|
|
private Guid ConfigurationGuid { get; set; } = Guid.Empty;
|
|
private string Workstream { get; set; } = string.Empty;
|
|
private object FilterSettings { get; set; }
|
|
|
|
[Test, Order(1)]
|
|
public async Task TestInitiativesExport_Step1()
|
|
{
|
|
// arrange
|
|
|
|
// act
|
|
var configurations = await GetConfigurations();
|
|
var configuration = configurations.OrderBy(c => c.DisplayOrder).First();
|
|
var configurationGuid = configuration.ConfigurationGuid;
|
|
ConfigurationGuid = configurationGuid;
|
|
|
|
// assert
|
|
Assert.That(ConfigurationGuid, Is.Not.EqualTo(Guid.Empty));
|
|
}
|
|
|
|
[Test, Order(2)]
|
|
public async Task TestInitiativesExport_Step2()
|
|
{
|
|
// arrange
|
|
var request = new HttpRequestMessage(HttpMethod.Get, InitiativesEndpoint + $"/{ConfigurationGuid}/filter-options");
|
|
var response = await HttpClient.SendAsync(request);
|
|
response.EnsureSuccessStatusCode();
|
|
var filterOptions = await response.Content.ReadFromJsonAsync<InitiativeFilterOptionsInfo>();
|
|
|
|
// assert
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(filterOptions, Is.Not.Null);
|
|
Assert.That(filterOptions.Workstreams, Is.Not.Null.And.Not.Empty);
|
|
});
|
|
var workstream = filterOptions.Workstreams.First().Name;
|
|
Workstream = workstream;
|
|
}
|
|
|
|
[Test, Order(3)]
|
|
public async Task TestInitiativesExport_Step3()
|
|
{
|
|
// arrange
|
|
FilterSettings = new
|
|
{
|
|
ConfigurationGuid,
|
|
name = "",
|
|
status = 0,
|
|
costDrivers = Array.Empty<string>(),
|
|
costLeaders = Array.Empty<string>(),
|
|
owners = Array.Empty<string>(),
|
|
executiveSponsors = Array.Empty<string>(),
|
|
workstreams = new string[] { Workstream },
|
|
rollupColumn1Values = Array.Empty<string>(),
|
|
rollupColumn2Values = Array.Empty<string>(),
|
|
rollupColumn3Values = Array.Empty<string>(),
|
|
groupByCategory = "CostDriver"
|
|
};
|
|
|
|
// act
|
|
var request = new HttpRequestMessage(HttpMethod.Post, InitiativesEndpoint + "/set-filter-settings");
|
|
await request.SetContentAsJsonAsync(FilterSettings);
|
|
var response = await HttpClient.SendAsync(request);
|
|
|
|
// assert
|
|
response.EnsureSuccessStatusCode();
|
|
}
|
|
|
|
[Test, Order(4)]
|
|
public async Task TestInitiativesExport_Step4()
|
|
{
|
|
// arrange
|
|
var request = new HttpRequestMessage(HttpMethod.Post, InitiativesEndpoint);
|
|
await request.SetContentAsJsonAsync(FilterSettings);
|
|
var response = await HttpClient.SendAsync(request);
|
|
|
|
// act
|
|
response.EnsureSuccessStatusCode();
|
|
}
|
|
|
|
[Test, Order(5)]
|
|
public async Task TestInitiativesExport_Step5()
|
|
{
|
|
// arrange
|
|
var data = new
|
|
{
|
|
sortOptions = new
|
|
{
|
|
sortField = "name",
|
|
sortOrder = "Asc"
|
|
},
|
|
filters = new
|
|
{
|
|
ConfigurationGuid,
|
|
name = "",
|
|
status = 0,
|
|
costDrivers = Array.Empty<string>(),
|
|
costLeaders = Array.Empty<string>(),
|
|
owners = Array.Empty<string>(),
|
|
executiveSponsors = Array.Empty<string>(),
|
|
workstreams = new string[] { Workstream },
|
|
rollupColumn1Values = Array.Empty<string>(),
|
|
rollupColumn2Values = Array.Empty<string>(),
|
|
rollupColumn3Values = Array.Empty<string>(),
|
|
groupByCategory = "CostDriver"
|
|
}
|
|
};
|
|
var request = new HttpRequestMessage(HttpMethod.Post, InitiativesEndpoint + "/export");
|
|
await request.SetContentAsJsonAsync(data);
|
|
|
|
// act
|
|
var response = await HttpClient.SendAsync(request);
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
// assert
|
|
var headers = response.Content.Headers.Where(x => x.Value != null)
|
|
.ToDictionary(k => k.Key, v => v.Value);
|
|
var disposition = headers["Content-Disposition"].First();
|
|
var regex = new Regex("attachment; filename=Initiatives_[\\d]{2}-[\\d]{2}-[\\d]{4}\\.xlsx; filename\\*=UTF-8''Initiatives_[\\d]{2}-[\\d]{2}-[\\d]{4}\\.xlsx",
|
|
RegexOptions.IgnoreCase);
|
|
Assert.That(regex.IsMatch(disposition));
|
|
}
|
|
|
|
}
|
|
}
|