Beispiel #1
0
        public static void Save(string testListenersFile)
        {
            // Expand each assembly path.
            foreach (TestListenerDescriptor listener in _testListenersCollection)
            {
                string testlisteners = TestProperties.TestConfigs;
                listener.Assembly = TestProperties.FixupString(listener.Assembly, "TestListeners");
            }

            TestListenerCollection.SerializeToFile(_testListenersCollection, testListenersFile);
        }
Beispiel #2
0
        public static void ReadFromFile(string testListenersFile)
        {
            Uri testListenersUri = new Uri(testListenersFile);

            _testListenersCollection = TestListenerCollection.DeserializeFromFile(testListenersUri.LocalPath);

            // Expand each assembly path.
            foreach (TestListenerDescriptor listener in _testListenersCollection)
            {
                if (listener.Assembly != null)
                {
                    listener.Assembly = TestProperties.ExpandString(listener.Assembly);
                }
            }

            TestListenersFile = testListenersFile;
        }
        public static void SerializeToFile(TestListenerCollection testListeners, string filePath)
        {
            XmlWriter writer = null;

            try
            {
                // Fixup assembly path to TestListeners definition.
                foreach (TestListenerDescriptor descriptor in testListeners)
                {
                    if (!string.IsNullOrEmpty(descriptor.Assembly))
                    {
                        TestProperties.FixupString(descriptor.Assembly, "TestConfigs");
                    }
                }

                DataContractSerializer serializer = new DataContractSerializer(typeof(TestListenerCollection));

                var settings = new XmlWriterSettings()
                {
                    Indent = true
                };

                using (writer = XmlWriter.Create(filePath, settings))
                {
                    serializer.WriteObject(writer, testListeners);
                }

                writer.Close();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (writer != null)
                {
                    // Close file.
                    writer.Close();
                }
            }
        }
Beispiel #4
0
        public void ExecuteTestSuite(TestSuite testSuite, List <TestCase> discreteTestCases, TestProfile testProfile, TestListenerCollection testListeners,
                                     bool suppressExecution)
        {
            LogEvent.Debug("Beginning execution");

            try
            {
                _testProfile = testProfile ?? new TestProfile();

                if (testListeners != null)
                {
                    LogEvent.Debug("Fixing up listeners");

                    _testListeners = fixupTestListeners(testListeners);

                    if (_testListeners.Count > 0)
                    {
                        _listenerEventsClient = getListenerEventsClient();
                        _listenerEventsClient.InitializeService(convertToListenerServiceCollection(testListeners), _testProfile);
                    }
                }

                ExecutionParameters executionParameters = new ExecutionParameters()
                {
                    _testScriptObject  = testSuite,
                    _testCases         = discreteTestCases,
                    _testProfile       = testProfile,
                    _suppressExecution = suppressExecution
                };

                LogEvent.Debug("Beginning executeTestScriptObject");

                executeTestScriptObject(executionParameters);
            }
            catch (Exception e)
            {
                LogEvent.Error(e.Message, e);

                throw;
            }
        }
        public static TestListenerCollection DeserializeFromFile(string filePath)
        {
            FileStream             reader        = null;
            TestListenerCollection testListeners = null;

            try
            {
                // Create DataContractSerializer.
                System.Runtime.Serialization.DataContractSerializer serializer =
                    new System.Runtime.Serialization.DataContractSerializer(typeof(TestListenerCollection));

                // Create a file stream to read into.
                reader = new FileStream(filePath, FileMode.Open, FileAccess.Read);

                // Read into object.
                testListeners = serializer.ReadObject(reader) as TestListenerCollection;

                // Fixup assembly path to TestListeners definition.
                foreach (TestListenerDescriptor descriptor in testListeners)
                {
                    TestProperties.ExpandString(descriptor.Assembly);

                    descriptor.Parameters = descriptor.Parameters ?? new Dictionary <string, string>();
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (reader != null)
                {
                    // Close file.
                    reader.Close();
                }
            }

            return(testListeners);
        }
Beispiel #6
0
        /// <summary>
        /// Iterates through the test listener collection for active listeners s
        /// expanding each parameter value for subsequent use.
        /// </summary>
        /// <param name="testListeners">The passed in test listener collection.</param>
        /// <returns>Fixed up collection.</returns>
        private TestListenerCollection fixupTestListeners(TestListenerCollection testListeners)
        {
            var activeListeners = testListeners.FindAll(x => x.Status == Status.Active && x.Parameters != null);

            foreach (var activeListener in activeListeners)
            {
                // Create new collection to hold updated values.
                var newParameters = new Dictionary <string, string>();

                foreach (var parameter in activeListener.Parameters)
                {
                    var key           = parameter.Key;
                    var expandedValue = TestProperties.ExpandString(parameter.Value);
                    newParameters.Add(key, expandedValue);
                }

                // Replace old collection with fixedup collection.
                activeListener.Parameters = newParameters;
            }

            // Return fixed up collection
            return(new TestListenerCollection(activeListeners));
        }
Beispiel #7
0
 public static void Initialize()
 {
     _testListenersCollection = new TestListenerCollection();
 }
Beispiel #8
0
        /// <summary>
        /// This is a bit of a hack.  Translates the core TestListenerCollection into a list
        /// of ListenerService TestListenerDescriptors.  There is probably a better, more elegant
        /// way to avoid this.
        /// </summary>
        /// <param name="testListeners">TestlistenerCollection</param>
        /// <returns>List of ListenerService test listener d</returns>
        private List <ListenersService.TestListenerDescriptor> convertToListenerServiceCollection(TestListenerCollection testListeners)
        {
            var serviceCollection = new List <ListenersService.TestListenerDescriptor>();

            foreach (TestListenerDescriptor descriptor in testListeners)
            {
                serviceCollection.Add(
                    new ListenersService.TestListenerDescriptor()
                {
                    Name        = descriptor.Name,
                    Description = descriptor.Description,
                    Status      = descriptor.Status,
                    OnFailure   = descriptor.OnFailure,
                    Assembly    = descriptor.Assembly,
                    Type        = descriptor.Type,
                    Parameters  = descriptor.Parameters
                }
                    );
            }

            return(serviceCollection);
        }