Permalink
Browse files

Setting up failing test for bad platform (may need to move the test t…

…o the test assembly finder specs though, not sure yet, still working it out)
  • Loading branch information...
codereflection committed Mar 1, 2012
1 parent 90eed95 commit 26f6533a7cbf2ea60624787ea3f45605c3504f64
@@ -71,50 +71,56 @@ public string GetAssemblyFilePath(string projectFilePath)
return Path.Combine (projectPath, Path.Combine(dir, assemblyName));
}
- public string GetPropertyValue(string platformConfig, string property)
+ public string GetPropertyValue(string platformName, string property)
{
- var condition = "'" + platformConfig + "'";
- var specific = (
- from XmlNode propertyGroup in ProjectNode.ChildNodes
- where propertyGroup.Name == "PropertyGroup" &&
- propertyGroup.Attributes != null &&
- propertyGroup.Attributes["Condition"] != null &&
- propertyGroup.Attributes["Condition"].InnerText.Contains(condition)
-
- from XmlNode outputNode in propertyGroup.ChildNodes
- where outputNode.Name == property
- select outputNode.InnerText).ToArray();
-
- var defaultConfig = (
- from XmlNode propertyGroup in ProjectNode.ChildNodes
- where propertyGroup.Name == "PropertyGroup" && (
- propertyGroup.Attributes == null ||
- propertyGroup.Attributes["Condition"] == null)
-
- from XmlNode outputNode in propertyGroup.ChildNodes
- where outputNode.Name == property
- select outputNode.InnerText).ToArray();
-
- switch (specific.Length)
+ var configAndPlatform = "'" + platformName + "'";
+ var specific = GetConfigAndPlatformPropertyValues(configAndPlatform, property);
+
+ var defaultConfig = GetDefaultPropertyValues(property);
+
+ if (specific.Length >= 1)
+ return specific[0];
+
+ if (specific.Length == 0)
{
- case 1:
- return specific[0];
- case 0:
- switch (defaultConfig.Length)
- {
- case 1:
- return defaultConfig[0];
- case 0:
- throw new InvalidOperationException(
- string.Format("No value found for property '{0}' using "
- + "platform configuration '{1}'", property, platformConfig));
- }
- break;
+ switch (defaultConfig.Length)
+ {
+ case 1:
+ return defaultConfig[0];
+ case 0:
+ throw new InvalidOperationException(
+ string.Format("No value found for property '{0}' using "
+ + "platform configuration '{1}'", property, platformName));
+ }
}
- throw new InvalidOperationException(
- string.Format("The property '{0}' had multiple values "
- + "applicable for the same platform configuration '{1}'",
- property, platformConfig));
+ return string.Empty;
+ }
+
+ string[] GetConfigAndPlatformPropertyValues(string configAndPlatform, string propertyName)
+ {
+ return (
+ from XmlNode propertyGroup in ProjectNode.ChildNodes
+ where propertyGroup.Name == "PropertyGroup" &&
+ propertyGroup.Attributes != null &&
+ propertyGroup.Attributes["Condition"] != null &&
+ propertyGroup.Attributes["Condition"].InnerText.Contains(configAndPlatform)
+
+ from XmlNode outputNode in propertyGroup.ChildNodes
+ where outputNode.Name == propertyName
+ select outputNode.InnerText).ToArray();
+ }
+
+ string[] GetDefaultPropertyValues(string propertyName)
+ {
+ return (
+ from XmlNode propertyGroup in ProjectNode.ChildNodes
+ where propertyGroup.Name == "PropertyGroup" && (
+ propertyGroup.Attributes == null ||
+ propertyGroup.Attributes["Condition"] == null)
+
+ from XmlNode outputNode in propertyGroup.ChildNodes
+ where outputNode.Name == propertyName
+ select outputNode.InnerText).ToArray();
}
public string GetDefaultPlatformConfig()
@@ -6,31 +6,24 @@
namespace Giles.Specs.Core.Configuration
{
[Subject(typeof(MsBuildProject))]
- public class an_msbuild_project
+ public class when_loading
{
protected static string projectPath;
protected static MsBuildProject project;
- private Establish context = () => {
+ Establish context = () =>
projectPath = "Giles.Specs.Core.Configuration.Resources.Giles.Specs.csproj";
- };
- }
- [Subject(typeof(MsBuildProject))]
- public class when_an_msbuild_project_is_loaded : an_msbuild_project
- {
- Because of = () => {
+ Because of = () =>
project = MsBuildProject.Load(TestResources.Read(projectPath));
- };
- It returns_referenced_assemblies_with_local_paths = () => {
+ It returns_referenced_assemblies_with_relative_paths = () => {
project.GetLocalAssemblyRefs()
- .Any(x => x == @"..\..\lib\NSubstitute.1.0.0.0\lib\35\NSubstitute.dll")
- .ShouldEqual(true);
+ .Count(x => x == @"..\..\lib\NSubstitute.1.0.0.0\lib\35\NSubstitute.dll")
+ .ShouldEqual(1);
project.GetLocalAssemblyRefs()
- .Any(x => x == @"..\..\tools\mspec\Machine.Specifications.dll")
- .ShouldEqual(true);
- project.GetLocalAssemblyRefs().Count().ShouldEqual(2);
+ .Count(x => x == @"..\..\tools\mspec\Machine.Specifications.dll")
+ .ShouldEqual(1);
};
It returns_the_default_platform_configuration = () =>
@@ -53,7 +46,27 @@ public class when_an_msbuild_project_is_loaded : an_msbuild_project
project.GetAssemblyFilePath(@"C:\projects\Giles\src\Giles.Specs\Giles.Specs.csproj")
.ShouldEqual(@"C:\projects\Giles\src\Giles.Specs\bin\Debug\Giles.Specs.dll");
- private It returns_the_assembly_name = () =>
+ It returns_the_assembly_name = () =>
project.GetAssemblyName().ShouldEqual(@"Giles.Specs");
}
+
+ [Subject(typeof(MsBuildProject))]
+ public class when_loading_a_project_with_an_invalid_default_platform
+ {
+ protected static string projectPath;
+ protected static MsBuildProject project;
+ static string defaultPlatformConfig;
+
+ Establish context = () =>
+ {
+ projectPath = "Giles.Specs.Core.Configuration.Resources.Giles.Specs.WithInvalidPlatform.csproj";
+ project = MsBuildProject.Load(TestResources.Read(projectPath));
+ };
+
+ Because of = () =>
+ defaultPlatformConfig = project.GetDefaultPlatformConfig();
+
+ It should_default_to_the_next_available_platform_in_the_project_file = () =>
+ defaultPlatformConfig.ShouldEqual("Debug|x86");
+ }
}
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{8FAE1516-9D4A-4575-83BF-515BC6AF8AC3}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Giles.Specs</RootNamespace>
+ <AssemblyName>Giles.Specs</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="..\ProjectVersion.cs">
+ <Link>Properties\ProjectVersion.cs</Link>
+ </Compile>
+ <Compile Include="Core\Configuration\GilesConfigFactorySpecs.cs" />
+ <Compile Include="Core\Configuration\SolutionConfigSpecs.cs" />
+ <Compile Include="Core\Runners\CommandProcessExecutorSpecs.cs" />
+ <Compile Include="Core\Runners\TestRunnerSpecs.cs" />
+ <Compile Include="Core\Watchers\SourceWatcherSpecs.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="Machine.Specifications, Version=0.3.0.0, Culture=neutral, PublicKeyToken=5c474de7a495cff1, processorArchitecture=MSIL">
+ <HintPath>..\..\tools\mspec\Machine.Specifications.dll</HintPath>
+ </Reference>
+ <Reference Include="NSubstitute">
+ <HintPath>..\..\lib\NSubstitute.1.0.0.0\lib\35\NSubstitute.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Giles.Core\Giles.Core.csproj">
+ <Project>{9039E7FA-989E-46ED-B031-FB67571E8385}</Project>
+ <Name>Giles.Core</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -110,6 +110,9 @@
<ItemGroup>
<EmbeddedResource Include="Core\Configuration\Resources\Giles.Core.WithMSpec.csproj" />
</ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Core\Configuration\Resources\Giles.Specs.WithInvalidPlatform.csproj" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

0 comments on commit 26f6533

Please sign in to comment.