public void It_should_dispose_of_auto_properties()
        {
            var target = DisposableHelper.SafeCreate <DisposableItem>();

            target.Dispose();
            target.DisposableReadOnlyAutoProperty.Should().BeNull();
        }
        public void It_should_dispose_of_read_only_fields()
        {
            var target = DisposableHelper.SafeCreate <DisposableItem>();

            target.Dispose();
            target.GetPrivateReadOnlyDisposableField().Should().BeNull();
        }
        public void It_should_not_dispose_of_fields_attributed_with_do_not_dispose()
        {
            var target = DisposableHelper.SafeCreate <DisposableItem>();

            target.Dispose();
            target.GetDoNotDisposeField().Should().NotBeNull();
        }
                public ClassWithDictionaryFieldWithDisposableKey()
                {
                    var builder = ImmutableDictionary <Mutex, string> .Empty.ToBuilder();

                    builder.Add(DisposableHelper.SafeCreate <Mutex>(), "a name");
                    _field = builder.ToImmutable();
                }
        public void It_should_not_dispose_of_auto_properties_attributed_with_do_not_dispose()
        {
            var target = DisposableHelper.SafeCreate <DisposableItem>();

            target.Dispose();
            target.DoNotDisposeAutoProperty.Should().NotBeNull();
        }
            protected override void ArrangeMethod()
            {
                traceLines = new List <string>();

                memoryStream = DisposableHelper.SafeCreate(
                    () =>
                {
                    var rv      = DisposableHelper.SafeCreate(() => new MemoryStream());
                    rv.Capacity = 1024 * 1024;
                    rv.Position = 0;
                    return(rv);
                });
                var streamWriter = new StreamWriter(memoryStream)
                {
                    AutoFlush = true
                };

                memoryListener = new TextWriterTraceListener(streamWriter);
                Trace.Listeners.Add(memoryListener);

                source = new EventSource();

                removedInstanceSink = new EventSink(source);
                removedInstanceId   = removedInstanceSink.Id;
                TestHelp.DoNothing(removedInstanceSink);

                keptInstanceSink = new EventSink(source);
                keptInstanceId   = keptInstanceSink.Id;
                TestHelp.DoNothing(keptInstanceSink);
            }
        public void It_should_handle_contained_nulls_in_an_enumerable()
        {
            var targetEnumerable = DisposableHelper.SafeCreate <DisposableEnumerable>();

            targetEnumerable.AddDisposable(null);
            targetEnumerable.Dispose();

            TestHardCodes.NoExceptionWasThrown.Should().BeTrue();
        }
 public void It_should_dispose_a_Dictionary_field_with_an_Enumerable_Disposable_Key()
 {
     using (var target = DisposableHelper.SafeCreate <ClassWithDictionaryFieldWithEnumerableDisposableKey>())
     {
         target.Dispose();
         var actual = target.TestHookGetField();
         actual.Should().BeNull();
     }
 }
        public void It_should_handle_null_fields()
        {
            var target = DisposableHelper.SafeCreate <DisposableEnumerable>();

            target.SetFlatField(null);
            target.Dispose();

            TestHardCodes.NoExceptionWasThrown.Should().BeTrue();
        }
Esempio n. 10
0
 public void When_I_call_DisposableHelp_SafeCreate_generic_and_the_ctor_throws()
 {
     try
     {
         DisposableHelper.SafeCreate <TestTarget>();
     }
     catch (InvalidOperationException ioe)
     {
         ioe.Message.Should().Be("Intentionally throwing from .ctor");
     }
 }
Esempio n. 11
0
        public void It_should_dispose_of_all_contained_disposables_in_an_enumerable()
        {
            var targetEnumerable = DisposableHelper.SafeCreate <DisposableEnumerable>();
            var contained        = DisposableHelper.SafeCreate(() => new DisposableItem());

            targetEnumerable.AddDisposable(contained);

            targetEnumerable.Dispose();

            contained.IsDisposed.Should().BeTrue();
        }
Esempio n. 12
0
        public void It_should_throw_when_disposed()
        {
            var target = DisposableHelper.SafeCreate <DisposableItem>();

            target.Dispose();

            // ReSharper disable once AccessToDisposedClosure
            Action throwingAction = target.Method;

            throwingAction.Should().Throw <ObjectDisposedException>();
        }
Esempio n. 13
0
        public void It_should_handle_inheritance()
        {
            var target = DisposableHelper.SafeCreate <DisposableDescendant>();
            var item0  = DisposableHelper.SafeCreate(() => new DisposableItem());

            target.SetFlatField(item0);

            var item1 = DisposableHelper.SafeCreate(() => new DisposableItem());

            target.SetAnotherField(item1);

            target.Dispose();

            item1.IsDisposed.Should().BeTrue();
            item0.IsDisposed.Should().BeTrue();
        }
Esempio n. 14
0
 public ClassWithDictionaryFieldWithDisposableValue()
 {
     _field = new Dictionary <string, Mutex> {
         { "name", DisposableHelper.SafeCreate <Mutex>() }
     };
 }