Exemple #1
0
        private void LoadTestCollections()
        {
            IList <string> testCollectionFiles = null;

            try
            {
                testCollectionFiles = _testCollectionServiceService.GetTestCollectionFiles();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error Loading TestCollections", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (testCollectionFiles == null)
            {
                return;
            }

            foreach (var testCollectionFile in testCollectionFiles)
            {
                TestCollection testCollection = null;

                try
                {
                    testCollection = _testCollectionServiceService.GetTestCollection(testCollectionFile);
                }
                catch (Exception e)
                {
                    MessageBox.Show("TestCollection: " + testCollectionFile + Environment.NewLine + e.Message,
                                    "Error Loading TestCollection", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                if (testCollection == null)
                {
                    return;
                }

                var testCollectionViewModel = new TestCollectionViewModel
                {
                    Domain    = testCollection.DefaultDomain,
                    IsEnabled = testCollection.Enabled,
                    Name      = testCollection.File
                };

                if (testCollection.Tests == null)
                {
                    return;
                }

                foreach (var test in testCollection.Tests)
                {
                    var testViewModel = new TestViewModel
                    {
                        IsEnabled = test.Enabled,
                        Name      = test.Name,
                        Url       = test.Url,
                        IsEnabledChangedCommand = new RelayCommand(enabled =>
                        {
                            test.Enabled = (bool)enabled;
                            _testCollectionServiceService.SaveTestCollection(testCollection);
                        })
                    };

                    if (test.Commands == null)
                    {
                        return;
                    }

                    foreach (var command in test.Commands)
                    {
                        var commandViewModel = new CommandViewModel
                        {
                            Name    = command.Name,
                            Command = command,
                        };

                        var properties = _commandService.GetCommandValues(command);

                        foreach (var item in properties)
                        {
                            commandViewModel.Properties.Add(new CommandPropertyViewModel
                            {
                                Name  = item.Key,
                                Value = item.Value
                            });
                        }

                        testViewModel.Children.Add(commandViewModel);
                    }

                    testCollectionViewModel.Children.Add(testViewModel);
                }

                TestCollections.Add(testCollectionViewModel);
            }
        }
        private void LoadTestCollections()
        {
            IList<string> testCollectionFiles = null;

            try
            {
                testCollectionFiles = _testCollectionServiceService.GetTestCollectionFiles();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error Loading TestCollections", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (testCollectionFiles == null)
                return;

            foreach (var testCollectionFile in testCollectionFiles)
            {
                TestCollection testCollection = null;

                try
                {
                    testCollection = _testCollectionServiceService.GetTestCollection(testCollectionFile);
                }
                catch (Exception e)
                {
                    MessageBox.Show("TestCollection: " + testCollectionFile + Environment.NewLine + e.Message,
                                    "Error Loading TestCollection", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                if (testCollection == null)
                    return;

                var testCollectionViewModel = new TestCollectionViewModel
                {
                    Domain = testCollection.DefaultDomain,
                    IsEnabled = testCollection.Enabled,
                    Name = testCollection.File,
                    FullPath = testCollection.ResolvedFile,
                };

                if (testCollection.Tests == null)
                    return;

                foreach (var test in testCollection.Tests)
                {
                    var testViewModel = new TestViewModel
                    {
                        IsEnabled = test.Enabled,
                        Name = test.Name,
                        Url = test.Url,
                        IsEnabledChangedCommand = new RelayCommand(enabled =>
                        {
                            test.Enabled = (bool) enabled;
                            _testCollectionServiceService.SaveTestCollectionInfo(testCollection);
                        })
                    };

                    if (test.Commands == null)
                        return;

                    foreach (var command in test.Commands)
                    {
                        var commandViewModel = new CommandViewModel
                        {
                            Name = command.Name,
                            Command = command,
                        };

                        var properties = _commandService.GetCommandValues(command);

                        foreach (var item in properties)
                        {
                            commandViewModel.Properties.Add(new CommandPropertyViewModel
                            {
                                Name = item.Key,
                                Value = item.Value
                            });
                        }

                        testViewModel.Children.Add(commandViewModel);
                    }

                    testCollectionViewModel.Children.Add(testViewModel);
                }

                TestCollections.Add(testCollectionViewModel);
            }
        }