Ejemplo n.º 1
0
        public void ResetInstance_should_honor_options(ResetOptions resetOptions, bool shouldResetNoCleanField, bool shouldResetReadonlyField, bool shouldResetNoCleanProperty, bool shouldResetNoCleanReadonlyField, bool shouldResetField, bool shouldDispose)
        {
            var noCleanField         = new Mock <IDisposable>();
            var readonlyField        = new Mock <IDisposable>();
            var noCleanProperty      = new Mock <IDisposable>();
            var noCleanReadonlyField = new Mock <IDisposable>();
            var field = new Mock <IDisposable>();

            var current = new Options.Current(
                noCleanField.Object,
                readonlyField.Object,
                noCleanProperty.Object,
                noCleanReadonlyField.Object,
                field.Object
                );

            StateCleaner.ResetInstance(current, HierarchyOptions.All, VisibilityOptions.All, resetOptions);

            Assert.That(current.NoCleanField == null, Is.EqualTo(shouldResetNoCleanField));
            noCleanField.Verify(d => d.Dispose(), Times.Exactly(shouldResetNoCleanField && shouldDispose ? 1 : 0));

            Assert.That(current.ReadonlyField == null, Is.EqualTo(shouldResetReadonlyField));
            readonlyField.Verify(d => d.Dispose(), Times.Exactly(shouldResetReadonlyField && shouldDispose ? 1 : 0));

            Assert.That(current.NoCleanProperty == null, Is.EqualTo(shouldResetNoCleanProperty));
            noCleanProperty.Verify(d => d.Dispose(), Times.Exactly(shouldResetNoCleanProperty && shouldDispose ? 1 : 0));

            Assert.That(current.NoCleanReadonlyField == null, Is.EqualTo(shouldResetNoCleanReadonlyField));
            noCleanReadonlyField.Verify(d => d.Dispose(), Times.Exactly(shouldResetNoCleanReadonlyField && shouldDispose ? 1 : 0));

            Assert.That(current.Field == null, Is.EqualTo(shouldResetField));
            field.Verify(d => d.Dispose(), Times.Exactly(shouldResetField && shouldDispose ? 1 : 0));
        }
Ejemplo n.º 2
0
        public void ResetInstance_should_handler_null_fields()
        {
            var current = new Options.Current(null, new Mock <IDisposable>().Object, null, null, new Mock <IDisposable>().Object);

            Assert.DoesNotThrow(() => StateCleaner.ResetInstance(current, HierarchyOptions.All, VisibilityOptions.All, ResetOptions.OverruleNoAutoClean | ResetOptions.IncludeReadOnlyMembers));
            Assert.That(current.ReadonlyField, Is.Null);
            Assert.That(current.Field, Is.Null);
        }