1
0

Updating to VS 2026

This commit is contained in:
2025-11-13 20:30:44 +01:00
parent 1096186c40
commit 1767b55c8a
29 changed files with 230 additions and 277 deletions

View File

@@ -8,6 +8,8 @@ namespace AMWD.Common.Tests.Utilities
[TestClass]
public class AsyncQueueTest
{
public TestContext TestContext { get; set; }
private Queue<TestElement> _internalQueue;
private TestElement _queueElement1;
@@ -52,7 +54,7 @@ namespace AMWD.Common.Tests.Utilities
queue.Enqueue(element);
// assert
Assert.AreEqual(1, _internalQueue.Count);
Assert.HasCount(1, _internalQueue);
Assert.AreEqual(_internalQueue.Count, queue.Count);
}
@@ -69,11 +71,11 @@ namespace AMWD.Common.Tests.Utilities
// act
var task = Task.Run(async () =>
{
await queue.WaitAsync();
await queue.WaitAsync(TestContext.CancellationToken);
available = true;
});
}, TestContext.CancellationToken);
queue.Enqueue(element);
task.Wait();
task.Wait(TestContext.CancellationToken);
// assert
Assert.IsTrue(available);
@@ -92,10 +94,10 @@ namespace AMWD.Common.Tests.Utilities
// act
var task = Task.Run(async () =>
{
callback = await queue.DequeueAsync();
});
callback = await queue.DequeueAsync(TestContext.CancellationToken);
}, TestContext.CancellationToken);
queue.Enqueue(element);
task.Wait();
task.Wait(TestContext.CancellationToken);
// assert
Assert.IsNotNull(callback);
@@ -118,8 +120,8 @@ namespace AMWD.Common.Tests.Utilities
queue.Enqueue(elements);
// assert
Assert.AreEqual(2, _internalQueue.Count);
Assert.AreEqual(queue.Count, _internalQueue.Count);
Assert.HasCount(2, _internalQueue);
Assert.HasCount(queue.Count, _internalQueue);
}
[TestMethod]
@@ -229,12 +231,12 @@ namespace AMWD.Common.Tests.Utilities
var task = Task.Run(async () =>
{
await Task.Delay(1000);
queue.Enqueue(new[] { _queueElement1, _queueElement2, _queueElement3 });
});
await Task.Delay(1000, TestContext.CancellationToken);
queue.Enqueue([_queueElement1, _queueElement2, _queueElement3]);
}, TestContext.CancellationToken);
// act
var item = await queue.DequeueAsync();
var item = await queue.DequeueAsync(TestContext.CancellationToken);
// assert
Assert.AreEqual(2, queue.Count);
@@ -251,17 +253,17 @@ namespace AMWD.Common.Tests.Utilities
var task = Task.Run(async () =>
{
await Task.Delay(1000);
queue.Enqueue(new[] { _queueElement1, _queueElement2, _queueElement3 });
});
await Task.Delay(1000, TestContext.CancellationToken);
queue.Enqueue([_queueElement1, _queueElement2, _queueElement3]);
}, TestContext.CancellationToken);
// act
var items = await queue.DequeueManyAsync(2);
var items = await queue.DequeueManyAsync(2, TestContext.CancellationToken);
// assert
Assert.AreEqual(1, queue.Count);
Assert.IsNotNull(items);
Assert.AreEqual(2, items.Length);
Assert.HasCount(2, items);
Assert.AreEqual(_queueElement1, items[0]);
Assert.AreEqual(_queueElement2, items[1]);
}
@@ -275,17 +277,17 @@ namespace AMWD.Common.Tests.Utilities
var task = Task.Run(async () =>
{
await Task.Delay(1000);
queue.Enqueue(new[] { _queueElement1, _queueElement2, _queueElement3 });
});
await Task.Delay(1000, TestContext.CancellationToken);
queue.Enqueue([_queueElement1, _queueElement2, _queueElement3]);
}, TestContext.CancellationToken);
// act
var items = await queue.DequeueAvailableAsync();
var items = await queue.DequeueAvailableAsync(cancellationToken: TestContext.CancellationToken);
// assert
Assert.AreEqual(0, queue.Count);
Assert.IsNotNull(items);
Assert.AreEqual(3, items.Length);
Assert.HasCount(3, items);
Assert.AreEqual(_queueElement1, items[0]);
Assert.AreEqual(_queueElement2, items[1]);
Assert.AreEqual(_queueElement3, items[2]);
@@ -300,34 +302,30 @@ namespace AMWD.Common.Tests.Utilities
var task = Task.Run(async () =>
{
await Task.Delay(1000);
queue.Enqueue(new[] { _queueElement1, _queueElement2, _queueElement3 });
});
await Task.Delay(1000, TestContext.CancellationToken);
queue.Enqueue([_queueElement1, _queueElement2, _queueElement3]);
}, TestContext.CancellationToken);
// act
var items = await queue.DequeueAvailableAsync(2);
var items = await queue.DequeueAvailableAsync(2, TestContext.CancellationToken);
// assert
Assert.AreEqual(1, queue.Count);
Assert.IsNotNull(items);
Assert.AreEqual(2, items.Length);
Assert.HasCount(2, items);
Assert.AreEqual(_queueElement1, items[0]);
Assert.AreEqual(_queueElement2, items[1]);
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public async Task ShouldThrowArumentOutOfRangeException()
{
// arrange
_internalQueue.Clear();
var queue = GetQueue();
// act
await queue.DequeueManyAsync(-2);
// assert - ArgumentOutOfRangeException expected
Assert.Fail();
// act & assert
await Assert.ThrowsExactlyAsync<ArgumentOutOfRangeException>(() => queue.DequeueManyAsync(-2, TestContext.CancellationToken));
}
private AsyncQueue<TestElement> GetQueue()

View File

@@ -114,8 +114,8 @@ namespace UnitTests.Common.Utilities
// assert
CollectionAssert.AreNotEqual(cipher1, cipher2);
Assert.AreEqual(24, cipher1.Length);
Assert.AreEqual(24, cipher2.Length);
Assert.HasCount(24, cipher1);
Assert.HasCount(24, cipher2);
CollectionAssert.AreEqual(plain, plain1);
CollectionAssert.AreEqual(plain, plain2);
}
@@ -228,8 +228,8 @@ namespace UnitTests.Common.Utilities
// assert
CollectionAssert.AreNotEqual(cipher1, cipher2);
Assert.AreEqual(16, cipher1.Length);
Assert.AreEqual(16, cipher2.Length);
Assert.HasCount(16, cipher1);
Assert.HasCount(16, cipher2);
CollectionAssert.AreEqual(plain, plain1);
CollectionAssert.AreEqual(plain, plain2);
}
@@ -368,11 +368,11 @@ namespace UnitTests.Common.Utilities
byte[] bytes3 = CryptographyHelper.GetRandomBytes(length3);
// assert
Assert.AreEqual(length1, bytes1.Length);
Assert.AreEqual(length2, bytes2.Length);
Assert.AreEqual(length3, bytes3.Length);
Assert.HasCount(length1, bytes1);
Assert.HasCount(length2, bytes2);
Assert.HasCount(length3, bytes3);
Assert.IsTrue(bytes1.Length == bytes2.Length);
Assert.HasCount(bytes2.Length, bytes1);
CollectionAssert.AreNotEqual(bytes1, bytes2);
}
@@ -394,8 +394,8 @@ namespace UnitTests.Common.Utilities
Assert.AreEqual(length2, str2.Length);
Assert.AreEqual(length3, str3.Length);
Assert.IsTrue(str1.Length == str2.Length);
Assert.IsFalse(str1 == str2);
Assert.HasCount(str2.Length, str2);
Assert.AreNotEqual(str2, str1);
}
[TestMethod]
@@ -412,7 +412,7 @@ namespace UnitTests.Common.Utilities
// assert
Assert.AreEqual(length, str1.Length);
Assert.AreEqual(length, str2.Length);
Assert.IsFalse(str1 == str2);
Assert.AreNotEqual(str2, str1);
Assert.IsFalse(RandomStringWithPoolRegex().IsMatch(str1));
Assert.IsFalse(RandomStringWithPoolRegex().IsMatch(str2));
}
@@ -532,7 +532,7 @@ namespace UnitTests.Common.Utilities
Assert.IsFalse(fileExistsBefore);
Assert.IsNotNull(helper);
Assert.IsTrue(fileExistsAfter);
Assert.IsTrue(!string.IsNullOrWhiteSpace(content));
Assert.IsFalse(string.IsNullOrWhiteSpace(content));
}
[TestMethod]

View File

@@ -9,6 +9,8 @@ namespace AMWD.Common.Tests.Utilities
[TestClass]
public class DelayedTaskTest
{
public TestContext TestContext { get; set; }
[TestMethod]
public void ShouldCreateNewDelayedTaskNotStarting()
{
@@ -113,7 +115,7 @@ namespace AMWD.Common.Tests.Utilities
var cts = new CancellationTokenSource(delay.Add(TimeSpan.FromSeconds(1)));
sw.Start();
var delayedTask = DelayedTask.Run(Action, delay);
await Task.Delay(50);
await Task.Delay(50, TestContext.CancellationToken);
delayedTask.Reset();
SpinWait.SpinUntil(() => executionCount > 0 || cts.IsCancellationRequested);
@@ -142,7 +144,7 @@ namespace AMWD.Common.Tests.Utilities
var cts = new CancellationTokenSource(delay.Add(TimeSpan.FromSeconds(1)));
sw.Start();
var delayedTask = DelayedTask.Create(Action, delay);
await Task.Delay(50);
await Task.Delay(50, TestContext.CancellationToken);
bool isSuccess = delayedTask.ExecutePending();
SpinWait.SpinUntil(() => executionCount > 0 || cts.IsCancellationRequested);
sw.Stop();
@@ -173,7 +175,7 @@ namespace AMWD.Common.Tests.Utilities
var cts = new CancellationTokenSource(delay.Add(TimeSpan.FromSeconds(1)));
sw.Start();
var delayedTask = DelayedTask.Run(Action, delay);
await Task.Delay(50);
await Task.Delay(50, TestContext.CancellationToken);
bool isSuccess = delayedTask.ExecutePending();
SpinWait.SpinUntil(() => executionCount > 0 || cts.IsCancellationRequested);
@@ -205,7 +207,6 @@ namespace AMWD.Common.Tests.Utilities
// assert
Assert.IsNotNull(delayedTask);
Assert.IsNotNull(awaiter);
Assert.IsFalse(delayedTask.IsRunning);
Assert.IsFalse(delayedTask.IsWaitingToRun);
Assert.IsNull(delayedTask.Exception);