Beispiel #1
0
        public void Test_ClearDeadThreads()
        {
            //---------------Set up test pack-------------------
            var dataAccessorMain = new DataAccessorInMemory();
            var dataAccessor     = new DataAccessorThreadSplitter(dataAccessorMain);
            var expectedDataAccessorForThread = new DataAccessorInMemory();
            var thread = new Thread(() =>
            {
                dataAccessor.AddDataAccessorForThread(expectedDataAccessorForThread);
                Thread.Sleep(100);
            });

            thread.Start();
            //---------------Assert preconditions---------------
            Assert.AreSame(expectedDataAccessorForThread, dataAccessor.GetDataAccessorForThread(thread));
            //---------------Execute Test ----------------------
            thread.Join();
            dataAccessor.ClearDeadThreads();
            //---------------Test Result -----------------------
            try
            {
                Assert.IsNull(dataAccessor.GetDataAccessorForThread(thread));
                Assert.Fail("An exception should be thrown");
            } catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("Data accessor for thread does not exist", ex.Message);
            }
        }
Beispiel #2
0
        public void Test_WithThread()
        {
            //---------------Set up test pack-------------------
            var dataAccessorMain = new DataAccessorInMemory();
            var dataAccessor     = new DataAccessorThreadSplitter(dataAccessorMain);
            var expectedDataAccessorForThread = new DataAccessorInMemory();
            var thread = new Thread(() =>
            {
                dataAccessor.AddDataAccessorForThread(expectedDataAccessorForThread);
                Thread.Sleep(1000);
            });

            thread.Start();
            Thread.Sleep(500);
            //---------------Execute Test ----------------------
            var dataAccessorForThread = dataAccessor.GetDataAccessorForThread(thread);

            //---------------Test Result -----------------------
            Assert.AreSame(expectedDataAccessorForThread, dataAccessorForThread);
        }