diff --git a/source/Api/OutgoingMessages/MessageCountRequestListener.cs b/source/Api/OutgoingMessages/MessageCountRequestListener.cs deleted file mode 100644 index 7a0f07fb23..0000000000 --- a/source/Api/OutgoingMessages/MessageCountRequestListener.cs +++ /dev/null @@ -1,58 +0,0 @@ -// 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.Globalization; -using System.IO; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using Application.Configuration.Authentication; -using Application.OutgoingMessages.MessageCount; -using MediatR; -using Microsoft.Azure.Functions.Worker; -using Microsoft.Azure.Functions.Worker.Http; - -namespace Api.OutgoingMessages; - -public class MessageCountRequestListener -{ - private readonly IMediator _mediator; - private readonly IMarketActorAuthenticator _marketActorAuthenticator; - - public MessageCountRequestListener(IMediator mediator, IMarketActorAuthenticator marketActorAuthenticator) - { - _mediator = mediator; - _marketActorAuthenticator = marketActorAuthenticator; - } - - [Function("MessageCountRequestListener")] - public async Task RunAsync( - [HttpTrigger( - AuthorizationLevel.Anonymous, - "get", - Route = "messagecount")] - HttpRequestData request, - FunctionContext executionContext) - { - var result = await _mediator.Send( - new MessageCountQuery(_marketActorAuthenticator.CurrentIdentity.Number)) - .ConfigureAwait(false); - - var response = HttpResponseData.CreateResponse(request); - response.Body = new MemoryStream(Encoding.UTF8.GetBytes(result.Data!.MessageCount.ToString(CultureInfo.InvariantCulture))); - response.Headers.Add("content-type", "application/xml"); - response.StatusCode = HttpStatusCode.OK; - return response; - } -} diff --git a/source/Application/OutgoingMessages/MessageCount/MessageCountRequestHandler.cs b/source/Application/OutgoingMessages/MessageCount/MessageCountRequestHandler.cs deleted file mode 100644 index e999875b5c..0000000000 --- a/source/Application/OutgoingMessages/MessageCount/MessageCountRequestHandler.cs +++ /dev/null @@ -1,43 +0,0 @@ -// 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.Threading; -using System.Threading.Tasks; -using Application.Configuration.Queries; -using Domain.Actors; -using MediatR; - -namespace Application.OutgoingMessages.MessageCount; - -public class MessageCountRequestHandler : IRequestHandler> -{ - private readonly IEnqueuedMessages _enqueuedMessages; - - public MessageCountRequestHandler(IEnqueuedMessages enqueuedMessages) - { - _enqueuedMessages = enqueuedMessages; - } - - public async Task> Handle(MessageCountQuery request, CancellationToken cancellationToken) - { - ArgumentNullException.ThrowIfNull(request); - var messageCount = await _enqueuedMessages.GetAvailableMessageCountAsync(request.ActorNumber).ConfigureAwait(false); - return new QueryResult(new MessageCountData(messageCount)); - } -} - -public record MessageCountQuery(ActorNumber ActorNumber) : IQuery>; - -public record MessageCountData(int MessageCount); diff --git a/source/Infrastructure/OutgoingMessages/Peek/PeekConfiguration.cs b/source/Infrastructure/OutgoingMessages/Peek/PeekConfiguration.cs index 4b599b13fd..a1bb4d59f7 100644 --- a/source/Infrastructure/OutgoingMessages/Peek/PeekConfiguration.cs +++ b/source/Infrastructure/OutgoingMessages/Peek/PeekConfiguration.cs @@ -15,7 +15,6 @@ using System; using Application.Configuration.Queries; using Application.OutgoingMessages; -using Application.OutgoingMessages.MessageCount; using Application.OutgoingMessages.Peek; using MediatR; using Microsoft.Extensions.DependencyInjection; @@ -28,7 +27,6 @@ internal static void Configure(IServiceCollection services, IBundleConfiguration { services.AddTransient(); services.AddTransient, PeekRequestHandler>(); - services.AddTransient>, MessageCountRequestHandler>(); services.AddScoped(); services.AddScoped(_ => bundleConfiguration); diff --git a/source/IntegrationTests/Application/OutgoingMessages/WhenMessageCountIsRequestedTests.cs b/source/IntegrationTests/Application/OutgoingMessages/WhenMessageCountIsRequestedTests.cs deleted file mode 100644 index c4fd9678d4..0000000000 --- a/source/IntegrationTests/Application/OutgoingMessages/WhenMessageCountIsRequestedTests.cs +++ /dev/null @@ -1,77 +0,0 @@ -// 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.Threading.Tasks; -using Application.OutgoingMessages.MessageCount; -using Domain.Actors; -using Domain.OutgoingMessages; -using IntegrationTests.Application.IncomingMessages; -using IntegrationTests.Fixtures; -using Xunit; - -namespace IntegrationTests.Application.OutgoingMessages; - -public class WhenMessageCountIsRequestedTests : TestBase -{ - public WhenMessageCountIsRequestedTests(DatabaseFixture databaseFixture) - : base(databaseFixture) - { - } - - [Fact] - public async Task When_no_messages_are_available_return_zero() - { - var result = await QueryAsync(CreateMessageCountRequest(SampleData.NewEnergySupplierNumber)) - .ConfigureAwait(false); - - Assert.Equal(0, result.Data!.MessageCount); - } - - [Fact] - public async Task When_messages_are_available_return_count() - { - await GivenAMoveInTransactionHasBeenAccepted().ConfigureAwait(false); - - var result = await QueryAsync(CreateMessageCountRequest(SampleData.NewEnergySupplierNumber)) - .ConfigureAwait(false); - - Assert.Equal(1, result.Data!.MessageCount); - } - - private static MessageCountQuery CreateMessageCountRequest(string actorNumber) - { - return new MessageCountQuery(ActorNumber.Create(SampleData.NewEnergySupplierNumber)); - } - - private static IncomingMessageBuilder MessageBuilder() - { - return new IncomingMessageBuilder() - .WithEnergySupplierId(SampleData.NewEnergySupplierNumber) - .WithMessageId(SampleData.OriginalMessageId) - .WithTransactionId(SampleData.TransactionId); - } - - private async Task GivenAMoveInTransactionHasBeenAccepted() - { - var incomingMessage = MessageBuilder() - .WithMarketEvaluationPointId(SampleData.MeteringPointNumber) - .WithProcessType(ProcessType.MoveIn) - .WithReceiver(SampleData.ReceiverId) - .WithSenderId(SampleData.SenderId) - .WithConsumerName(SampleData.ConsumerName) - .Build(); - - await InvokeCommandAsync(incomingMessage).ConfigureAwait(false); - } -}