Пример #1
0
        protected void TryMillipedeException(Exception exception)
        {
            string tempFileName = Path.GetTempFileName();
            toBeDeleted.Add(tempFileName);

            // Create the mock connector
            MockConnector mockConnector = new MockConnector();
            mockConnector.CreateTransport = delegate { throw exception; };
            mockConnector.Start();

            recorder = new MillipedeRecorder();
            recorder.StartRecording(tempFileName);
            Assert.AreEqual(MillipedeMode.Record, recorder.Mode);
            Assert.AreEqual(0, recorder.NumberEvents);
            MillipedeConnector connector =
                (MillipedeConnector)MillipedeConnector.Wrap(mockConnector, recorder);
            try
            {
                connector.Connect("localhost", "9999", new Dictionary<string, string>());
                Assert.Fail("should have thrown CannotConnectException");
            }
            catch(GTException) { /* ignored */ }
            Assert.AreEqual(1, recorder.NumberEvents);

            recorder.Dispose(); // don't want the disposes add to the list
            mockConnector.Dispose();
            recorder = new MillipedeRecorder();
            recorder.StartReplaying(tempFileName);
            Assert.AreEqual(0, recorder.NumberEvents);
            connector = (MillipedeConnector)MillipedeConnector.Wrap(mockConnector = new MockConnector(),
                recorder);
            try
            {
                connector.Connect("localhost", "9999", new Dictionary<string, string>());
                Assert.Fail("should have thrown " + exception.GetType());
            }
            catch (Exception e)
            {
                Assert.AreEqual(exception.GetType(), e.GetType());
            }
            Assert.AreEqual(1, recorder.NumberEvents);

            recorder.Dispose();
        }
Пример #2
0
        public void BaseTestUniqueStableDescriptor()
        {
            string[] values = { typeof(String).FullName, "test", "bar", "test" };
            foreach (string value in values) {
                object d1 = recorder.GenerateDescriptor(value);
                recorder.Dispose();
                recorder = new MillipedeRecorder();
                object d2 = recorder.GenerateDescriptor(value);
                recorder.Dispose();
                Assert.AreEqual(d1,d2);
                recorder = new MillipedeRecorder();
            }

            Dictionary<object, object> descriptors = new Dictionary<object, object>();
            foreach (string value in values)
            {
                object d1 = recorder.GenerateDescriptor(value);
                Assert.IsFalse(descriptors.ContainsKey(d1));
                descriptors[d1] = d1;
            }
        }