public async Task DuplicateErrorTest() { const int key = 1337; var dictionary = new WaitingDictionary <int, Mock>(); var mock = new Mock(); await dictionary.SetAsync(key, mock); Assert.CatchAsync <InvalidOperationException>(() => dictionary.SetAsync(key, mock)); }
public async Task FilterTest() { using var dictionary = new WaitingDictionary <int, Mock>(); await dictionary.SetAsync(1, new Mock()); Assert.IsEmpty(dictionary.Filter(tcs => tcs.Value.Task.Status == TaskStatus.Canceled)); }
public async Task RemoveTest() { using var dictionary = new WaitingDictionary <int, Mock>(); await dictionary.SetAsync(1, new Mock()); Assert.IsTrue(await dictionary.TryRemoveAsync(1)); }
public async Task DuplicateTest() { const int key = 1337; using var dictionary = new WaitingDictionary <int, Mock>( new MiddlewareBuilder <Mock>() .RegisterDuplicateActionInSet((old, @new) => new Mock(old, @new)) ); var mock = new Mock(); await dictionary.SetAsync(key, mock); await dictionary.SetAsync(key, mock); var waitMock = await dictionary.WaitAsync(key); Assert.IsNotEmpty(waitMock.Nodes); }
public void EnumerateTest() { using var dictionary = new WaitingDictionary <int, Mock>(); dictionary.SetAsync(1, new Mock()); dictionary.SetAsync(2, new Mock()); var idx = 0; foreach (var taskCompletionSource in dictionary) { Assert.NotNull(taskCompletionSource); idx++; } Assert.IsNotEmpty(dictionary); Assert.Greater(dictionary.Count, 1); Assert.Greater(idx, 1); }
public async Task MultipleWaitTest() { const int key = 1337; using var dictionary = new WaitingDictionary <int, Mock>(); var waitTask1 = dictionary.WaitAsync(key); var waitTask2 = dictionary.WaitAsync(key); Assert.IsTrue(!waitTask1.IsCompletedSuccessfully); Assert.IsTrue(!waitTask2.IsCompletedSuccessfully); await dictionary.SetAsync(key, new Mock()); await Task.Delay(200); Assert.IsTrue(waitTask1.IsCompletedSuccessfully); Assert.IsTrue(waitTask2.IsFaulted); }
public async Task NormalTest() { const int key = 1337; using var dictionary = new WaitingDictionary <int, Mock>( new MiddlewareBuilder <Mock>() .RegisterCompletionActionInSet(() => TestContext.WriteLine("Set completed")) .RegisterCompletionActionInWait(() => TestContext.WriteLine("Wait completed")) ); var waitTask = dictionary.WaitAsync(key); Assert.IsTrue(!waitTask.IsCompletedSuccessfully); var mock = new Mock(); await dictionary.SetAsync(key, mock); Assert.IsTrue(waitTask.IsCompletedSuccessfully); }