public async Task TwoObserverOneCancelled() { var subject = new AsyncSubject <int>(); var cts = new CancellationTokenSource(); string result1 = ""; string result2 = ""; var t1 = subject .Finally(() => result1 += "F") .SubscribeAsync(i => result1 += i, ex => result1 += "E", () => result1 += "C", cts.Token); var t2 = subject .Finally(() => result2 += "F") .SubscribeAsync(i => result2 += i, ex => result2 += "E", () => result2 += "C"); await subject.OnNextAsync(1); cts.Cancel(); await subject.OnNextAsync(2); await subject.DisposeAsync(); await t1; await t2; result1 .Should().Be("1FE"); result2 .Should().Be("12FC"); }
public async Task TwoObserverTwoItems() { var subject = new AsyncSubject <int>(); string result1 = ""; string result2 = ""; var t1 = subject .Finally(() => result1 += "F") .SubscribeAsync(i => result1 += i, ex => result1 += "E", () => result1 += "C"); var t2 = subject .Finally(() => result2 += "F") .SubscribeAsync(i => result2 += i, ex => result2 += "E", () => result2 += "C"); await subject.OnNextAsync(1); await subject.OnNextAsync(2); await subject.DisposeAsync(); await t1; await t2; result1 .Should().Be("12FC"); result2 .Should().Be("12FC"); }
public async Task OneObserverEmpty() { var subject = new AsyncSubject <int>(); string result = ""; var t = subject .Finally(() => result += "F") .SubscribeAsync(i => result += i, ex => result += "E", () => result += "C"); await subject.DisposeAsync(); await t; result .Should().Be("FC"); }