Skip to content

Commit

Permalink
more cleanup and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-merkle committed Jan 8, 2024
1 parent 60661af commit 9374961
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/jjm.one.RabbitMqClientWrapper.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
global using Xunit;
global using FluentAssertions;
global using FluentAssertions;
global using Moq;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using jjm.one.RabbitMqClientWrapper.types;
using jjm.one.RabbitMqClientWrapper.types.events;
using Microsoft.Extensions.Logging;
using Moq;

namespace jjm.one.RabbitMqClientWrapper.Tests.main;

Expand All @@ -19,16 +18,15 @@ public class RmqcWrapperTests
public RmqcWrapperTests()
{
_rmqcCoreMock = new Mock<IRmqcCore>();
_rmqcWrapperLoggingMock = new Mock<ILogger<RmqcWrapper>>();
Mock<ILogger<RmqcWrapper>> rmqcWrapperLoggingMock = new();

_sut = new RmqcWrapper(_rmqcCoreMock.Object, _rmqcWrapperLoggingMock.Object);
_sut = new RmqcWrapper(_rmqcCoreMock.Object, rmqcWrapperLoggingMock.Object);
}

#region private members

private readonly RmqcWrapper _sut;
private readonly Mock<IRmqcCore> _rmqcCoreMock;
private readonly Mock<ILogger<RmqcWrapper>> _rmqcWrapperLoggingMock;

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using jjm.one.RabbitMqClientWrapper.types.events;
using jjm.one.RabbitMqClientWrapper.types.exceptions;
using Microsoft.Extensions.Logging;
using Moq;
using RabbitMQ.Client;

namespace jjm.one.RabbitMqClientWrapper.Tests.main.core;
Expand Down Expand Up @@ -867,7 +866,6 @@ public void RmqcWrapperTest_ReadMsgTest2()
{
// arrange
var bgr = new BasicGetResult(42, false, "TEST-EX", "TEST-RK", 69, null, null);
var m = new RmqcMessage(bgr);
_connectionMock.Setup(x => x.IsOpen).Returns(false);
_channelMock.Setup(x => x.IsOpen).Returns(false);
_channelMock.Setup(x => x.BasicGet(It.IsAny<string>(), It.IsAny<bool>())).Returns(bgr);
Expand All @@ -891,8 +889,6 @@ public void RmqcWrapperTest_ReadMsgTest2()
public void RmqcWrapperTest_ReadMsgTest3()
{
// arrange
var bgr = new BasicGetResult(42, false, "TEST-EX", "TEST-RK", 69, null, null);
var m = new RmqcMessage(bgr);
_connectionMock.Setup(x => x.IsOpen).Returns(true);
_channelMock.Setup(x => x.IsOpen).Returns(true);
_channelMock.Setup(x => x.BasicGet(It.IsAny<string>(), It.IsAny<bool>())).Returns(value: null!);
Expand Down Expand Up @@ -1070,13 +1066,12 @@ public void RmqcWrapperTest_WaitForWriteConfirmTest2()
public void RmqcWrapperTest_QueuedMsgsTest1()
{
// arrange
uint? a = 0;
_connectionMock.Setup(x => x.IsOpen).Returns(true);
_channelMock.Setup(x => x.IsOpen).Returns(true);
_channelMock.Setup(x => x.MessageCount(It.IsAny<string>())).Returns(42);

// act
var res = _sut.QueuedMsgs(out a, out var resExc);
var res = _sut.QueuedMsgs(out var a, out var resExc);

// assert
_connectionMock.Verify(x => x.IsOpen, Times.AtMostOnce);
Expand All @@ -1094,13 +1089,12 @@ public void RmqcWrapperTest_QueuedMsgsTest1()
public void RmqcWrapperTest_QueuedMsgsTest2()
{
// arrange
uint? a = 0;
_connectionMock.Setup(x => x.IsOpen).Returns(false);
_channelMock.Setup(x => x.IsOpen).Returns(false);
_channelMock.Setup(x => x.MessageCount(It.IsAny<string>())).Returns(42);

// act
var res = _sut.QueuedMsgs(out a, out var resExc);
var res = _sut.QueuedMsgs(out var a, out var resExc);

// assert
_connectionMock.Verify(x => x.IsOpen, Times.AtMostOnce);
Expand Down
4 changes: 2 additions & 2 deletions src/jjm.one.RabbitMqClientWrapper.Tests/types/MessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void MessageTest_RoutingKeySetTest1()
}

/// <summary>
/// Tests the setter of the RoutingKey member. (Testm2)
/// Tests the setter of the RoutingKey member. (Test 2)
/// </summary>
[Fact]
public void MessageTest_RoutingKeySetTest2()
Expand Down Expand Up @@ -233,7 +233,7 @@ public void MessageTest_BodySetTest1()
{
// arrange
var b = Array.Empty<byte>();
;

var m = new RmqcMessage(
new BasicGetResult(42, true, "TEST-EX", "TEST-RK", 69,
null, null))
Expand Down
14 changes: 7 additions & 7 deletions src/jjm.one.RabbitMqClientWrapper/di/core/RmqcCoreDi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace jjm.one.RabbitMqClientWrapper.di.core;
/// </summary>
internal static class RmqcCoreDi
{
/// <summary>
/// Adds all dependencies ot the <see cref="RmqcCore" /> class to a <see cref="ServiceCollection" />.
/// </summary>
/// <param name="services"></param>
/// <param name="settings"></param>
/// <returns></returns>
public static IServiceCollection AddRmqcCore(this IServiceCollection services, RmqcSettings settings)
/// <summary>
/// Adds all dependencies ot the <see cref="RmqcCore" /> class to a <see cref="ServiceCollection" />.
/// </summary>
/// <param name="services"></param>
/// <param name="settings"></param>
/// <returns></returns>
public static IServiceCollection AddRmqcCore(this IServiceCollection services, RmqcSettings settings)
{
services.AddSingleton(settings);
services.AddScoped<IRmqcCore>(sp => ActivatorUtilities.CreateInstance<RmqcCore>(sp));
Expand Down
5 changes: 1 addition & 4 deletions src/jjm.one.RabbitMqClientWrapper/main/RmqcWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,8 @@ public bool ReConnect(out Exception? exception)
var sw = new Stopwatch();
sw.Start();

// init output
var res = true;

// disconnect
res = Disconnect(out exception);
var res = Disconnect(out exception);

if (res)
{
Expand Down
2 changes: 1 addition & 1 deletion src/jjm.one.RabbitMqClientWrapper/types/RmqcMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ internal set

_wasModified = value;

OnChanged(new List<string> { "This information is currently not supported!" });
OnChanged(["This information is currently not supported!"]);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/jjm.one.RabbitMqClientWrapper/types/RmqcSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ public RmqcSettings(string? hostname = null, int? port = null, string? username
public override bool Equals(object? obj)
{
//Check for null and compare run-time types.
if (obj == null || GetType() != obj.GetType())
{
return false;
}
if (obj == null || GetType() != obj.GetType()) return false;

var s = (RmqcSettings)obj;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public ErrorOccurredEventArgs(Exception? exception = null)
/// <summary>
/// The exception which may have occurred.
/// </summary>
// ReSharper disable once UnusedAutoPropertyAccessor.Global
public Exception? Exception { get; set; }

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MsgChangedEventArgs : EventArgs
/// <param name="changedMembers"></param>
public MsgChangedEventArgs(List<string>? changedMembers)
{
ChangedMembers = changedMembers ?? new List<string>();
ChangedMembers = changedMembers ?? [];
}

#endregion
Expand All @@ -28,6 +28,7 @@ public MsgChangedEventArgs(List<string>? changedMembers)
/// <summary>
/// The list of the names of all changed members.
/// </summary>
// ReSharper disable once UnusedAutoPropertyAccessor.Global
public List<string> ChangedMembers { get; set; }

#endregion
Expand Down

0 comments on commit 9374961

Please sign in to comment.