Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Introduced ShouldBeOfExactType and ShouldBeAssignableTo with overload…

…s and deprecated old missleading methods. Closes #171
  • Loading branch information...
commit 5e28bfc7b19421185576a23944ae131af5f043c8 1 parent 34d423d
@danielmarbach danielmarbach authored
View
89 Source/Machine.Specifications.Should/Fody.targets
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Choose>
+ <When Condition="$(NCrunchOriginalSolutionDir) != '' And $(NCrunchOriginalSolutionDir) != '*Undefined*'">
+ <PropertyGroup>
+ <FodySolutionDir>$(NCrunchOriginalSolutionDir)</FodySolutionDir>
+ </PropertyGroup>
+ </When>
+ <When Condition="$(SolutionDir) != '' And $(SolutionDir) != '*Undefined*'">
+ <PropertyGroup>
+ <FodySolutionDir>$(SolutionDir)</FodySolutionDir>
+ </PropertyGroup>
+ </When>
+ <When Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">
+ <PropertyGroup>
+ <FodySolutionDir>$(MSBuildProjectDirectory)\..\</FodySolutionDir>
+ </PropertyGroup>
+ </When>
+ </Choose>
+ <Choose>
+ <When Condition="$(KeyOriginatorFile) != '' And $(KeyOriginatorFile) != '*Undefined*'">
+ <PropertyGroup>
+ <FodyKeyFilePath>$(KeyOriginatorFile)</FodyKeyFilePath>
+ </PropertyGroup>
+ </When>
+ <When Condition="$(AssemblyOriginatorKeyFile) != '' And $(AssemblyOriginatorKeyFile) != '*Undefined*'">
+ <PropertyGroup>
+ <FodyKeyFilePath>$(AssemblyOriginatorKeyFile)</FodyKeyFilePath>
+ </PropertyGroup>
+ </When>
+ <Otherwise >
+ <PropertyGroup>
+ <FodyKeyFilePath></FodyKeyFilePath>
+ </PropertyGroup>
+ </Otherwise>
+ </Choose>
+ <PropertyGroup>
+ <IntermediateDir>$(ProjectDir)$(IntermediateOutputPath)</IntermediateDir>
+ <FodyMessageImportance Condition="$(FodyMessageImportance) == '' Or $(FodyMessageImportance) == '*Undefined*'">Low</FodyMessageImportance>
+ <FodySignAssembly Condition="$(FodySignAssembly) == '' Or $(FodySignAssembly) == '*Undefined*'">$(SignAssembly)</FodySignAssembly>
+ <FodyPath Condition="$(FodyPath) == '' Or $(FodyPath) == '*Undefined*'">$(MSBuildThisFileDirectory)</FodyPath>
+ </PropertyGroup>
+ <UsingTask
+ TaskName="Fody.WeavingTask"
+ AssemblyFile="$(FodyPath)\Fody.dll" />
+ <Target
+ AfterTargets="AfterCompile"
+ Name="WinFodyTarget"
+ Condition=" '$(OS)' == 'Windows_NT'">
+
+ <Fody.WeavingTask
+ AssemblyPath="@(IntermediateAssembly)"
+ IntermediateDir="$(IntermediateDir)"
+ KeyFilePath="$(FodyKeyFilePath)"
+ MessageImportance="$(FodyMessageImportance)"
+ ProjectDirectory="$(ProjectDir)"
+ SolutionDir="$(FodySolutionDir)"
+ References="@(ReferencePath)"
+ SignAssembly="$(FodySignAssembly)"
+ ReferenceCopyLocalPaths="@(ReferenceCopyLocalPaths)"
+ DefineConstants="$(DefineConstants)"
+ />
+ </Target>
+
+ <Target
+ AfterTargets="AfterBuild"
+ Name="NonWinFodyTarget"
+ Condition=" '$(OS)' != 'Windows_NT'">
+ <Fody.WeavingTask
+ AssemblyPath="$(TargetPath)"
+ IntermediateDir="$(IntermediateDir)"
+ KeyFilePath="$(FodyKeyFilePath)"
+ MessageImportance="$(FodyMessageImportance)"
+ ProjectDirectory="$(ProjectDir)"
+ SolutionDir="$(FodySolutionDir)"
+ References="@(ReferencePath)"
+ SignAssembly="$(FodySignAssembly)"
+ ReferenceCopyLocalPaths="$(ReferenceCopyLocalPaths)"
+ DefineConstants="$(DefineConstants)"
+ />
+ </Target>
+
+
+ <!--Support for ncrunch-->
+ <ItemGroup>
+ <None Include="$(FodyPath)\*.*" />
+ </ItemGroup>
+
+</Project>
View
4 Source/Machine.Specifications.Should/FodyWeavers.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Weavers>
+ <Obsolete />
+</Weavers>
View
11 Source/Machine.Specifications.Should/Machine.Specifications.Should.csproj
@@ -12,6 +12,7 @@
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AssemblyOriginatorKeyFile>..\Machine.snk</AssemblyOriginatorKeyFile>
+ <FodyPath>..\..\packages\Fody.1.19.1.0</FodyPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -31,6 +32,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Obsolete">
+ <HintPath>..\..\packages\Obsolete.Fody.3.0.1.0\Lib\NET35\Obsolete.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
@@ -64,11 +69,15 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
+ <None Include="Fody.targets" />
<None Include="packages.config" />
</ItemGroup>
+ <ItemGroup>
+ <Content Include="FodyWeavers.xml" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-
<Import Project="..\..\packages\GitFlowVersionTask.0.14.0\Build\GitFlowVersionTask.targets" Condition="Exists('..\..\packages\GitFlowVersionTask.0.14.0\Build\GitFlowVersionTask.targets')" />
+ <Import Project="Fody.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">
View
82 Source/Machine.Specifications.Should/ShouldExtensionMethods.cs
@@ -94,6 +94,7 @@ public static object ShouldNotBeTheSameAs(this object actual, object expected)
return expected;
}
+ [ObsoleteEx(Message = "This method behaved like `ShouldBeAssignableTo` which is missleading. For exact type comparison use `ShouldBeOfExactType`, for assignability verification use `ShouldBeAssignableTo`. Redesigned because of #171.", RemoveInVersion = "0.9", TreatAsErrorFromVersion = "0.8")]
public static void ShouldBeOfType(this object actual, Type expected)
{
if (actual == null)
@@ -109,16 +110,19 @@ public static void ShouldBeOfType(this object actual, Type expected)
}
}
+ [ObsoleteEx(Message = "This method behaved like `ShouldBeAssignableTo` which is missleading. For exact type comparison use `ShouldBeOfExactType`, for assignability verification use `ShouldBeAssignableTo`. Redesigned because of #171.", RemoveInVersion = "0.9", TreatAsErrorFromVersion = "0.8")]
public static void ShouldBeOfType<T>(this object actual)
{
actual.ShouldBeOfType(typeof(T));
}
+ [ObsoleteEx(Message = "This method behaved like `ShouldBeAssignableTo` which is missleading. For exact type comparison use `ShouldBeOfExactType`, for assignability verification use `ShouldBeAssignableTo`. Redesigned because of #171.", RemoveInVersion = "0.9", TreatAsErrorFromVersion = "0.8")]
public static void ShouldBe(this object actual, Type expected)
{
actual.ShouldBeOfType(expected);
}
+ [ObsoleteEx(Message = "This method should no longer be used. Redesigned because of #171. See replacement.", RemoveInVersion = "0.9", TreatAsErrorFromVersion = "0.8", Replacement = "ShouldNotBeOfExactType")]
public static void ShouldNotBeOfType(this object actual, Type expected)
{
if (actual.GetType() == expected)
@@ -128,6 +132,84 @@ public static void ShouldNotBeOfType(this object actual, Type expected)
}
}
+ public static void ShouldBeOfExactType(this object actual, Type expected)
+ {
+ if (actual == null)
+ {
+ throw new SpecificationException(string.Format("Should be of type {0} but is [null]", expected));
+ }
+
+ if (actual.GetType() != expected)
+ {
+ throw new SpecificationException(string.Format("Should be of type {0} but is of type {1}", expected,
+ actual.GetType()));
+ }
+ }
+
+ public static void ShouldNotBeOfExactType(this object actual, Type expected)
+ {
+ if (actual == null)
+ {
+ throw new SpecificationException(string.Format("Should not be of type {0} but is [null]", expected));
+ }
+
+ if (actual.GetType() == expected)
+ {
+ throw new SpecificationException(string.Format("Should not be of type {0} but is of type {1}", expected,
+ actual.GetType()));
+ }
+ }
+
+ public static void ShouldBeOfExactType<T>(this object actual)
+ {
+ actual.ShouldBeOfExactType(typeof(T));
+ }
+
+ public static void ShouldNotBeOfExactType<T>(this object actual)
+ {
+ actual.ShouldNotBeOfExactType(typeof(T));
+ }
+
+ public static void ShouldBeAssignableTo(this object actual, Type expected)
+ {
+ if (actual == null)
+ {
+ throw new SpecificationException(string.Format("Should be assignable to type {0} but is [null]", expected));
+ }
+
+ if (!expected.IsAssignableFrom(actual.GetType()))
+ {
+ throw new SpecificationException(string.Format("Should be assignable to type {0} but is not. Actual type is {1}",
+ expected,
+ actual.GetType()));
+ }
+ }
+
+ public static void ShouldNotBeAssignableTo(this object actual, Type expected)
+ {
+ if (actual == null)
+ {
+ throw new SpecificationException(string.Format("Should not be assignable to type {0} but is [null]", expected));
+ }
+
+ if (expected.IsAssignableFrom(actual.GetType()))
+ {
+ throw new SpecificationException(string.Format("Should not be assignable to type {0} but is. Actual type is {1}",
+ expected,
+ actual.GetType()));
+ }
+ }
+
+ public static void ShouldBeAssignableTo<T>(this object actual)
+ {
+ actual.ShouldBeAssignableTo(typeof(T));
+ }
+
+ public static void ShouldNotBeAssignableTo<T>(this object actual)
+ {
+ actual.ShouldNotBeAssignableTo(typeof(T));
+ }
+
public static void ShouldMatch<T>(this T actual, Expression<Func<T, bool>> condition)
{
var matches = condition.Compile().Invoke(actual);
View
2  Source/Machine.Specifications.Should/packages.config
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
+ <package id="Fody" version="1.19.1.0" targetFramework="net35" developmentDependency="true" />
<package id="GitFlowVersionTask" version="0.14.0" targetFramework="net35" />
+ <package id="Obsolete.Fody" version="3.0.1.0" targetFramework="net35" developmentDependency="true" />
</packages>
View
2  Source/Runners/Machine.Specifications.ReSharperRunner.8.0/Machine.Specifications.ReSharperRunner.8.0.csproj
@@ -111,7 +111,6 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
- <None Include="ripple.dependencies.config" />
<None Include="Resources\Machine.Specifications.ico" />
</ItemGroup>
<ItemGroup>
@@ -134,7 +133,6 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-
<Import Project="..\..\..\packages\JetBrains.ReSharper.SDK.8.0.1243\build\JetBrains.ReSharper.SDK.Targets" Condition="Exists('..\..\..\packages\JetBrains.ReSharper.SDK.8.0.1243\build\JetBrains.ReSharper.SDK.Targets')" />
<Import Project="..\..\..\packages\GitFlowVersionTask.0.14.0\Build\GitFlowVersionTask.targets" Condition="Exists('..\..\..\packages\GitFlowVersionTask.0.14.0\Build\GitFlowVersionTask.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Please sign in to comment.
Something went wrong with that request. Please try again.