public void Should_finish_on_finalize() { _subject = null; GC.Collect(GC.MaxGeneration); GC.WaitForPendingFinalizers(); _aggregator.AssertWasCalled(a => a.Finished()); }
public void The_coordinator_should_uninstall_self_upon_disposal_only_if_it_actively_used_one() { using (var installedCoordinator = new TestableFeatureCoordinator().InstallSelf()) { using (new TestableFeatureCoordinator()) { } Assert.That(TestableFeatureCoordinator.GetInstalled(), Is.SameAs(installedCoordinator)); } }
public void It_should_be_possible_to_install_new_cooridnator_when_previous_was_disposed() { using (new TestableFeatureCoordinator().InstallSelf()) { } using (var coord = new TestableFeatureCoordinator()) Assert.DoesNotThrow(() => coord.InstallSelf()); }
public void It_should_not_be_possible_to_install_multiple_coordinators_at_the_same_time() { using (var coord1 = new TestableFeatureCoordinator()) using (var coord2 = new TestableFeatureCoordinator()) { coord1.InstallSelf(); var ex = Assert.Throws <InvalidOperationException>(() => coord2.InstallSelf()); Assert.That(ex.Message, Is.EqualTo($"FeatureCoordinator of {typeof(TestableFeatureCoordinator)} type is already installed")); } }
public void Should_trace_error_if_exception_is_thrown_during_finalization() { _subject.OnBeforeFinish += () => { throw new NotImplementedException("abc"); }; using (var console = new TraceInterceptor()) { _subject = null; GC.Collect(GC.MaxGeneration); GC.WaitForPendingFinalizers(); Assert.That(console.GetCapturedText(), Is.StringContaining("Summary aggregation failed: System.NotImplementedException: abc")); } }
public void Should_trace_warning_if_finalization_takes_longer_than_1_and_half_second() { _subject.OnBeforeFinish += () => Thread.Sleep(1550); using (var console = new TraceInterceptor()) { _subject = null; GC.Collect(GC.MaxGeneration); GC.WaitForPendingFinalizers(); Assert.That(console.GetCapturedText(), Is.StringContaining("WARNING: Please consider to call FeatureCoordinator.Instance.Finished() manually, otherwise if execution time reach 2 seconds, .NET framework will kill aggregation process.")); } }
public void Should_not_print_warning_if_finalization_takes_less_than_1_and_half_second() { _subject.OnBeforeFinish += () => Thread.Sleep(1450); using (var console = new TraceInterceptor()) { _subject = null; GC.Collect(GC.MaxGeneration); GC.WaitForPendingFinalizers(); Assert.That(console.GetCapturedText(), Is.Not.StringContaining("WARNING: Please consider")); } }
public void The_coordinator_should_uninstall_self_upon_disposal() { using (var coord = new TestableFeatureCoordinator().InstallSelf()) Assert.That(TestableFeatureCoordinator.GetInstalled(), Is.SameAs(coord)); Assert.That(TestableFeatureCoordinator.GetInstalled(), Is.Null); }
public void SetUp() { _aggregator = MockRepository.GenerateMock<IFeatureAggregator>(); _subject = new TestableFeatureCoordinator(_aggregator); }
public void SetUp() { _aggregator = MockRepository.GenerateMock <IFeatureAggregator>(); _subject = new TestableFeatureCoordinator(_aggregator); }