public async Task SimpleTest(int count) { var waiter = new TestAwaitable(count); var moqClients = Enumerable.Range(0, 4).Select(x => ClientMoq.Get(() => $"SimpleTest{x}", () => x.ToString())).ToList(); var rollup = new TestRollup(moqClients.Select(x => x.Object)); var coord = new TestedCoordinator(rollup, (x, y, e) => waiter.Fail($"Client Error Sended {x.GetIdentifier()}\n ex: {e}"), (x) => waiter.Fail($"Canceled {x.GetIdentifier()}"), onComplete: (x, y) => { if (Interlocked.Increment(ref _simpleTestReadCounter) == count) { waiter.Complete(); } }); await SuccessResults(count, waiter, coord, x => x.ToString()); moqClients.ForEach(x => x.Verify(y => y.AskAsync(It.IsAny <RequestMoq>(), It.IsAny <CancellationToken>()), Times.AtLeastOnce)); await Task.CompletedTask; }
public async Task CancelTest(int wait) { var waiter = new TestAwaitable(wait); var clients = new[] { ClientMoq.Get(() => "", () => "wait", wait) }; var rollupSingleWaiting = new TestRollup(clients.Select(x => x.Object)); var coord = new TestedCoordinator(rollupSingleWaiting, (x, y, e) => waiter.Fail($"Client Error Sended {x.GetIdentifier()}\n ex: {e}"), (x) => waiter.Complete()); const string name = "cancel"; string id = await coord.GetToken(new RequestMoq(name)); await coord.Cancel(id); Models.Response <ResponseMoq> r = new Models.Response <ResponseMoq>(); var t = coord.Result(id); r = await t; await waiter.Awaiter(); Assert.IsTrue(r.GetState() == Models.ResponseState.Deleted); await Task.CompletedTask; }
public async Task RepeatTest(int count) { var waiter = new TestAwaitable(count); var clients = new[] { ClientMoq.Get(() => "wait", () => "wait", 100) }; var rollupSingleWaiting = new TestRollup(clients.Select(x => x.Object)); var coord = new TestedCoordinator(rollupSingleWaiting, (x, c, e) => Assert.Fail(), (x) => Assert.Fail(), onComplete: (x, y) => { if (Interlocked.Increment(ref _repeatTestReadCounter) == 2) { waiter.Complete(); } }); await SuccessResults(count, waiter, coord, x => (x % 2).ToString()); foreach (var x in clients) { x.Verify(y => y.AskAsync(It.IsAny <RequestMoq>(), It.IsAny <CancellationToken>()), Times.AtMost(2)); x.Verify(y => y.AskAsync(It.IsAny <RequestMoq>(), It.IsAny <CancellationToken>()), Times.AtLeastOnce); } await Task.CompletedTask; }