public async Task TwoEvents_NoUnsubscribe() { var obj = new ObjectWithEvent(); var t = _eas.Create(obj); t.IsCompleted.Should().BeFalse(); Task.Run(() => obj.RaiseInt(5)).DoNotWait(); await t; t.Result.Value.Should().Be(5); Task.Run(() => obj.RaiseInt(10)).DoNotWait(); t.Result.Value.Should().Be(5); }
public async Task TwoObjects() { var obj1 = new ObjectWithEvent(); var obj2 = new ObjectWithEvent(); var t1 = _eas.Create(obj1); var t2 = _eas.Create(obj2); t1.IsCompleted.Should().BeFalse(); t2.IsCompleted.Should().BeFalse(); Task.Run(() => obj1.RaiseInt(5)).DoNotWait(); await Task.WhenAny(t1, t2); t1.IsCompleted.Should().BeTrue(); t2.IsCompleted.Should().BeFalse(); t1.Result.Value.Should().Be(5); Task.Run(() => obj2.RaiseInt(10)).DoNotWait(); await t2; t1.IsCompleted.Should().BeTrue(); t2.IsCompleted.Should().BeTrue(); t2.Result.Value.Should().Be(10); }
public async Task TwoObjects_OneCancelled() { var obj1 = new ObjectWithEvent(); var t1 = _eas.Create(obj1); var obj2 = new ObjectWithEvent(); var cts = new CancellationTokenSource(); var t2 = _eas.Create(obj2, cts.Token); t1.IsCompleted.Should().BeFalse(); t2.IsCompleted.Should().BeFalse(); Task.Run(() => obj1.RaiseInt(5)).DoNotWait(); await Task.WhenAny(t1, t2); t1.IsCompleted.Should().BeTrue(); t2.IsCompleted.Should().BeFalse(); t1.Result.Value.Should().Be(5); Task.Run(() => cts.Cancel()).DoNotWait(); Func <Task> f = async() => await t2; f.ShouldThrow <OperationCanceledException>(); t1.IsCompleted.Should().BeTrue(); t2.IsCompleted.Should().BeTrue(); }
public async Task TwoEventsSequentalTasks() { var obj = new ObjectWithEvent(); var t1 = _eas.Create(obj); t1.IsCompleted.Should().BeFalse(); Task.Run(() => obj.RaiseInt(5)).DoNotWait(); await t1; t1.Result.Value.Should().Be(5); var t2 = _eas.Create(obj); Task.Run(() => obj.RaiseInt(10)).DoNotWait(); t1.Result.Value.Should().Be(5); t2.Result.Value.Should().Be(10); }
public async Task TwoTasks() { var obj = new ObjectWithEvent(); var t1 = _eas.Create(obj); var t2 = _eas.Create(obj); t1.IsCompleted.Should().BeFalse(); t2.IsCompleted.Should().BeFalse(); Task.Run(() => obj.RaiseInt(5)).DoNotWait(); await Task.WhenAll(t1, t2); t1.Result.Value.Should().Be(5); t2.Result.Should().Be(t1.Result); }
public async Task TwoEvents_NoUnsubscribe() { var obj = new ObjectWithEvent(); var t = _eas.Create(obj); t.IsCompleted.Should().BeFalse(); Task.Run(() => obj.RaiseInt(5)).DoNotWait(); await t; t.Result.Value.Should().Be(5); Task.Run(() => obj.RaiseInt(10)).DoNotWait(); t.Result.Value.Should().Be(5); }
public async Task TwoEventsSequentalTasks() { var obj = new ObjectWithEvent(); var t1 = _eas.Create(obj); t1.IsCompleted.Should().BeFalse(); Task.Run(() => obj.RaiseInt(5)).DoNotWait(); await t1; t1.Result.Value.Should().Be(5); var t2 = _eas.Create(obj); Task.Run(() => obj.RaiseInt(10)).DoNotWait(); t1.Result.Value.Should().Be(5); t2.Result.Value.Should().Be(10); }
public async Task TwoTasks() { var obj = new ObjectWithEvent(); var t1 = _eas.Create(obj); var t2 = _eas.Create(obj); t1.IsCompleted.Should().BeFalse(); t2.IsCompleted.Should().BeFalse(); Task.Run(() => obj.RaiseInt(5)).DoNotWait(); await Task.WhenAll(t1, t2); t1.Result.Value.Should().Be(5); t2.Result.Should().Be(t1.Result); }
public async Task TwoObjects_OneCancelled() { var obj1 = new ObjectWithEvent(); var t1 = _eas.Create(obj1); var obj2 = new ObjectWithEvent(); var cts = new CancellationTokenSource(); var t2 = _eas.Create(obj2, cts.Token); t1.IsCompleted.Should().BeFalse(); t2.IsCompleted.Should().BeFalse(); Task.Run(() => obj1.RaiseInt(5)).DoNotWait(); await Task.WhenAny(t1, t2); t1.IsCompleted.Should().BeTrue(); t2.IsCompleted.Should().BeFalse(); t1.Result.Value.Should().Be(5); Task.Run(() => cts.Cancel()).DoNotWait(); Func<Task> f = async () => await t2; f.ShouldThrow<OperationCanceledException>(); t1.IsCompleted.Should().BeTrue(); t2.IsCompleted.Should().BeTrue(); }
public async Task TwoObjects() { var obj1 = new ObjectWithEvent(); var obj2 = new ObjectWithEvent(); var t1 = _eas.Create(obj1); var t2 = _eas.Create(obj2); t1.IsCompleted.Should().BeFalse(); t2.IsCompleted.Should().BeFalse(); Task.Run(() => obj1.RaiseInt(5)).DoNotWait(); await Task.WhenAny(t1, t2); t1.IsCompleted.Should().BeTrue(); t2.IsCompleted.Should().BeFalse(); t1.Result.Value.Should().Be(5); Task.Run(() => obj2.RaiseInt(10)).DoNotWait(); await t2; t1.IsCompleted.Should().BeTrue(); t2.IsCompleted.Should().BeTrue(); t2.Result.Value.Should().Be(10); }