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

feat: updating packages #69

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -1,6 +1,5 @@
using Herald.MessageQueue.AzureStorageQueue;

using Microsoft.Azure.Storage.Queue;
using Microsoft.Extensions.Diagnostics.HealthChecks;

using System.Threading.Tasks;
Expand All @@ -9,20 +8,27 @@ namespace Herald.MessageQueue.HealthCheck.AzureStorageQueue
{
public class HealthCheckAzureStorageQueue<T> : HealthCheckBase<T> where T : MessageBase
{
private readonly CloudQueueClient _cloudQueueClient;
private readonly string _queueName;
private readonly IQueueClientFactory _queueClientFactory;
private readonly MessageQueueOptions _options;

public HealthCheckAzureStorageQueue(CloudQueueClient cloudQueueClient, IMessageQueueInfo info, int healthCheckInterval = 1) : base(healthCheckInterval)
public HealthCheckAzureStorageQueue(IQueueClientFactory queueClientFactory, MessageQueueOptions options, IMessageQueueInfo info, int healthCheckInterval = 1) : base(healthCheckInterval)
{
_cloudQueueClient = cloudQueueClient;
_queueName = info.GetQueueName(typeof(T));
_options = options;
_queueClientFactory = queueClientFactory;
}

protected override async Task<HealthCheckResult> ProcessHealthCheck(HealthCheckContext context)
{
var queue = _cloudQueueClient.GetQueueReference(_queueName);
var queueClient = _queueClientFactory.Create(_options.ConnectionString, _queueName);

return await Task.FromResult(HealthCheckResult.Healthy());
var queueExists = await queueClient.ExistsAsync();

if (queueExists)
return await Task.FromResult(HealthCheckResult.Healthy());

return await Task.FromResult(HealthCheckResult.Unhealthy());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Herald.MessageQueue.AzureStorageQueue" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="3.0.0" />
<PackageReference Include="Herald.MessageQueue.AzureStorageQueue" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Herald.MessageQueue.Kafka" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="3.0.0" />
<PackageReference Include="Herald.MessageQueue.Kafka" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Herald.MessageQueue.RabbitMq" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="3.0.0" />
<PackageReference Include="Herald.MessageQueue.RabbitMq" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Herald.MessageQueue.Sqs" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="3.0.0" />
<PackageReference Include="Herald.MessageQueue.Sqs" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Herald.MessageQueue.AzureStorageQueue;
using Azure.Storage.Queues;
using Azure;
using Herald.MessageQueue.AzureStorageQueue;
using Herald.MessageQueue.HealthCheck.AzureStorageQueue;

using Microsoft.Azure.Storage.Queue;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
Expand All @@ -11,9 +12,11 @@

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using Xunit;
using Newtonsoft.Json;

namespace Herald.MessageQueue.HealthCheck.Tests.AzureStorageQueue
{
Expand All @@ -25,14 +28,30 @@ private class TestMessage : MessageBase { };
public void ShouldAddHealthCheck()
{
//Arrange
var clouldQueueClientMock = new Mock<CloudQueueClient>(MockBehavior.Loose, new Uri("http://localhost"), null, null);
var mockMessageReponse = new Mock<Response<bool>>();
mockMessageReponse
.SetupGet(m => m.Value).Returns(true)
.Verifiable();

var queueClientMock = new Mock<QueueClient>();
queueClientMock
.Setup(x => x.ExistsAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(mockMessageReponse.Object)
.Verifiable();

var queueClientFactoryMock = new Mock<IQueueClientFactory>();
queueClientFactoryMock
.Setup(x => x.Create(It.IsAny<string>(), It.IsAny<string>()))
.Returns(queueClientMock.Object)
.Verifiable();

var serviceCollection = new ServiceCollection();
var config = new ConfigurationBuilder().Build();

serviceCollection.AddScoped<IConfiguration>(x => config)
.AddScoped(x => new MessageQueueOptions())
.AddScoped(x => clouldQueueClientMock.Object)
.AddScoped<IMessageQueueInfo, MessageQueueInfo>()
.AddScoped(x => queueClientFactoryMock.Object)
.AddScoped<IMessageQueueInfo, MessageQueueInfo>()
.AddHealthChecks()
.AddAzureStorageQueueCheck<TestMessage>();
var serviceProvider = serviceCollection.BuildServiceProvider();
Expand All @@ -50,12 +69,29 @@ public void ShouldAddHealthCheck()
public async Task ShouldBeHealthy()
{
//Arrange
var clouldQueueClientMock = new Mock<CloudQueueClient>(MockBehavior.Loose, new Uri("http://localhost"), null, null);
var mockMessageReponse = new Mock<Response<bool>>();
mockMessageReponse
.SetupGet(m => m.Value).Returns(true)
.Verifiable();

var queueClientMock = new Mock<QueueClient>();
queueClientMock
.Setup(x => x.ExistsAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(mockMessageReponse.Object)
.Verifiable();

var queueClientFactoryMock = new Mock<IQueueClientFactory>();
queueClientFactoryMock
.Setup(x => x.Create(It.IsAny<string>(), It.IsAny<string>()))
.Returns(queueClientMock.Object)
.Verifiable();

var messageQueueOptions = new MessageQueueOptions();

var messageQueueInfoMock = new Mock<IMessageQueueInfo>();
messageQueueInfoMock.Setup(x => x.GetQueueName(It.IsAny<Type>())).Returns(typeof(TestMessage).Name);

var healthCheck = new HealthCheckAzureStorageQueue<TestMessage>(clouldQueueClientMock.Object, messageQueueInfoMock.Object, 0);
var healthCheck = new HealthCheckAzureStorageQueue<TestMessage>(queueClientFactoryMock.Object, messageQueueOptions, messageQueueInfoMock.Object, 0);
var healthCheckContext = new HealthCheckContext()
{
Registration = new HealthCheckRegistration(nameof(TestMessage), healthCheck, default, default)
Expand All @@ -72,15 +108,29 @@ public async Task ShouldBeHealthy()
public async Task ShouldBeUnhealthy()
{
//Arrange
var clouldQueueClientMock = new Mock<CloudQueueClient>(MockBehavior.Loose, new Uri("http://localhost"), null, null);
clouldQueueClientMock
.Setup(x => x.GetQueueReference(It.IsAny<string>()))
.Throws<Exception>();
var mockMessageReponse = new Mock<Response<bool>>();
mockMessageReponse
.SetupGet(m => m.Value).Returns(false)
.Verifiable();

var queueClientMock = new Mock<QueueClient>();
queueClientMock
.Setup(x => x.ExistsAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(mockMessageReponse.Object)
.Verifiable();

var queueClientFactoryMock = new Mock<IQueueClientFactory>();
queueClientFactoryMock
.Setup(x => x.Create(It.IsAny<string>(), It.IsAny<string>()))
.Returns(queueClientMock.Object)
.Verifiable();

var messageQueueOptions = new MessageQueueOptions();

var messageQueueInfoMock = new Mock<IMessageQueueInfo>();
messageQueueInfoMock.Setup(x => x.GetQueueName(It.IsAny<Type>())).Returns(typeof(TestMessage).Name);

var healthCheck = new HealthCheckAzureStorageQueue<TestMessage>(clouldQueueClientMock.Object, messageQueueInfoMock.Object, 0);
var healthCheck = new HealthCheckAzureStorageQueue<TestMessage>(queueClientFactoryMock.Object, messageQueueOptions, messageQueueInfoMock.Object, 0);
var healthCheckContext = new HealthCheckContext()
{
Registration = new HealthCheckRegistration(nameof(TestMessage), healthCheck, default, default)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>

<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.8.1">
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="JUnitTestLogger" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="Moq" Version="4.14.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Moq" Version="4.18.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Herald.MessageQueue" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="3.1.4" />
<PackageReference Include="Herald.MessageQueue" Version="11.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="3.1.0" />
</ItemGroup>

</Project>