Example #1
0
        public void GetForNewItem()
        {
            // Setup
            var fakeItem = Substitute.For <IReaderWriterLock>();

            m_factory.Create().Returns(fakeItem);
            var mgr = new ReaderWriterLockManager <string>(m_factory, m_logger);
            // Act
            var item = mgr.GetFor("test");

            // Assert
            Assert.AreEqual(item, fakeItem);
            m_factory.Received().Create();
        } /* End of Function - GetForNewItem */
Example #2
0
        public void GetForOldItem()
        {
            // Setup
            var fakeItem = Substitute.For <IReaderWriterLock>();
            Dictionary <string, IReaderWriterLock> dictionary = new Dictionary <string, IReaderWriterLock>();

            dictionary.Add("test", fakeItem);
            var mgr = new ReaderWriterLockManager <string>(m_factory, m_logger);
            // Setup to set the private field
            var field = typeof(ReaderWriterLockManager <string>).GetField("m_readerWriters",
                                                                          System.Reflection.BindingFlags.NonPublic
                                                                          | System.Reflection.BindingFlags.GetField
                                                                          | System.Reflection.BindingFlags.Instance);

            field.SetValue(mgr, dictionary);
            // Act
            var item = mgr.GetFor("test");

            // Assert
            Assert.AreEqual(item, fakeItem);
            m_factory.DidNotReceive().Create();
        } /* End of Function - GetForOldItem */