diff --git a/Directory.Build.props b/Directory.Build.props
new file mode 100644
index 0000000..1940226
--- /dev/null
+++ b/Directory.Build.props
@@ -0,0 +1,5 @@
+
+
+ 11
+
+
diff --git a/Hangfire.Console.sln b/Hangfire.Console.sln
index b45476e..2d0e73d 100644
--- a/Hangfire.Console.sln
+++ b/Hangfire.Console.sln
@@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
dashboard.png = dashboard.png
README.md = README.md
+ Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CBD2EEC6-826C-4477-B8F7-EADE2D944B74}"
diff --git a/tests/Hangfire.Console.Tests/ConsoleExtensionsFacts.cs b/tests/Hangfire.Console.Tests/ConsoleExtensionsFacts.cs
index 4d77a80..141b950 100644
--- a/tests/Hangfire.Console.Tests/ConsoleExtensionsFacts.cs
+++ b/tests/Hangfire.Console.Tests/ConsoleExtensionsFacts.cs
@@ -42,7 +42,7 @@ public void WriteLine_Writes_IfConsoleCreated()
var context = CreatePerformContext();
context.Items["ConsoleContext"] = CreateConsoleContext(context);
- ConsoleExtensions.WriteLine(context, "");
+ context.WriteLine("");
_transaction.Verify(x => x.Commit());
}
@@ -52,7 +52,7 @@ public void WriteLine_DoesNotFail_IfConsoleNotCreated()
{
var context = CreatePerformContext();
- ConsoleExtensions.WriteLine(context, "");
+ context.WriteLine("");
_transaction.Verify(x => x.Commit(), Times.Never);
}
@@ -72,7 +72,7 @@ public void WriteProgressBar_ReturnsProgressBar_IfConsoleCreated()
var context = CreatePerformContext();
context.Items["ConsoleContext"] = CreateConsoleContext(context);
- var progressBar = ConsoleExtensions.WriteProgressBar(context);
+ var progressBar = context.WriteProgressBar();
Assert.IsType(progressBar);
_transaction.Verify(x => x.Commit());
@@ -83,16 +83,17 @@ public void WriteProgressBar_ReturnsNoOp_IfConsoleNotCreated()
{
var context = CreatePerformContext();
- var progressBar = ConsoleExtensions.WriteProgressBar(context);
+ var progressBar = context.WriteProgressBar();
Assert.IsType(progressBar);
_transaction.Verify(x => x.Commit(), Times.Never);
}
+ // ReSharper disable once RedundantDisableWarningComment
#pragma warning disable xUnit1013
- public static void JobMethod()
+ // ReSharper disable once MemberCanBePrivate.Global
+ public static void JobMethod() {
#pragma warning restore xUnit1013
- {
}
private PerformContext CreatePerformContext()
diff --git a/tests/Hangfire.Console.Tests/Dashboard/ConsoleRendererFacts.cs b/tests/Hangfire.Console.Tests/Dashboard/ConsoleRendererFacts.cs
index ed85666..79cdda4 100644
--- a/tests/Hangfire.Console.Tests/Dashboard/ConsoleRendererFacts.cs
+++ b/tests/Hangfire.Console.Tests/Dashboard/ConsoleRendererFacts.cs
@@ -15,15 +15,8 @@ namespace Hangfire.Console.Tests.Dashboard
{
public class ConsoleRendererFacts
{
- private readonly ConsoleId _consoleId;
- private readonly Mock _storage;
-
- public ConsoleRendererFacts()
- {
- _consoleId = new ConsoleId("1", new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));
-
- _storage = new Mock();
- }
+ private readonly ConsoleId _consoleId = new("1", new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));
+ private readonly Mock _storage = new();
[Fact]
public void RenderText_Empty()
@@ -348,7 +341,7 @@ private void SetupStorage(StateData stateData, params ConsoleLine[] lines)
_storage.Setup(x => x.GetLineCount(It.IsAny()))
.Returns(lines.Length);
_storage.Setup(x => x.GetLines(It.IsAny(), It.IsAny(), It.IsAny()))
- .Returns((ConsoleId id, int start, int end) => lines.Where((x, i) => i >= start && i <= end));
+ .Returns((ConsoleId _, int start, int end) => lines.Where((_, i) => i >= start && i <= end));
}
}
}
diff --git a/tests/Hangfire.Console.Tests/Serialization/ConsoleIdFacts.cs b/tests/Hangfire.Console.Tests/Serialization/ConsoleIdFacts.cs
index 28cee82..c95c82d 100644
--- a/tests/Hangfire.Console.Tests/Serialization/ConsoleIdFacts.cs
+++ b/tests/Hangfire.Console.Tests/Serialization/ConsoleIdFacts.cs
@@ -6,7 +6,7 @@ namespace Hangfire.Console.Tests.Serialization
{
public class ConsoleIdFacts
{
- private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+ private static readonly DateTime UnixEpoch = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
[Fact]
public void Ctor_ThrowsAnException_WhenJobIdIsNull()
@@ -23,17 +23,17 @@ public void Ctor_ThrowsAnException_WhenJobIdIsEmpty()
[Fact]
public void Ctor_ThrowsAnException_WhenTimestampBeforeEpoch()
{
- Assert.Throws("timestamp",
+ Assert.Throws("timestamp",
() => new ConsoleId("123", UnixEpoch));
}
[Fact]
public void Ctor_ThrowsAnException_WhenTimestampAfterEpochPlusMaxInt()
{
- Assert.Throws("timestamp",
+ Assert.Throws("timestamp",
() => new ConsoleId("123", UnixEpoch.AddSeconds(int.MaxValue).AddSeconds(1)));
}
-
+
[Fact]
public void SerializesCorrectly()
{
diff --git a/tests/Hangfire.Console.Tests/Server/ConsoleContextFacts.cs b/tests/Hangfire.Console.Tests/Server/ConsoleContextFacts.cs
index 84d3ddb..89325a0 100644
--- a/tests/Hangfire.Console.Tests/Server/ConsoleContextFacts.cs
+++ b/tests/Hangfire.Console.Tests/Server/ConsoleContextFacts.cs
@@ -9,12 +9,7 @@ namespace Hangfire.Console.Tests.Server
{
public class ConsoleContextFacts
{
- private readonly Mock _storage;
-
- public ConsoleContextFacts()
- {
- _storage = new Mock();
- }
+ private readonly Mock _storage = new();
[Fact]
public void Ctor_ThrowsException_IfConsoleIdIsNull()
@@ -34,7 +29,7 @@ public void Ctor_ThrowsException_IfStorageIsNull()
public void Ctor_InitializesConsole()
{
var consoleId = new ConsoleId("1", new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));
- var context = new ConsoleContext(consoleId, _storage.Object);
+ _ = new ConsoleContext(consoleId, _storage.Object);
_storage.Verify(x => x.InitConsole(consoleId));
}
@@ -83,7 +78,7 @@ public void WriteLine_ReallyAddsLine()
context.WriteLine("line", null);
- _storage.Verify(x => x.AddLine(It.IsAny(), It.Is(_ => _.Message == "line" && _.TextColor == null)));
+ _storage.Verify(x => x.AddLine(It.IsAny(), It.Is(l => l.Message == "line" && l.TextColor == null)));
}
[Fact]
@@ -94,7 +89,7 @@ public void WriteLine_ReallyAddsLineWithColor()
context.WriteLine("line", ConsoleTextColor.Red);
- _storage.Verify(x => x.AddLine(It.IsAny(), It.Is(_ => _.Message == "line" && _.TextColor == ConsoleTextColor.Red)));
+ _storage.Verify(x => x.AddLine(It.IsAny(), It.Is(l => l.Message == "line" && l.TextColor == ConsoleTextColor.Red)));
}
[Fact]
@@ -108,7 +103,7 @@ public void WriteProgressBar_WritesDefaults_AndReturnsNonNull()
_storage.Verify(x => x.AddLine(It.IsAny(), It.IsAny()));
Assert.NotNull(progressBar);
}
-
+
[Fact]
public void WriteProgressBar_WritesName_AndReturnsNonNull()
{
@@ -117,10 +112,10 @@ public void WriteProgressBar_WritesName_AndReturnsNonNull()
var progressBar = context.WriteProgressBar("test", 0, null);
- _storage.Verify(x => x.AddLine(It.IsAny(), It.Is(_ => _.ProgressName == "test")));
+ _storage.Verify(x => x.AddLine(It.IsAny(), It.Is(l => l.ProgressName == "test")));
Assert.NotNull(progressBar);
}
-
+
[Fact]
public void WriteProgressBar_WritesInitialValue_AndReturnsNonNull()
{
@@ -129,7 +124,8 @@ public void WriteProgressBar_WritesInitialValue_AndReturnsNonNull()
var progressBar = context.WriteProgressBar(null, 5, null);
- _storage.Verify(x => x.AddLine(It.IsAny(), It.Is(_ => _.ProgressValue == 5)));
+ _storage.Verify(x => x.AddLine(It.IsAny(), It.Is(l =>
+ l.ProgressValue.HasValue && Math.Abs(l.ProgressValue.Value - 5.0) < double.Epsilon)));
Assert.NotNull(progressBar);
}
@@ -141,7 +137,7 @@ public void WriteProgressBar_WritesProgressBarColor_AndReturnsNonNull()
var progressBar = context.WriteProgressBar(null, 0, ConsoleTextColor.Red);
- _storage.Verify(x => x.AddLine(It.IsAny(), It.Is(_ => _.TextColor == ConsoleTextColor.Red)));
+ _storage.Verify(x => x.AddLine(It.IsAny(), It.Is(l => l.TextColor == ConsoleTextColor.Red)));
Assert.NotNull(progressBar);
}
@@ -155,7 +151,7 @@ public void Expire_ReallyExpiresLines()
_storage.Verify(x => x.Expire(It.IsAny(), It.IsAny()));
}
-
+
[Fact]
public void FixExpiration_RequestsConsoleTtl_IgnoresIfNegative()
{
diff --git a/tests/Hangfire.Console.Tests/Server/ConsoleServerFilterFacts.cs b/tests/Hangfire.Console.Tests/Server/ConsoleServerFilterFacts.cs
index 564e5eb..8651674 100644
--- a/tests/Hangfire.Console.Tests/Server/ConsoleServerFilterFacts.cs
+++ b/tests/Hangfire.Console.Tests/Server/ConsoleServerFilterFacts.cs
@@ -167,7 +167,9 @@ public void CreatesConsoleContext_IfStateIsProcessing_ExpiresData_IfNotFollowsJo
_transaction.Verify(x => x.Commit());
}
+ // ReSharper disable once RedundantDisableWarningComment
#pragma warning disable xUnit1013
+ // ReSharper disable once MemberCanBePrivate.Global
public static void JobMethod(PerformContext context)
#pragma warning restore xUnit1013
{
@@ -178,9 +180,11 @@ public static void JobMethod(PerformContext context)
private IJobFilterProvider CreateJobFilterProvider(bool followJobRetention = false)
{
- var filters = new JobFilterCollection();
- filters.Add(new ConsoleServerFilter(new ConsoleOptions() { FollowJobRetentionPolicy = followJobRetention }));
- filters.Add(_otherFilter.Object);
+ var filters = new JobFilterCollection
+ {
+ new ConsoleServerFilter(new ConsoleOptions() { FollowJobRetentionPolicy = followJobRetention }),
+ _otherFilter.Object
+ };
return new JobFilterProviderCollection(filters);
}
@@ -190,8 +194,13 @@ private PerformContext CreatePerformContext()
_jobStorage.Object,
_connection.Object,
new BackgroundJob("1", Job.FromExpression(() => JobMethod(null)), DateTime.UtcNow),
- _cancellationToken.Object);
- context.Items["this"] = this;
+ _cancellationToken.Object)
+ {
+ Items =
+ {
+ ["this"] = this
+ }
+ };
return context;
}
diff --git a/tests/Hangfire.Console.Tests/States/ConsoleApplyStateFilterFacts.cs b/tests/Hangfire.Console.Tests/States/ConsoleApplyStateFilterFacts.cs
index 1e9c3d5..5b7f0f6 100644
--- a/tests/Hangfire.Console.Tests/States/ConsoleApplyStateFilterFacts.cs
+++ b/tests/Hangfire.Console.Tests/States/ConsoleApplyStateFilterFacts.cs
@@ -6,8 +6,6 @@
using Moq;
using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
using Xunit;
namespace Hangfire.Console.Tests.States
@@ -41,7 +39,7 @@ public ConsoleApplyStateFilterFacts()
public void UsesFinalJobExpirationTimeoutValue()
{
_otherFilter.Setup(x => x.OnStateApplied(It.IsAny(), It.IsAny()))
- .Callback((c, t) => c.JobExpirationTimeout = TimeSpan.FromSeconds(123));
+ .Callback((c, _) => c.JobExpirationTimeout = TimeSpan.FromSeconds(123));
_connection.Setup(x => x.GetJobData("1"))
.Returns(CreateJobData(ProcessingState.StateName));
_monitoring.Setup(x => x.JobDetails("1"))
@@ -152,6 +150,7 @@ private StateChangeContext CreateStateChangeContext(IState state)
return new StateChangeContext(_storage.Object, _connection.Object, "1", state);
}
+ // ReSharper disable once RedundantDisableWarningComment
#pragma warning disable xUnit1013
public static void JobMethod()
#pragma warning restore xUnit1013
diff --git a/tests/Hangfire.Console.Tests/Storage/ConsoleExpirationTransactionFacts.cs b/tests/Hangfire.Console.Tests/Storage/ConsoleExpirationTransactionFacts.cs
index f33baf1..723520a 100644
--- a/tests/Hangfire.Console.Tests/Storage/ConsoleExpirationTransactionFacts.cs
+++ b/tests/Hangfire.Console.Tests/Storage/ConsoleExpirationTransactionFacts.cs
@@ -9,16 +9,9 @@ namespace Hangfire.Console.Tests.Storage
{
public class ConsoleExpirationTransactionFacts
{
- private readonly ConsoleId _consoleId;
-
- private readonly Mock _transaction;
+ private readonly ConsoleId _consoleId = new("1", DateTime.UtcNow);
- public ConsoleExpirationTransactionFacts()
- {
- _consoleId = new ConsoleId("1", DateTime.UtcNow);
-
- _transaction = new Mock();
- }
+ private readonly Mock _transaction = new();
[Fact]
public void Ctor_ThrowsException_IfTransactionIsNull()
@@ -35,7 +28,7 @@ public void Dispose_ReallyDisposesTransaction()
_transaction.Verify(x => x.Dispose());
}
-
+
[Fact]
public void Expire_ThrowsException_IfConsoleIdIsNull()
{
@@ -43,7 +36,7 @@ public void Expire_ThrowsException_IfConsoleIdIsNull()
Assert.Throws("consoleId", () => expiration.Expire(null, TimeSpan.FromHours(1)));
}
-
+
[Fact]
public void Expire_ExpiresSetAndHash()
{
@@ -66,7 +59,7 @@ public void Persist_ThrowsException_IfConsoleIdIsNull()
Assert.Throws("consoleId", () => expiration.Persist(null));
}
-
+
[Fact]
public void Persist_PersistsSetAndHash()
{
diff --git a/tests/Hangfire.Console.Tests/Storage/ConsoleStorageFacts.cs b/tests/Hangfire.Console.Tests/Storage/ConsoleStorageFacts.cs
index f0d2869..6dfcfcc 100644
--- a/tests/Hangfire.Console.Tests/Storage/ConsoleStorageFacts.cs
+++ b/tests/Hangfire.Console.Tests/Storage/ConsoleStorageFacts.cs
@@ -276,7 +276,7 @@ public void GetLines_ReturnsRangeFromSet()
};
_connection.Setup(x => x.GetRangeFromSet(_consoleId.GetSetKey(), It.IsAny(), It.IsAny()))
- .Returns((string key, int start, int end) => lines.Where((x, i) => i >= start && i <= end).Select(SerializationHelper.Serialize).ToList());
+ .Returns((string _, int start, int end) => lines.Where((_, i) => i >= start && i <= end).Select(SerializationHelper.Serialize).ToList());
var storage = new ConsoleStorage(_connection.Object);
@@ -296,7 +296,7 @@ public void GetLines_ReturnsRangeFromOldSet_ForBackwardsCompatibility()
};
_connection.Setup(x => x.GetRangeFromSet(_consoleId.GetOldConsoleKey(), It.IsAny(), It.IsAny()))
- .Returns((string key, int start, int end) => lines.Where((x, i) => i >= start && i <= end).Select(SerializationHelper.Serialize).ToList());
+ .Returns((string _, int start, int end) => lines.Where((_, i) => i >= start && i <= end).Select(SerializationHelper.Serialize).ToList());
var storage = new ConsoleStorage(_connection.Object);
@@ -313,7 +313,7 @@ public void GetLines_ExpandsReferences()
};
_connection.Setup(x => x.GetRangeFromSet(_consoleId.GetSetKey(), It.IsAny(), It.IsAny()))
- .Returns((string key, int start, int end) => lines.Where((x, i) => i >= start && i <= end).Select(SerializationHelper.Serialize).ToList());
+ .Returns((string _, int start, int end) => lines.Where((_, i) => i >= start && i <= end).Select(SerializationHelper.Serialize).ToList());
_connection.Setup(x => x.GetValueFromHash(_consoleId.GetHashKey(), It.IsAny()))
.Returns("Dereferenced Line");
@@ -333,7 +333,7 @@ public void GetLines_ExpandsReferencesFromOldHash_ForBackwardsCompatibility()
};
_connection.Setup(x => x.GetRangeFromSet(_consoleId.GetOldConsoleKey(), It.IsAny(), It.IsAny()))
- .Returns((string key, int start, int end) => lines.Where((x, i) => i >= start && i <= end).Select(SerializationHelper.Serialize).ToList());
+ .Returns((string _, int start, int end) => lines.Where((_, i) => i >= start && i <= end).Select(SerializationHelper.Serialize).ToList());
_connection.Setup(x => x.GetValueFromHash(_consoleId.GetOldConsoleKey(), It.IsAny()))
.Returns("Dereferenced Line");
@@ -353,7 +353,7 @@ public void GetLines_HandlesHashException_WhenTryingToExpandReferences()
};
_connection.Setup(x => x.GetRangeFromSet(_consoleId.GetOldConsoleKey(), It.IsAny(), It.IsAny()))
- .Returns((string key, int start, int end) => lines.Where((x, i) => i >= start && i <= end).Select(SerializationHelper.Serialize).ToList());
+ .Returns((string _, int start, int end) => lines.Where((_, i) => i >= start && i <= end).Select(SerializationHelper.Serialize).ToList());
_connection.Setup(x => x.GetValueFromHash(_consoleId.GetOldConsoleKey(), It.IsAny()))
.Throws(new NotSupportedException());
diff --git a/tests/Hangfire.Console.Tests/Support/It2.cs b/tests/Hangfire.Console.Tests/Support/It2.cs
index aa38847..6e8299b 100644
--- a/tests/Hangfire.Console.Tests/Support/It2.cs
+++ b/tests/Hangfire.Console.Tests/Support/It2.cs
@@ -13,9 +13,9 @@ public static IEnumerable AnyIs(Expression> m
{
var predicate = match.Compile();
- return Match.Create>(
+ return Match.Create(
values => values.Any(predicate),
- () => It2.AnyIs(match));
+ () => AnyIs(match));
}
}
-}
\ No newline at end of file
+}