Skip to content
Snippets Groups Projects
Commit 5fdc910d authored by Klaus Fischer's avatar Klaus Fischer
Browse files

updated tests

parent 86a9b84d
No related branches found
No related tags found
No related merge requests found
......@@ -15,19 +15,20 @@ using Microsoft.Extensions.Logging;
namespace E2ETest;
public record SenderConfig(string ClientId, string ClientSecret, string CallbackSecret);
[Order(20)]
[TestFixture]
public class ReplyChannelTest : EndToEndTestBase {
private SenderConfig[] _senderConfigs;
private FitConnectEnvironment _environment = FitConnectEnvironment.Test;
private ClientConfig[] _senderConfigs;
private readonly FitConnectEnvironment _environment = FitConnectEnvironment.Test;
private int _senderId;
private record ClientConfig(string ClientId, string ClientSecret, string CallbackSecret);
[OneTimeSetUp]
public void OneTimeSetUp() {
Configuration = new ConfigurationBuilder().AddJsonFile("biDiKoSettings.json").Build();
_senderConfigs = Configuration.GetSection("sender").Get<SenderConfig[]>();
_senderConfigs = Configuration.GetSection("sender").Get<ClientConfig[]>();
_senderId = DateTime.UtcNow.Millisecond % _senderConfigs.Length;
Console.WriteLine($"Choosing sender {_senderId}");
}
......@@ -36,7 +37,7 @@ public class ReplyChannelTest : EndToEndTestBase {
public override void Setup() {
base.Setup();
Configuration = new ConfigurationBuilder().AddJsonFile("biDiKoSettings.json").Build();
_senderConfigs = Configuration.GetSection("sender").Get<SenderConfig[]>();
_senderConfigs = Configuration.GetSection("sender").Get<ClientConfig[]>();
var senderConfig = _senderConfigs[_senderId];
//
......@@ -45,10 +46,11 @@ public class ReplyChannelTest : EndToEndTestBase {
senderConfig.ClientId, senderConfig.ClientSecret,
Logger);
var subscriberClientData = Configuration.GetSection("subscribers").Get<List<ClientConfig>>();
Subscriber = ClientFactory.CreateSubscriberClient(
_environment,
Configuration["subscriber:clientId"],
Configuration["subscriber:clientSecret"],
subscriberClientData.First().ClientId,
subscriberClientData.First().ClientSecret,
new[] {
Configuration["destination:privateDecryptionKey"]!
}.ToList(),
......@@ -56,24 +58,36 @@ public class ReplyChannelTest : EndToEndTestBase {
Logger
);
AddSubscriber(Subscriber);
foreach (var subscriber in subscriberClientData) {
var subscriberClient = ClientFactory.CreateSubscriberClient(
_environment,
subscriber.ClientId,
subscriber.ClientSecret,
new[] {
Configuration["destination:privateDecryptionKey"]!
}.ToList(),
Configuration["destination:privateSigningKey"],
Logger
);
AddSubscriber(subscriberClient);
}
DestinationId = Guid.Parse(Configuration["destination:id"]);
}
private SentSubmission _submission = null!;
private const string REPLY_CHANNEL_EMAIL = "dummy@trashmail.com";
private const string TRANSACTION_ID = "9xxd-432x-6543-xfd6-gfdx-fd28";
private const double GROSS_AMOUNT = 12.5;
private const string AUTHENTICATION_VERSION = "1.0.34";
private static IReceivedSubmission receivedSubmission = null!;
private const string ReplyChannelEmail = "dummy@trashmail.com";
private const string TransactionId = "9xxd-432x-6543-xfd6-gfdx-fd28";
private const double GrossAmount = 12.5;
private const string AuthenticationVersion = "1.0.34";
private static IReceivedSubmission _receivedSubmission = null!;
private static JsonWebKey GeneratedPrivateKey { get; set; }
private static JsonWebKey GeneratedPublicKey { get; set; }
private IConfigurationRoot Configuration { get; set; } = null!;
public static Guid CaseId { get; set; }
private const string AUTHENTICATION_CONTENT =
private const string AuthenticationContent =
"QXV0b21hdGljYWxseSBCYXNlNjRVcmwgZW5jb2RlZCBTdHJpbmc";
private Guid DestinationId { get; set; } = Guid.Empty;
......@@ -104,16 +118,16 @@ public class ReplyChannelTest : EndToEndTestBase {
Encoding.UTF8.GetBytes("{\"message\":\"Hello World\"}"),
MediaTypeNames.Application.Json, "JsonFileAttachment.json", "Attachment #4"))
.SetAuthenticationInformation(new AuthenticationInformation(
AUTHENTICATION_CONTENT,
AuthenticationContent,
AuthenticationInformationType.IdentificationReport,
AUTHENTICATION_VERSION))
AuthenticationVersion))
.SetPaymentInformation(new PaymentInformation(
PaymentMethod.Invoice,
PaymentStatus.Booked,
TRANSACTION_ID,
TransactionId,
"E2E Testing the payment information"
) {
GrossAmount = GROSS_AMOUNT
GrossAmount = GrossAmount
})
.SetReplyChannel(ReplyChannel.OfFitConnect(
GeneratedPublicKey,
......@@ -186,13 +200,13 @@ public class ReplyChannelTest : EndToEndTestBase {
[Test]
[Order(40)]
public void T040_Subscriber_RequestSubmission() {
receivedSubmission =
_receivedSubmission =
Subscriber.RequestSubmissionAsync(_submission.SubmissionId).Result;
var data = receivedSubmission.GetData();
var data = _receivedSubmission.GetData();
Logger.LogInformation("Data {Data}", data);
var attachments = receivedSubmission.GetAttachmentsAsync().Result.ToList();
var attachments = _receivedSubmission.GetAttachmentsAsync().Result.ToList();
attachments.Count(a => a.Filename == "Test.pdf").Should().Be(3);
attachments.TrueForAll(a => a.Description?.StartsWith("Attachment #") ?? false).Should()
.BeTrue();
......@@ -203,37 +217,37 @@ public class ReplyChannelTest : EndToEndTestBase {
attachments.Single(attachment => attachment.Filename == "JsonFileAttachment.json").GetData()
.Should().BeEquivalentTo("{\"message\":\"Hello World\"}");
receivedSubmission.SubmissionId.Should().Be(_submission.SubmissionId);
receivedSubmission.CaseId.Should().Be(_submission.CaseId);
receivedSubmission.GetDataMimeType().Should()
_receivedSubmission.SubmissionId.Should().Be(_submission.SubmissionId);
_receivedSubmission.CaseId.Should().Be(_submission.CaseId);
_receivedSubmission.GetDataMimeType().Should()
.Be(MediaTypeNames.Application.Json);
receivedSubmission.Metadata.Should().NotBeNull();
_receivedSubmission.Metadata.Should().NotBeNull();
var authenticationInformation =
receivedSubmission.Metadata?.AuthenticationInformation?.First();
_receivedSubmission.Metadata?.AuthenticationInformation?.First();
authenticationInformation.Should().NotBeNull();
authenticationInformation!.Type
.Should().Be(AuthenticationInformationType.IdentificationReport);
authenticationInformation!.Version.Should().Be(AUTHENTICATION_VERSION);
authenticationInformation!.Content.Should().Be(AUTHENTICATION_CONTENT);
authenticationInformation!.Version.Should().Be(AuthenticationVersion);
authenticationInformation!.Content.Should().Be(AuthenticationContent);
receivedSubmission.Metadata?.PaymentInformation.GrossAmount.Should().Be(GROSS_AMOUNT);
receivedSubmission.Metadata?.PaymentInformation.TransactionId.Should()
.Be(TRANSACTION_ID);
receivedSubmission.Metadata?.PaymentInformation.PaymentMethod.Should()
_receivedSubmission.Metadata?.PaymentInformation.GrossAmount.Should().Be(GrossAmount);
_receivedSubmission.Metadata?.PaymentInformation.TransactionId.Should()
.Be(TransactionId);
_receivedSubmission.Metadata?.PaymentInformation.PaymentMethod.Should()
.Be(PaymentMethod.Invoice);
receivedSubmission.Metadata?.ReplyChannel?.EMail?.Address.Should().Be(REPLY_CHANNEL_EMAIL);
_receivedSubmission.Metadata?.ReplyChannel?.EMail?.Address.Should().Be(ReplyChannelEmail);
receivedSubmission.AcceptSubmissionAsync().Wait();
_receivedSubmission.AcceptSubmissionAsync().Wait();
}
[Test]
[Order(43)]
public void T043_SendReply() {
var replySubmission = SendableReply.From(receivedSubmission)
var replySubmission = SendableReply.From(_receivedSubmission)
.SetJsonData("{ \"replyData\" : \"Bitte Anhang xy nachreichen\"}",
new Uri("https://projects.eloware.dev/fit-connect/schemas/reply.schema.json"))
.AddAttachment(Attachment.FromPath("Test.pdf", "application/pdf", description: "Attachment #1",
......@@ -269,7 +283,6 @@ public class ReplyChannelTest : EndToEndTestBase {
Console.WriteLine($"Found {replies?.Count ?? 0} replies");
if (replies == null) return;
foreach (var reply in replies)
Sender.RejectReplyAsync(reply.ReplyId,
new Problems(Problems.ProblemTypeEnum.ServiceMismatch, "Cleaning up reject")).Wait();
......@@ -344,6 +357,7 @@ public class ReplyChannelTest : EndToEndTestBase {
[Test]
[Order(63)]
[Ignore("Was just used for debugging")]
public void T063_List_Cases() {
var sender0Cases = ClientFactory.CreateSenderClient(_environment,
_senderConfigs[0].ClientId, _senderConfigs[0].ClientSecret,
......@@ -405,15 +419,21 @@ public class ReplyChannelTest : EndToEndTestBase {
public override void CleanServer() {
base.CleanServer();
for (var i = 0; i < _senderConfigs.Length; i++) {
foreach (var senderConfig in _senderConfigs) {
var senderClient = ClientFactory.CreateSenderClient(_environment,
_senderConfigs[i].ClientId, _senderConfigs[i].ClientSecret,
senderConfig.ClientId, senderConfig.ClientSecret,
Logger
);
var destinations = senderClient.GetCases().Result.Select(c=>c.DestinationId).Distinct();
var replies = senderClient.ListAvailableRepliesAsync(null).Result?.ToList();
foreach (var reply in replies)
senderClient.RejectReplyAsync(reply.ReplyId,
new Problems(Problems.ProblemTypeEnum.ServiceMismatch, "Cleaning up reject")).Wait();
var destinations = senderClient.GetCases().Result.Select(c => c.DestinationId).Distinct();
foreach (var destinationId in destinations) {
Console.WriteLine($"Server not cleaned for {destinationId}");
Console.WriteLine(
$"Server not cleaned for Sender {senderConfig.ClientId} on destination {destinationId} but got {replies.Count} replies");
}
}
}
......
......@@ -17,11 +17,23 @@
"callbackSecret": ""
}
],
"subscriber": {
"clientId": "db49abed-bb23-429c-976f-fa8382780ea4",
"clientSecret": "5CUEwrmkEBsUwwOzFrHGczDI3lOtSCcpSJOK6Q338FI",
"callbackSecret": ""
},
"subscribers": [
{
"clientId": "db49abed-bb23-429c-976f-fa8382780ea4",
"clientSecret": "5CUEwrmkEBsUwwOzFrHGczDI3lOtSCcpSJOK6Q338FI",
"callbackSecret": ""
},
{
"clientId": "b43fdb1a-fa01-4955-93df-a70e4301fb1d",
"clientSecret": "0-Zwrv3ptTwvUBpX-N-FwZSYHxPwrZ1AAfozBukKwEI",
"callbackSecret": ""
},
{
"clientId": "20175c2b-c4dd-4a01-99b1-3a08436881a1",
"clientSecret": "KV2qd7qc5n-xESB6dvfrTlMDx2BWHJd5hXJ6pKKnbEQ",
"callbackSecret": ""
}
],
"destination": {
"id": "57fe8bbe-67a6-433a-b9c6-7efaa5e8b8b7",
"serviceIdentifier": "urn:de:fim:leika:leistung:99400048079000",
......
......@@ -59,8 +59,7 @@ public static class Container {
return builder.Build();
}
private static Mock<IDestinationService>
CreateDestinationService(IFitConnectSettings settings) {
private static Mock<IDestinationService> CreateDestinationService(IFitConnectSettings settings) {
var mock = new Mock<IDestinationService>();
mock.Setup(x => x.GetPublicKey(It.IsAny<Guid>()))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment