-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ReSharper support for derived Subject attributes
- Loading branch information
1 parent
12c6f6b
commit 1009584
Showing
7 changed files
with
238 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
Source/Machine.Specifications.Example.DerivedSubject/DerivedSubjectSpecs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
|
||
namespace Machine.Specifications.Example.DerivedSubject | ||
{ | ||
public class Account | ||
{ | ||
private decimal _balance; | ||
|
||
public decimal Balance | ||
{ | ||
get { return _balance; } | ||
set { _balance = value; } | ||
} | ||
|
||
public void Transfer(decimal amount, Account toAccount) | ||
{ | ||
if (amount > _balance) | ||
{ | ||
throw new Exception(String.Format("Cannot transfer ${0}. The available balance is ${1}.", amount, _balance)); | ||
} | ||
|
||
_balance -= amount; | ||
toAccount.Balance += amount; | ||
} | ||
} | ||
|
||
[MySubject(typeof(Account), "Funds transfer")] | ||
public class when_transferring_between_two_accounts_with_derived_subject | ||
: AccountSpecs | ||
{ | ||
Because of = () => | ||
fromAccount.Transfer(1m, toAccount); | ||
|
||
It should_debit_the_from_account_by_the_amount_transferred = () => | ||
fromAccount.Balance.ShouldEqual(0m); | ||
|
||
It should_credit_the_to_account_by_the_amount_transferred = () => | ||
toAccount.Balance.ShouldEqual(2m); | ||
} | ||
|
||
[Subject(typeof(Account), "Funds transfer")] | ||
public class when_transferring_between_two_accounts_with_normal_subject | ||
: AccountSpecs | ||
{ | ||
Because of = () => | ||
fromAccount.Transfer(1m, toAccount); | ||
|
||
It should_debit_the_from_account_by_the_amount_transferred = () => | ||
fromAccount.Balance.ShouldEqual(0m); | ||
|
||
It should_credit_the_to_account_by_the_amount_transferred = () => | ||
toAccount.Balance.ShouldEqual(2m); | ||
} | ||
|
||
public abstract class AccountSpecs | ||
{ | ||
protected static Account fromAccount; | ||
protected static Account toAccount; | ||
|
||
Establish context = () => | ||
{ | ||
fromAccount = new Account { Balance = 1m }; | ||
toAccount = new Account { Balance = 1m }; | ||
}; | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...pecifications.Example.DerivedSubject/Machine.Specifications.Example.DerivedSubject.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?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>9.0.30729</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{13650EC6-35A0-429A-A779-DCA0214E7F79}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Machine.Specifications.Example.DerivedSubject</RootNamespace> | ||
<AssemblyName>Machine.Specifications.Example.DerivedSubject</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<FileUpgradeFlags> | ||
</FileUpgradeFlags> | ||
<OldToolsVersion>3.5</OldToolsVersion> | ||
<UpgradeBackupLocation /> | ||
<PublishUrl>publish\</PublishUrl> | ||
<Install>true</Install> | ||
<InstallFrom>Disk</InstallFrom> | ||
<UpdateEnabled>false</UpdateEnabled> | ||
<UpdateMode>Foreground</UpdateMode> | ||
<UpdateInterval>7</UpdateInterval> | ||
<UpdateIntervalUnits>Days</UpdateIntervalUnits> | ||
<UpdatePeriodically>false</UpdatePeriodically> | ||
<UpdateRequired>false</UpdateRequired> | ||
<MapFileExtensions>true</MapFileExtensions> | ||
<ApplicationRevision>0</ApplicationRevision> | ||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> | ||
<IsWebBootstrapper>false</IsWebBootstrapper> | ||
<UseApplicationTrust>false</UseApplicationTrust> | ||
<BootstrapperEnabled>true</BootstrapperEnabled> | ||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> | ||
<RestorePackages>true</RestorePackages> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<NoWarn>169</NoWarn> | ||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core"> | ||
<RequiredTargetFramework>3.5</RequiredTargetFramework> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="..\SharedAssemblyInfo.cs"> | ||
<Link>Properties\SharedAssemblyInfo.cs</Link> | ||
</Compile> | ||
<Compile Include="..\VersionInfo.cs"> | ||
<Link>Properties\VersionInfo.cs</Link> | ||
</Compile> | ||
<Compile Include="DerivedSubjectSpecs.cs" /> | ||
<Compile Include="MySubjectAttribute.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Machine.Specifications\Machine.Specifications.csproj"> | ||
<Project>{CCD02629-1262-4F78-9E9F-AC97B942D0E7}</Project> | ||
<Name>Machine.Specifications</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5"> | ||
<Visible>False</Visible> | ||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> | ||
<Install>false</Install> | ||
</BootstrapperPackage> | ||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> | ||
<Visible>False</Visible> | ||
<ProductName>.NET Framework 3.5 SP1</ProductName> | ||
<Install>true</Install> | ||
</BootstrapperPackage> | ||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1"> | ||
<Visible>False</Visible> | ||
<ProductName>Windows Installer 3.1</ProductName> | ||
<Install>true</Install> | ||
</BootstrapperPackage> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Import Project="$(SolutionDir)\.nuget\nuget.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> |
19 changes: 19 additions & 0 deletions
19
Source/Machine.Specifications.Example.DerivedSubject/MySubjectAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
|
||
namespace Machine.Specifications.Example.DerivedSubject | ||
{ | ||
public class MySubjectAttribute : SubjectAttribute | ||
{ | ||
public MySubjectAttribute(Type subjectType) : base(subjectType) | ||
{ | ||
} | ||
|
||
public MySubjectAttribute(Type subjectType, string subject) : base(subjectType, subject) | ||
{ | ||
} | ||
|
||
public MySubjectAttribute(string subject) : base(subject) | ||
{ | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Source/Machine.Specifications.Example.DerivedSubject/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
|
||
[assembly: AssemblyTitle("Machine.Specifications.Example.DerivedSubject")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
|
||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
|
||
[assembly: Guid("e01bfd4e-4f67-4681-b84e-1aaa4217f239")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters