From f4d4ff3bf1914fd35691f15d8c02a1838a63008d Mon Sep 17 00:00:00 2001 From: Attila Sztupak Date: Tue, 29 Jun 2010 10:05:44 +0200 Subject: [PATCH] .feature files are working like expected in silverlight projects added "mstest.silverlight" generator --- .../Configuration/GeneratorConfiguration.cs | 11 +- Generator/TechTalk.SpecFlow.Generator.csproj | 187 +++++++++--------- .../MsTestSilverlightGeneratorProvider.cs | 124 ++++++++++++ Installer/SpecFlowInstaller/Common.wxi | 1 + .../SpecFlowInstaller/Product.Generated.wxs | 27 +-- .../SpecFlowInstaller.wixproj | 187 +++++++++--------- Installer/SpecFlowInstaller/VS2010.wxs | 10 + 7 files changed, 348 insertions(+), 199 deletions(-) create mode 100755 Generator/UnitTestProvider/MsTestSilverlightGeneratorProvider.cs diff --git a/Generator/Configuration/GeneratorConfiguration.cs b/Generator/Configuration/GeneratorConfiguration.cs index 9ff0be821..f1f960d47 100644 --- a/Generator/Configuration/GeneratorConfiguration.cs +++ b/Generator/Configuration/GeneratorConfiguration.cs @@ -74,10 +74,13 @@ private void SetUnitTestDefaultsByName(string name) break; case "xunit": GeneratorUnitTestProviderType = typeof(XUnitTestGeneratorProvider); - break; - case "mstest": - GeneratorUnitTestProviderType = typeof(MsTestGeneratorProvider); - break; + break; + case "mstest": + GeneratorUnitTestProviderType = typeof(MsTestGeneratorProvider); + break; + case "mstest.silverlight": + GeneratorUnitTestProviderType = typeof(MsTestSilverlightGeneratorProvider); + break; default: GeneratorUnitTestProviderType = null; break; diff --git a/Generator/TechTalk.SpecFlow.Generator.csproj b/Generator/TechTalk.SpecFlow.Generator.csproj index 70701ee13..6efba04a1 100644 --- a/Generator/TechTalk.SpecFlow.Generator.csproj +++ b/Generator/TechTalk.SpecFlow.Generator.csproj @@ -1,100 +1,101 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {453D8014-B6CD-4E86-80A8-D59F59092334} - Library - Properties - TechTalk.SpecFlow.Generator - TechTalk.SpecFlow.Generator - v3.5 - 512 - true - ..\specflow.snk - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - 3.5 - - - 3.5 - - - 3.5 - - - - - - - Configuration\ConfigDefaults.cs - - - Configuration\ConfigurationSectionHandler.cs - - - Configuration\ConfigurationServices.cs - - - Configuration\MissingOrPendingStepsOutcome.cs - - - StringExtensions.cs - - - VersionInfo.cs - - - - - - - - - - - - - - - - - - - - {7CCEF6D6-FC17-422E-9BED-EDD752B6496F} - TechTalk.SpecFlow.Parser - - - + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {453D8014-B6CD-4E86-80A8-D59F59092334} + Library + Properties + TechTalk.SpecFlow.Generator + TechTalk.SpecFlow.Generator + v3.5 + 512 + true + ..\specflow.snk + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + Configuration\ConfigDefaults.cs + + + Configuration\ConfigurationSectionHandler.cs + + + Configuration\ConfigurationServices.cs + + + Configuration\MissingOrPendingStepsOutcome.cs + + + StringExtensions.cs + + + VersionInfo.cs + + + + + + + + + + + + + + + + + + + + + {7CCEF6D6-FC17-422E-9BED-EDD752B6496F} + TechTalk.SpecFlow.Parser + + + + --> \ No newline at end of file diff --git a/Generator/UnitTestProvider/MsTestSilverlightGeneratorProvider.cs b/Generator/UnitTestProvider/MsTestSilverlightGeneratorProvider.cs new file mode 100755 index 000000000..aa0231d9e --- /dev/null +++ b/Generator/UnitTestProvider/MsTestSilverlightGeneratorProvider.cs @@ -0,0 +1,124 @@ +using System.CodeDom; +using System.Collections.Generic; + +namespace TechTalk.SpecFlow.Generator.UnitTestProvider +{ + // TODO: it's an ugly copy-paste of MsTestGeneratorProvider - we should consider refactoring the generator creation to support custom factories. + public class MsTestSilverlightGeneratorProvider : IUnitTestGeneratorProvider + { + private const string TESTFIXTURE_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute"; + private const string TEST_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute"; + private const string PROPERTY_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute"; + private const string TESTFIXTURESETUP_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute"; + private const string TESTFIXTURETEARDOWN_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute"; + private const string TESTSETUP_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute"; + private const string TESTTEARDOWN_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute"; + private const string IGNORE_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.IgnoreAttribute"; + private const string DESCRIPTION_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute"; + + private const string FEATURE_TITILE_PROPERTY_NAME = "FeatureTitle"; + private const string FEATURE_TITILE_KEY = "FeatureTitle"; + + private const string TESTCONTEXT_TYPE = "Microsoft.VisualStudio.TestTools.UnitTesting.TestContext"; + + private CodeTypeDeclaration currentTestTypeDeclaration = null; + + public void SetTestFixture(CodeTypeDeclaration typeDeclaration, string title, string description) + { + typeDeclaration.CustomAttributes.Add( + new CodeAttributeDeclaration( + new CodeTypeReference(TESTFIXTURE_ATTR))); + + //as in mstest, you cannot mark classes with the description attribute, we + //just remember the feature title, and we will apply it for each test method + typeDeclaration.UserData[FEATURE_TITILE_KEY] = title; + + currentTestTypeDeclaration = typeDeclaration; + } + + private void SetDescription(CodeAttributeDeclarationCollection customAttributes, string description) + { + customAttributes.Add( + new CodeAttributeDeclaration( + new CodeTypeReference(DESCRIPTION_ATTR), + new CodeAttributeArgument( + new CodePrimitiveExpression(description)))); + } + + private void SetProperty(CodeAttributeDeclarationCollection customAttributes, string name, string value) + { + customAttributes.Add( + new CodeAttributeDeclaration( + new CodeTypeReference(PROPERTY_ATTR), + new CodeAttributeArgument( + new CodePrimitiveExpression(name)), + new CodeAttributeArgument( + new CodePrimitiveExpression(value)))); + } + + public void SetTestFixtureCategories(CodeTypeDeclaration typeDeclaration, IEnumerable categories) + { + //MsTest does not support caregories... :( + } + + public void SetTest(CodeMemberMethod memberMethod, string title) + { + memberMethod.CustomAttributes.Add( + new CodeAttributeDeclaration( + new CodeTypeReference(TEST_ATTR))); + + SetDescription(memberMethod.CustomAttributes, title); + + if (currentTestTypeDeclaration == null) + return; + + string featureTitle = currentTestTypeDeclaration.UserData[FEATURE_TITILE_KEY] as string; + if (featureTitle != null) + SetProperty(memberMethod.CustomAttributes, FEATURE_TITILE_PROPERTY_NAME, featureTitle); + } + + public void SetTestCategories(CodeMemberMethod memberMethod, IEnumerable categories) + { + //MsTest does not support caregories... :( + } + + public void SetTestSetup(CodeMemberMethod memberMethod) + { + memberMethod.CustomAttributes.Add( + new CodeAttributeDeclaration( + new CodeTypeReference(TESTSETUP_ATTR))); + } + + public void SetTestFixtureSetup(CodeMemberMethod memberMethod) + { + memberMethod.Attributes |= MemberAttributes.Static; + + memberMethod.CustomAttributes.Add( + new CodeAttributeDeclaration( + new CodeTypeReference(TESTFIXTURESETUP_ATTR))); + } + + public void SetTestFixtureTearDown(CodeMemberMethod memberMethod) + { + memberMethod.Attributes |= MemberAttributes.Static; + + memberMethod.CustomAttributes.Add( + new CodeAttributeDeclaration( + new CodeTypeReference(TESTFIXTURETEARDOWN_ATTR))); + } + + public void SetTestTearDown(CodeMemberMethod memberMethod) + { + memberMethod.CustomAttributes.Add( + new CodeAttributeDeclaration( + new CodeTypeReference(TESTTEARDOWN_ATTR))); + } + + public void SetIgnore(CodeTypeMember codeTypeMember) + { + codeTypeMember.CustomAttributes.Add( + new CodeAttributeDeclaration( + new CodeTypeReference(IGNORE_ATTR))); + } + } +} \ No newline at end of file diff --git a/Installer/SpecFlowInstaller/Common.wxi b/Installer/SpecFlowInstaller/Common.wxi index 25b33b64a..e6ea46dc9 100644 --- a/Installer/SpecFlowInstaller/Common.wxi +++ b/Installer/SpecFlowInstaller/Common.wxi @@ -8,5 +8,6 @@ + diff --git a/Installer/SpecFlowInstaller/Product.Generated.wxs b/Installer/SpecFlowInstaller/Product.Generated.wxs index 8c6815581..8cc2898fd 100644 --- a/Installer/SpecFlowInstaller/Product.Generated.wxs +++ b/Installer/SpecFlowInstaller/Product.Generated.wxs @@ -1,13 +1,16 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Installer/SpecFlowInstaller/SpecFlowInstaller.wixproj b/Installer/SpecFlowInstaller/SpecFlowInstaller.wixproj index 25456bb47..2a66a6bd1 100644 --- a/Installer/SpecFlowInstaller/SpecFlowInstaller.wixproj +++ b/Installer/SpecFlowInstaller/SpecFlowInstaller.wixproj @@ -1,92 +1,99 @@ - - - Debug - x86 - 3.5 - {89167eb9-f458-48da-9d8f-f639a74f5871} - 2.0 - SpecFlowSetup - Package - $(MSBuildExtensionsPath32)\Microsoft\WiX\v3.5\Wix.targets - $(MSBuildExtensionsPath)\Microsoft\WiX\v3.5\Wix.targets - - - bin\$(Configuration)\ - obj\$(Configuration)\ - Debug - - - bin\$(Configuration)\ - obj\$(Configuration)\ - - - - - - - Product.wxs - True - - - - - - TechTalk.SpecFlow.Generator - {453d8014-b6cd-4e86-80a8-d59f59092334} - True - Binaries - INSTALLLOCATION - - - TechTalk.SpecFlow.Parser - {7ccef6d6-fc17-422e-9bed-edd752b6496f} - True - Binaries - INSTALLLOCATION - - - TechTalk.SpecFlow.Reporting - {fc43509f-e7d3-40c4-b4c3-1e6c9d5530a4} - True - Binaries - INSTALLLOCATION - - - TechTalk.SpecFlow - {413ee28c-4f89-4c6f-ba1e-2cdee4cd43b4} - True - Binaries - INSTALLLOCATION - - - TechTalk.SpecFlow.Tools - {87be7fe6-c3de-4409-abf6-fa5b60af3de1} - True - Binaries - INSTALLLOCATION - - - TechTalk.SpecFlow.VsIntegration - {5703ca95-a08a-46ae-ae24-db6b21fd6f7e} - True - Binaries - INSTALLLOCATION - - - - - $(WixExtDir)\WixUIExtension.dll - WixUIExtension - - - $(WixExtDir)\WixVSExtension.dll - WixVSExtension - - - - - - + + + Debug + x86 + 3.5 + {89167eb9-f458-48da-9d8f-f639a74f5871} + 2.0 + SpecFlowSetup + Package + $(MSBuildExtensionsPath32)\Microsoft\WiX\v3.5\Wix.targets + $(MSBuildExtensionsPath)\Microsoft\WiX\v3.5\Wix.targets + + + bin\$(Configuration)\ + obj\$(Configuration)\ + Debug + + + bin\$(Configuration)\ + obj\$(Configuration)\ + + + + + + + Product.wxs + True + + + + + + TechTalk.SpecFlow.Generator + {453d8014-b6cd-4e86-80a8-d59f59092334} + True + Binaries + INSTALLLOCATION + + + TechTalk.SpecFlow.Parser + {7ccef6d6-fc17-422e-9bed-edd752b6496f} + True + Binaries + INSTALLLOCATION + + + TechTalk.SpecFlow.Reporting + {fc43509f-e7d3-40c4-b4c3-1e6c9d5530a4} + True + Binaries + INSTALLLOCATION + + + TechTalk.SpecFlow.Silverlight + {b93f95cf-bf89-4d92-bb0f-86885b9b6dce} + True + Binaries;Content;Satellites + INSTALLLOCATION + + + TechTalk.SpecFlow + {413ee28c-4f89-4c6f-ba1e-2cdee4cd43b4} + True + Binaries + INSTALLLOCATION + + + TechTalk.SpecFlow.Tools + {87be7fe6-c3de-4409-abf6-fa5b60af3de1} + True + Binaries + INSTALLLOCATION + + + TechTalk.SpecFlow.VsIntegration + {5703ca95-a08a-46ae-ae24-db6b21fd6f7e} + True + Binaries + INSTALLLOCATION + + + + + $(WixExtDir)\WixUIExtension.dll + WixUIExtension + + + $(WixExtDir)\WixVSExtension.dll + WixVSExtension + + + + + + + --> \ No newline at end of file diff --git a/Installer/SpecFlowInstaller/VS2010.wxs b/Installer/SpecFlowInstaller/VS2010.wxs index c53385cda..e1114caca 100644 --- a/Installer/SpecFlowInstaller/VS2010.wxs +++ b/Installer/SpecFlowInstaller/VS2010.wxs @@ -72,6 +72,16 @@ + + + + + + + + + +