public void UpgradeProjectExtensionsTest() { string filename = Path.GetTempFileName(); try { CodeConfiguration oldConfiguration = new CodeConfiguration(); SourceHandlerConfiguration sourceHandler = new SourceHandlerConfiguration(); ExtensionConfiguration oldExtension = new ExtensionConfiguration(); oldExtension.Name = "csproj"; sourceHandler.ProjectExtensions.Add(oldExtension); oldConfiguration.Handlers.Add(sourceHandler); oldConfiguration.Save(filename); CodeConfiguration newConfiguration = CodeConfiguration.Load(filename); Assert.AreEqual(2, newConfiguration.Handlers.Count, "New handler was not created."); ProjectHandlerConfiguration projectHandlerConfiguration = newConfiguration.Handlers[0] as ProjectHandlerConfiguration; Assert.IsNotNull(projectHandlerConfiguration, "Expected a project handler config to be created."); Assert.IsNull(projectHandlerConfiguration.AssemblyName); Assert.AreEqual(typeof(MSBuildProjectParser).FullName, projectHandlerConfiguration.ParserType); Assert.AreEqual(1, projectHandlerConfiguration.ProjectExtensions.Count, "Unexpected number of project extensions."); Assert.AreEqual(oldExtension.Name, projectHandlerConfiguration.ProjectExtensions[0].Name); } finally { try { File.Delete(filename); } catch { } } }
public void SerializeAndDeserializeTest() { CodeConfiguration origConfig = new CodeConfiguration(); ElementConfiguration elementConfiguration1 = new ElementConfiguration(); elementConfiguration1.ElementType = ElementType.Using; elementConfiguration1.Id = "TestId"; origConfig.Elements.Add(elementConfiguration1); ElementConfiguration elementConfiguration2 = new ElementConfiguration(); elementConfiguration2.ElementType = ElementType.Namespace; origConfig.Elements.Add(elementConfiguration2); ElementReferenceConfiguration elementReferenceConfiguration = new ElementReferenceConfiguration(); elementReferenceConfiguration.Id = "TestId"; origConfig.Elements.Add(elementReferenceConfiguration); RegionConfiguration regionConfiguration = new RegionConfiguration(); regionConfiguration.Name = "Test Region"; origConfig.Elements.Add(regionConfiguration); origConfig.ResolveReferences(); Assert.AreEqual( elementConfiguration1.Elements.Count, elementReferenceConfiguration.ReferencedElement.Elements.Count, "Element reference was not resolved."); string tempFile = Path.GetTempFileName(); try { // // Save the configuration to an XML file // origConfig.Save(tempFile); // // Load the configuration from the XML file // CodeConfiguration loadedConfig = CodeConfiguration.Load(tempFile); Assert.IsNotNull(loadedConfig, "Loaded configuration should not be null."); Assert.AreEqual(origConfig.Elements.Count, loadedConfig.Elements.Count, "An unexpected number of config elements were deserialized."); for (int index = 0; index < origConfig.Elements.Count; index++) { if (origConfig.Elements[index] is ElementConfiguration) { ElementConfiguration origElement = origConfig.Elements[index] as ElementConfiguration; ElementConfiguration loadedElement = loadedConfig.Elements[index] as ElementConfiguration; Assert.AreEqual(origElement.ElementType, loadedElement.ElementType, "Unexpected element type."); } else if (origConfig.Elements[index] is ElementReferenceConfiguration) { ElementReferenceConfiguration origElement = origConfig.Elements[index] as ElementReferenceConfiguration; ElementReferenceConfiguration loadedElement = loadedConfig.Elements[index] as ElementReferenceConfiguration; Assert.AreEqual(origElement.Id, loadedElement.Id, "Unexpected element type."); Assert.AreEqual( origElement.ReferencedElement.Id, loadedElement.ReferencedElement.Id, "Unexpected referenced element."); } else if (origConfig.Elements[index] is RegionConfiguration) { RegionConfiguration origRegion = origConfig.Elements[index] as RegionConfiguration; RegionConfiguration loadedRegion = loadedConfig.Elements[index] as RegionConfiguration; Assert.AreEqual(origRegion.Name, loadedRegion.Name, "Unexpected region name."); } } } finally { File.Delete(tempFile); } }