Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/bbf tests #3648

Merged
merged 7 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2020 Energinet DataHub A/S
//
// Licensed under the Apache License, Version 2.0 (the "License2");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Energinet.DataHub.WebApi.Clients.MarketParticipant.v1;
using Energinet.DataHub.WebApi.Tests.Extensions;
using Energinet.DataHub.WebApi.Tests.TestServices;
using Moq;
using Xunit;

namespace Energinet.DataHub.WebApi.Tests.Integration.GraphQL.MessageDelegation;

public class MessageDelegationStatusTests
{
private static readonly Guid _actorId = new("9d1b5e2a-3c4e-4f8b-9a6e-7f2b6c8d9e1f");

private static readonly string _messageDelegationQuery =
$$"""
{
delegationsForActor(actorId: "{{_actorId}}") {
id
status
}
}
""";

private static readonly DateTimeOffset _sameDate = DateTimeOffset.Now.AddDays(5);
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.

public static IEnumerable<object[]> GetTestCases()
{
yield return new object[] { "Cancelled same date", _sameDate, _sameDate };
yield return new object[] { "Cancelled", DateTimeOffset.Now.AddDays(5), DateTimeOffset.Now.AddDays(4) };
yield return new object[] { "Active with end", DateTimeOffset.Now.AddDays(-5), DateTimeOffset.Now.AddDays(10) };
yield return new object[] { "Active without end", DateTimeOffset.Now.AddDays(-5), null };
yield return new object[] { "Expired", DateTimeOffset.Now.AddDays(-5), DateTimeOffset.Now.AddDays(-1) };
}

#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.

[Theory]
[MemberData(nameof(GetTestCases))]
public async Task MessageDelegationWithStatus(string testname, DateTimeOffset validFrom, DateTimeOffset? validTo) =>
await ExecuteTestAsync(testname, validFrom, validTo);

private static async Task ExecuteTestAsync(string testname, DateTimeOffset validFrom, DateTimeOffset? validTo)
{
var server = new GraphQLTestService();

server.MarketParticipantClientV1Mock
.Setup(x => x.ActorDelegationsGetAsync(_actorId, default))
.ReturnsAsync(new GetDelegationsForActorResponse()
{
Delegations = new[]
{
new ProcessDelegationDto()
{
Id = Guid.NewGuid(),
DelegatedBy = Guid.NewGuid(),
Process = DelegatedProcess.ReceiveEnergyResults,
Periods = new[]
{
new DelegationPeriodDto()
{
DelegatedTo = Guid.NewGuid(),
GridAreaId = Guid.NewGuid(),
Id = Guid.NewGuid(),
StartsAt = validFrom,
StopsAt = validTo,
},
},
},
},
});

var result = await server.ExecuteRequestAsync(b => b.SetQuery(_messageDelegationQuery));

await result.MatchSnapshotAsync(testname);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": {
"delegationsForActor": [
{
"id": "da2e97bd-94aa-43d6-ba2f-a93679d50d35",
"status": "ACTIVE"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": {
"delegationsForActor": [
{
"id": "131680bd-4c00-45e1-ab7e-7cc1fc4580e1",
"status": "ACTIVE"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": {
"delegationsForActor": [
{
"id": "43652030-d1c8-4aa0-9639-0dd201b22f3c",
"status": "CANCELLED"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": {
"delegationsForActor": [
{
"id": "57f95388-4c4a-4d8f-8aba-188997ba6c18",
"status": "CANCELLED"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": {
"delegationsForActor": [
{
"id": "73b4c7ba-542e-4ca4-a3ba-bbc0dc5b5176",
"status": "EXPIRED"
}
]
}
}
Loading