public async Task Shutdown_InvokesPassedCleanupFunc() { var c = new CleanupCollection <ShutdownRecorder>(); Func <ShutdownRecorder, Task> cleanupFunc = sr => { sr.Shutdown(); return(CodegenHelpers.CompletedTask); }; var obj1 = new ShutdownRecorder(); var obj2 = new ShutdownRecorder(); var obj3 = new ShutdownRecorder(); Assert.AreEqual(0, obj1.NumTimesShutdown); Assert.AreEqual(0, obj2.NumTimesShutdown); Assert.AreEqual(0, obj3.NumTimesShutdown); c.Add(obj1); c.Add(obj2); c.Add(obj3); c.Remove(obj3); await c.CleanupAsync(cleanupFunc); Assert.AreEqual(1, obj1.NumTimesShutdown); Assert.AreEqual(1, obj2.NumTimesShutdown); Assert.AreEqual(0, obj3.NumTimesShutdown); await c.CleanupAsync(cleanupFunc); Assert.AreEqual(1, obj1.NumTimesShutdown); Assert.AreEqual(1, obj2.NumTimesShutdown); Assert.AreEqual(0, obj3.NumTimesShutdown); }
public async Task AfterShutdown_CanStillRemove() { var c = new CleanupCollection <object>(); var obj1 = new object(); c.Add(obj1); await c.CleanupAsync(); c.Remove(obj1); }