public void CanHandleNamelessModulesForSectionToSectionDependencies()
        {
            string infoXml =
                @"
<SolutionProfile xmlns='http://schemas.microsoft.com/pag/cab-profile/2.0'>
	<Section Name='Foo'>
		<Modules>
			<ModuleInfo AssemblyFile='Foo.dll' />
		</Modules>
	</Section>
	<Section>
		<Dependencies>
			<Dependency Name='Foo' />
		</Dependencies>
		<Modules>
			<ModuleInfo AssemblyFile='Bar.dll' />
		</Modules>
	</Section>
</SolutionProfile>";

            XmlStreamDependentModuleEnumerator enumerator = new XmlStreamDependentModuleEnumerator();

            enumerator.ModuleInfoStore = new MockModuleInfoStore(infoXml);

            IDependentModuleInfo[] results = (IDependentModuleInfo[])enumerator.EnumerateModules();

            Assert.AreEqual(2, results.Length);
            Assert.AreEqual("Foo.dll", results[0].AssemblyFile);
            Assert.IsNotNull(results[0].Name);
            Assert.AreEqual("Bar.dll", results[1].AssemblyFile);
            Assert.AreEqual(0, results[0].Dependencies.Count);
            Assert.AreEqual(1, results[1].Dependencies.Count);
            Assert.IsNotNull(results[1].Dependencies[0]);
            Assert.AreEqual(results[0].Name, results[1].Dependencies[0]);
        }
        public void HandlesMultipleSectionsInV2Xml()
        {
            string infoXml =
                @"
<SolutionProfile xmlns='http://schemas.microsoft.com/pag/cab-profile/2.0'>
	<Section>
		<Modules>
			<ModuleInfo AssemblyFile='Bogus1.dll' />
		</Modules>
	</Section>
	<Section>
		<Modules>
			<ModuleInfo AssemblyFile='Bogus2.dll' />
			<ModuleInfo AssemblyFile='Bogus3.dll' />
		</Modules>
	</Section>
</SolutionProfile>";

            XmlStreamDependentModuleEnumerator enumerator = new XmlStreamDependentModuleEnumerator();

            enumerator.ModuleInfoStore = new MockModuleInfoStore(infoXml);

            IModuleInfo[] results = enumerator.EnumerateModules();

            Assert.IsNotNull(results);
            Assert.AreEqual(3, results.Length);
            Assert.AreEqual("Bogus1.dll", results[0].AssemblyFile);
            Assert.AreEqual("Bogus2.dll", results[1].AssemblyFile);
            Assert.AreEqual("Bogus3.dll", results[2].AssemblyFile);
        }
        public void IgnoresReflectionForNameAndDependenciesWhenGivenV2XmlWithNameAndDependenciesElements()
        {
            Assembly assembly1 = ModuleCompilerHelper.GeneratedAssemblies["ModuleDependency1"];
            Assembly assembly2 = ModuleCompilerHelper.GeneratedAssemblies["ModuleDependency2"];

            string infoXmlTemplate =
                @"
<SolutionProfile xmlns='http://schemas.microsoft.com/pag/cab-profile/2.0'>
	<Section>
		<Modules>
			<ModuleInfo AssemblyFile='{0}' Name='Flarble'>
				<Dependencies/>
			</ModuleInfo>
			<ModuleInfo AssemblyFile='{1}' Name='Blarble'>
				<Dependencies/>
			</ModuleInfo>
		</Modules>
	</Section>
</SolutionProfile>";

            XmlStreamDependentModuleEnumerator enumerator = new XmlStreamDependentModuleEnumerator();

            enumerator.ModuleInfoStore =
                new MockModuleInfoStore(
                    String.Format(infoXmlTemplate, CodeBaseToFilename(assembly1.CodeBase), CodeBaseToFilename(assembly2.CodeBase)));

            IDependentModuleInfo[] results = (IDependentModuleInfo[])enumerator.EnumerateModules();

            Assert.IsNotNull(results);
            Assert.AreEqual("Flarble", results[0].Name);
            Assert.AreEqual("Blarble", results[1].Name);
            Assert.AreEqual(0, results[0].Dependencies.Count);
            Assert.AreEqual(0, results[1].Dependencies.Count);
        }
        public void EnumeratorUnderstandsV2Roles()
        {
            string infoXml =
                @"
<SolutionProfile xmlns='http://schemas.microsoft.com/pag/cab-profile/2.0'>
	<Section>
		<Modules>
			<ModuleInfo AssemblyFile='Bogus.dll'>
				<Roles>
					<Role Allow='Administrators' />
				</Roles>
			</ModuleInfo>
		</Modules>
	</Section>
</SolutionProfile>";

            XmlStreamDependentModuleEnumerator enumerator = new XmlStreamDependentModuleEnumerator();

            enumerator.ModuleInfoStore = new MockModuleInfoStore(infoXml);

            IModuleInfo[] results = enumerator.EnumerateModules();

            Assert.IsNotNull(results);
            Assert.IsNotNull(results[0].AllowedRoles);
            Assert.AreEqual(1, results[0].AllowedRoles.Count);
            Assert.AreEqual("Administrators", results[0].AllowedRoles[0]);
        }
        public void EnumeratorReturnsSingleModuleListedInV2Xml()
        {
            string infoXml =
                @"
<SolutionProfile xmlns='http://schemas.microsoft.com/pag/cab-profile/2.0'>
	<Section>
		<Modules>
			<ModuleInfo AssemblyFile='Bogus.dll' />
		</Modules>
	</Section>
</SolutionProfile>";

            XmlStreamDependentModuleEnumerator enumerator = new XmlStreamDependentModuleEnumerator();

            enumerator.ModuleInfoStore = new MockModuleInfoStore(infoXml);

            IModuleInfo[] results = enumerator.EnumerateModules();

            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.Length);
            Assert.AreEqual("Bogus.dll", results[0].AssemblyFile);
            Assert.IsNotNull(results[0].AllowedRoles);
            Assert.AreEqual(0, results[0].AllowedRoles.Count);
            Assert.IsNull(results[0].UpdateLocation);
        }
        public void PassingInvalidXmlThrows()
        {
            string infoXml = @"<InvalidSolutionProfile xmlns='http://schemas.microsoft.com/pag/cab-profile' />";
            XmlStreamDependentModuleEnumerator enumerator = new XmlStreamDependentModuleEnumerator();

            enumerator.ModuleInfoStore = new MockModuleInfoStore(infoXml);

            enumerator.EnumerateModules();
        }
        public void EnumeratorReturnsEmptyArrayWhenPassedEmptyString()
        {
            XmlStreamDependentModuleEnumerator enumerator = new XmlStreamDependentModuleEnumerator();

            enumerator.ModuleInfoStore = new MockModuleInfoStore("");

            IModuleInfo[] results = enumerator.EnumerateModules();

            Assert.IsNotNull(results);
            Assert.AreEqual(0, results.Length);
        }
        public void PassingV1XmlDoesNotThrow()
        {
            string infoXml = @"<SolutionProfile xmlns='http://schemas.microsoft.com/pag/cab-profile' />";
            XmlStreamDependentModuleEnumerator enumerator = new XmlStreamDependentModuleEnumerator();

            enumerator.ModuleInfoStore = new MockModuleInfoStore(infoXml);

            IModuleInfo[] results = enumerator.EnumerateModules();

            Assert.IsNotNull(results);
            Assert.AreEqual(0, results.Length);
        }
        public void SectionDependencyForMissingSectionThrows()
        {
            string infoXml =
                @"
<SolutionProfile xmlns='http://schemas.microsoft.com/pag/cab-profile/2.0'>
	<Section>
		<Dependencies>
			<Dependency Name='TheUnknownSection' />
		</Dependencies>
		<Modules>
			<ModuleInfo AssemblyFile='Foo.dll' />
		</Modules>
	</Section>
</SolutionProfile>";

            XmlStreamDependentModuleEnumerator enumerator = new XmlStreamDependentModuleEnumerator();

            enumerator.ModuleInfoStore = new MockModuleInfoStore(infoXml);

            enumerator.EnumerateModules();
        }