public void ShouldBeAbleToSaveProjectsThatALoaderCanLoad()
		{
			ExecutableTask builder = new ExecutableTask();
			builder.Executable = "foo";
			FileSourceControl sourceControl = new FileSourceControl();
			sourceControl.RepositoryRoot = "bar";
			// Setup
			Project project1 = new Project();
			project1.Name = "Project One";
			project1.SourceControl = sourceControl;
			Project project2 = new Project();
			project2.Name = "Project Two";
			project2.SourceControl = sourceControl;
			ProjectList projectList = new ProjectList();
			projectList.Add(project1);
			projectList.Add(project2);

			DynamicMock mockConfiguration = new DynamicMock(typeof(IConfiguration));
			mockConfiguration.ExpectAndReturn("Projects", projectList);

			FileInfo configFile = new FileInfo(TempFileUtil.CreateTempFile(TempFileUtil.CreateTempDir(this), "loadernet.config"));

			// Execute
			DefaultConfigurationFileSaver saver = new DefaultConfigurationFileSaver(new NetReflectorProjectSerializer());
			saver.Save((IConfiguration) mockConfiguration.MockInstance, configFile);

			DefaultConfigurationFileLoader loader = new DefaultConfigurationFileLoader();
			IConfiguration configuration2 = loader.Load(configFile);

			// Verify
			Assert.IsNotNull (configuration2.Projects["Project One"]);
			Assert.IsNotNull (configuration2.Projects["Project Two"]);
			mockConfiguration.Verify();
		}
示例#2
0
        /// <summary>
        /// Begin loading the configuration.
        /// </summary>
        private void StartConfigurationLoad()
        {
            DisplayProgressMessage("Loading configuration, please wait...", 0);
            myStopwatch.Reset();
            myStopwatch.Start();
            var loader = new DefaultConfigurationFileLoader(this);
            myBodyEl = validationResults.Document.Body;
            myBodyEl.InnerHtml = string.Empty;
            this.configurationHierarchy.Initialise(myFileName);

            // Initialise the display
            DisplayConfig();
            ClearProcessed();

            try
            {
                // Attempt to load the configuration
                loader.Load(new FileInfo(myFileName));
            }
            catch (ConfigurationException error)
            {
                // There is an error with the configuration
                myBodyEl.AppendChild(
                    GenerateElement("div",
                    new HtmlAttribute("class", "error"),
                    GenerateElement("div", "Unable to load configuration:")));
                var errors = GenerateElement("ul");
                myBodyEl.AppendChild(errors);

                // Generate the error details
                Exception errorDetails = error;
                while (errorDetails != null)
                {
                    errors.AppendChild(
                        GenerateElement("li", errorDetails.Message));
                    errorDetails = errorDetails.InnerException;
                }

                // Log the base error
                LogMessage(error.Message);
                isConfigValid = false;
            }
            catch (PreprocessorException error)
            {
                // There was an error with pre-processing
                var message = "Preprocessing failed loading the XML: " + error.Message;
                myBodyEl.AppendChild(
                    GenerateElement("div",
                    new HtmlAttribute("class", "error"),
                    GenerateElement("div", message)));
                LogMessage(message);
                isConfigValid = false;
            }
            catch (Exception error)
            {
                // Catch-all exception block
                StringBuilder message = new StringBuilder();
                message.Append("An unexpected error has occurred while loading the configuration!" +
                    Environment.NewLine +
                    "Please report this error to the CCNet user group (http://groups.google.com/group/ccnet-user). This will help us to improve this application.");
                Exception currentError = error;
                while (currentError != null)
                {
                    message.AppendFormat("{0}{1} [{2}]", Environment.NewLine, currentError.Message, currentError.GetType().Name);
                    message.AppendFormat("{0}{1}", Environment.NewLine, currentError.StackTrace);
                    currentError = currentError.InnerException;
                    if (currentError != null)
                    {
                        message.AppendFormat("{0}{1} Inner Exception {1}", Environment.NewLine, new string('=', 10));
                    }
                }
                MessageBox.Show(this, message.ToString(), "Unexpected error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                isConfigValid = false;
            }
        }
        public void TestSerialization()
        {
            DefaultConfigurationFileLoader Loader = new DefaultConfigurationFileLoader();
            FileConfigurationService Service = new FileConfigurationService(Loader, null, new FileInfo(@"C:\Downloads\ccnet.config.xml"));

            IProject project = Service.Load().Projects["mh_refactor_p"];

            string Serialized = Serialize("project", project);
            System.Diagnostics.Debug.WriteLine(Serialized);
            Project Clone = (Project)Deserialize(Serialized);
        }
		protected void SetUp()
		{
			fileLoader = new DefaultConfigurationFileLoader();
		}