Mercurial > silverbladetech
changeset 6:c812bca7b1ac
"Restore packages on build" enabled by Nuget 1.6
General refactoring based on code analysis
author | stevenh7776 stevenhollidge@hotmail.com |
---|---|
date | Tue, 21 Feb 2012 01:00:34 +0700 |
parents | 877d70fb8176 |
children | cdc88fd7cb89 |
files | Stocks/.nuget/NuGet.exe Stocks/.nuget/NuGet.targets Stocks/Stocks.Common.Tests.Unit/Stocks.Common.Tests.Unit.csproj Stocks/Stocks.Common/Exceptions/InvalidWebPriceData.cs Stocks/Stocks.Common/IWebClientShim.cs Stocks/Stocks.Common/Stocks.Common.csproj Stocks/Stocks.Common/WebClientShim.cs Stocks/Stocks.Service.Tests.Functional/Stocks.Service.Tests.Functional.csproj Stocks/Stocks.Service.Tests.Unit/StockServiceTests.cs Stocks/Stocks.Service.Tests.Unit/Stocks.Service.Tests.Unit.csproj Stocks/Stocks.Service/AssemblyInit.cs Stocks/Stocks.Service/Stocks.Service.csproj Stocks/Stocks.Service/StocksService.cs Stocks/Stocks.sln |
diffstat | 14 files changed, 125 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Stocks/.nuget/NuGet.targets Tue Feb 21 01:00:34 2012 +0700 @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir> + <NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath> + <NuGetExePath>$(NuGetToolsPath)\nuget.exe</NuGetExePath> + <PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig> + <PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir> + <PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir> + + <!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config --> + <PackageSources>""</PackageSources> + + <!-- Enable the restore command to run before builds --> + <RestorePackages Condition="$(RestorePackages) == ''">false</RestorePackages> + + <!-- Property that enables building a package from a project --> + <BuildPackage Condition="$(BuildPackage) == ''">false</BuildPackage> + + <!-- Commands --> + <RestoreCommand>"$(NuGetExePath)" install "$(PackagesConfig)" -source $(PackageSources) -o "$(PackagesDir)"</RestoreCommand> + <BuildCommand>"$(NuGetExePath)" pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand> + + <!-- Make the build depend on restore packages --> + <BuildDependsOn Condition="$(RestorePackages) == 'true'"> + RestorePackages; + $(BuildDependsOn); + </BuildDependsOn> + + <!-- Make the build depend on restore packages --> + <BuildDependsOn Condition="$(BuildPackage) == 'true'"> + $(BuildDependsOn); + BuildPackage; + </BuildDependsOn> + </PropertyGroup> + + <Target Name="CheckPrerequisites"> + <!-- Raise an error if we're unable to locate nuget.exe --> + <Error Condition="!Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" /> + </Target> + + <Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites"> + <Exec Command="$(RestoreCommand)" + LogStandardErrorAsError="true" + Condition="Exists('$(PackagesConfig)')" /> + </Target> + + <Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites"> + <Exec Command="$(BuildCommand)" + LogStandardErrorAsError="true" /> + </Target> +</Project> \ No newline at end of file
--- a/Stocks/Stocks.Common.Tests.Unit/Stocks.Common.Tests.Unit.csproj Mon Feb 20 23:07:37 2012 +0700 +++ b/Stocks/Stocks.Common.Tests.Unit/Stocks.Common.Tests.Unit.csproj Tue Feb 21 01:00:34 2012 +0700 @@ -12,6 +12,8 @@ <AssemblyName>Stocks.Common.Tests.Unit</AssemblyName> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\Stocks\</SolutionDir> + <RestorePackages>true</RestorePackages> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -21,6 +23,8 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <CodeAnalysisIgnoreGeneratedCode>true</CodeAnalysisIgnoreGeneratedCode> + <RunCodeAnalysis>false</RunCodeAnalysis> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -60,6 +64,7 @@ </ItemGroup> <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">
--- a/Stocks/Stocks.Common/Exceptions/InvalidWebPriceData.cs Mon Feb 20 23:07:37 2012 +0700 +++ b/Stocks/Stocks.Common/Exceptions/InvalidWebPriceData.cs Tue Feb 21 01:00:34 2012 +0700 @@ -5,6 +5,7 @@ namespace Stocks.Common.Exceptions { + [Serializable] public class InvalidWebPriceDataException : Exception { public string WebPriceData { get; set; }
--- a/Stocks/Stocks.Common/IWebClientShim.cs Mon Feb 20 23:07:37 2012 +0700 +++ b/Stocks/Stocks.Common/IWebClientShim.cs Tue Feb 21 01:00:34 2012 +0700 @@ -1,6 +1,7 @@ -namespace Stocks.Common +using System; +namespace Stocks.Common { - public interface IWebClientShim + public interface IWebClientShim : IDisposable { string DownloadString(string address); }
--- a/Stocks/Stocks.Common/Stocks.Common.csproj Mon Feb 20 23:07:37 2012 +0700 +++ b/Stocks/Stocks.Common/Stocks.Common.csproj Tue Feb 21 01:00:34 2012 +0700 @@ -12,6 +12,8 @@ <AssemblyName>Stocks.Common</AssemblyName> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\Stocks\</SolutionDir> + <RestorePackages>true</RestorePackages> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -21,6 +23,8 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + <RunCodeAnalysis>false</RunCodeAnalysis> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -69,6 +73,7 @@ <None Include="packages.config" /> </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">
--- a/Stocks/Stocks.Common/WebClientShim.cs Mon Feb 20 23:07:37 2012 +0700 +++ b/Stocks/Stocks.Common/WebClientShim.cs Tue Feb 21 01:00:34 2012 +0700 @@ -1,23 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Net; +using System.Net; +using System; namespace Stocks.Common { + // Shim to wrap WebClient component to allow the shim to + // be mocked or stubbed for unit tests. + // Favours injection and composition over inheritence public class WebClientShim : IWebClientShim { - private readonly WebClient _webClient; + private WebClient _webClient; public WebClientShim(WebClient webClient) { _webClient = webClient; } - + + // add event handlers to the shim if you wish + // to hook into DownloadStringCompleted event public string DownloadString(string address) { return _webClient.DownloadString(address).ToString(); } + + public void Dispose() + { + _webClient.Dispose(); + } } -} +} \ No newline at end of file
--- a/Stocks/Stocks.Service.Tests.Functional/Stocks.Service.Tests.Functional.csproj Mon Feb 20 23:07:37 2012 +0700 +++ b/Stocks/Stocks.Service.Tests.Functional/Stocks.Service.Tests.Functional.csproj Tue Feb 21 01:00:34 2012 +0700 @@ -12,6 +12,8 @@ <AssemblyName>Stocks.Service.Tests.Functional</AssemblyName> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\Stocks\</SolutionDir> + <RestorePackages>true</RestorePackages> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -21,6 +23,7 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <RunCodeAnalysis>false</RunCodeAnalysis> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -55,6 +58,7 @@ <None Include="packages.config" /> </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">
--- a/Stocks/Stocks.Service.Tests.Unit/StockServiceTests.cs Mon Feb 20 23:07:37 2012 +0700 +++ b/Stocks/Stocks.Service.Tests.Unit/StockServiceTests.cs Tue Feb 21 01:00:34 2012 +0700 @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Net; +using System.Threading; +using System.Threading.Tasks; +using Stocks.Common; using Xunit; -using Stocks.Common; -using System.Threading.Tasks; -using System.Threading; -using System.Net; namespace Stocks.Service.Tests.Unit { @@ -17,26 +13,28 @@ { var file = "../../../Stocks.Service/companyData.json"; var configurationService = new ConfigurationService(file); - var webClientShim = new WebClientShim(new WebClient()); - - var service = new StocksService( - configurationService, - webClientShim); + using (var webClientShim = new WebClientShim(new WebClient())) + { + + var service = new StocksService( + configurationService, + webClientShim); + + Assert.Equal(false, service.IsActive); - Assert.Equal(false, service.IsActive); + using (var task = Task.Factory.StartNew(() => + { + service.Start(); + Assert.Equal(true, service.IsActive); - using (var task = Task.Factory.StartNew(() => + using (var task2 = Task.Factory.StartNew(() => Thread.Sleep(50))) + { task2.Wait(); } + service.Stop(); + Assert.Equal(false, service.IsActive); + })) { - service.Start(); - Assert.Equal(true, service.IsActive); - - using (var task2 = Task.Factory.StartNew(() => Thread.Sleep(50))) - { task2.Wait(); } - service.Stop(); - Assert.Equal(false, service.IsActive); - })) - { - task.Wait(); + task.Wait(); + } } } }
--- a/Stocks/Stocks.Service.Tests.Unit/Stocks.Service.Tests.Unit.csproj Mon Feb 20 23:07:37 2012 +0700 +++ b/Stocks/Stocks.Service.Tests.Unit/Stocks.Service.Tests.Unit.csproj Tue Feb 21 01:00:34 2012 +0700 @@ -12,6 +12,8 @@ <AssemblyName>Stocks.Service.Tests.Unit</AssemblyName> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\Stocks\</SolutionDir> + <RestorePackages>true</RestorePackages> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -21,6 +23,7 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <RunCodeAnalysis>false</RunCodeAnalysis> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -69,6 +72,7 @@ </ProjectReference> </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">
--- a/Stocks/Stocks.Service/AssemblyInit.cs Mon Feb 20 23:07:37 2012 +0700 +++ b/Stocks/Stocks.Service/AssemblyInit.cs Tue Feb 21 01:00:34 2012 +0700 @@ -9,7 +9,8 @@ { private static Logger logger = LogManager.GetCurrentClassLogger(); - public AssemblyInit () + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public AssemblyInit () { var fvi = FileVersionInfo.GetVersionInfo( Assembly.GetExecutingAssembly().Location);
--- a/Stocks/Stocks.Service/Stocks.Service.csproj Mon Feb 20 23:07:37 2012 +0700 +++ b/Stocks/Stocks.Service/Stocks.Service.csproj Tue Feb 21 01:00:34 2012 +0700 @@ -12,6 +12,8 @@ <AssemblyName>Stocks.Service</AssemblyName> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\Stocks\</SolutionDir> + <RestorePackages>true</RestorePackages> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -21,6 +23,7 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <RunCodeAnalysis>false</RunCodeAnalysis> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -71,6 +74,7 @@ </ProjectReference> </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">
--- a/Stocks/Stocks.Service/StocksService.cs Mon Feb 20 23:07:37 2012 +0700 +++ b/Stocks/Stocks.Service/StocksService.cs Tue Feb 21 01:00:34 2012 +0700 @@ -5,9 +5,9 @@ using System.Threading.Tasks; using NLog; using Stocks.Common; +using Stocks.Common.Core; using Stocks.Common.Events; using Stocks.Common.Models; -using Stocks.Common.Core; namespace Stocks.Service {
--- a/Stocks/Stocks.sln Mon Feb 20 23:07:37 2012 +0700 +++ b/Stocks/Stocks.sln Tue Feb 21 01:00:34 2012 +0700 @@ -13,6 +13,12 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stocks.Common.Tests.Unit", "Stocks.Common.Tests.Unit\Stocks.Common.Tests.Unit.csproj", "{71073218-673B-4E62-AC2B-0D6ECA775465}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{A0546281-ED09-4385-8FAB-8A819597F976}" + ProjectSection(SolutionItems) = preProject + .nuget\NuGet.exe = .nuget\NuGet.exe + .nuget\NuGet.targets = .nuget\NuGet.targets + EndProjectSection +EndProject Global GlobalSection(TestCaseManagementSettings) = postSolution CategoryFile = Stocks1.vsmdi