Пример #1
0
        public void CanDispose()
        {
            // Setup
            // Create a dictionary to use as a pretend populated
            // dictionary
            var pretendDictionary =
                new Dictionary <string, IReaderWriterLock>();

            pretendDictionary.Add("Test", Substitute.For <IReaderWriterLock>());
            var mgr = new ReaderWriterLockManager <string>(m_factory, m_logger);
            // And we will get the private field information to update
            // with our pretend dictionary
            var field = typeof(ReaderWriterLockManager <string>)
                        .GetField("m_readerWriters",
                                  System.Reflection.BindingFlags.GetField
                                  | System.Reflection.BindingFlags.Instance
                                  | System.Reflection.BindingFlags.NonPublic);

            // Set the value
            field.SetValue(mgr, pretendDictionary);
            // And for safe measures, read to make sure it is good
            Assert.IsNotNull(field.GetValue(mgr));
            // Act
            mgr.Dispose();
            // Assert
            // Now we should have a null object instead, due to the
            // disposal
            var dictionary = (Dictionary <string, IReaderWriterLock>)field.GetValue(mgr);

            Assert.AreEqual(null, dictionary);
        } /* End of Function - CanDispose */