Skip to content

Commit

Permalink
Infrastructure Update to improve Testability (#881)
Browse files Browse the repository at this point in the history
* Update Unity to 5.11.7

(cherry picked from commit 1fa54fa)

* move all Unit tests to the Unit namespace

(cherry picked from commit ea50767)

* refactor ConfigurationEntry for testability

(cherry picked from commit 4d24d32)

* Migration to MSTest V2

(cherry picked from commit 4e2c696)

* Consolidate Nuget packages
  • Loading branch information
eugeniomiro authored Mar 5, 2021
1 parent 498a8b7 commit 6277ecf
Show file tree
Hide file tree
Showing 46 changed files with 447 additions and 375 deletions.
67 changes: 39 additions & 28 deletions Bonobo.Git.Server.Test/Bonobo.Git.Server.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -48,6 +49,9 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
Expand All @@ -56,6 +60,15 @@
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.15.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.15.2\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -90,30 +103,30 @@
<Private>True</Private>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll</HintPath>
<Private>True</Private>
<Reference Include="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
<Reference Include="WebDriver, Version=3.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.3.3.0\lib\net40\WebDriver.dll</HintPath>
Expand All @@ -130,13 +143,7 @@
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework">
<Private>False</Private>
</Reference>
</ItemGroup>
</Otherwise>
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="MembershipTests\ADTests\ADBackendStoreTest.cs" />
Expand All @@ -159,16 +166,17 @@
<Compile Include="MembershipTests\MembershipServiceTestBase.cs" />
<Compile Include="MembershipTests\EFTests\SqliteTestConnection.cs" />
<Compile Include="MembershipTests\EFTests\SqlServerTestConnection.cs" />
<Compile Include="UnitTests\CustomHtmlHelperTest.cs" />
<Compile Include="UnitTests\DatabaseUpdateTestsSqlite.cs" />
<Compile Include="UnitTests\DatabaseUpdateTestsSqlServer.cs" />
<Compile Include="UnitTests\PathEncoderTest.cs" />
<Compile Include="Unit\CustomHtmlHelperTest.cs" />
<Compile Include="Unit\DatabaseUpdateTestsSqlite.cs" />
<Compile Include="Unit\DatabaseUpdateTestsSqlServer.cs" />
<Compile Include="Unit\PathEncoderTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestCategories.cs" />
<Compile Include="UnitTests\PasswordServiceTest.cs" />
<Compile Include="UnitTests\GitAuthorizeAttributeTest.cs" />
<Compile Include="UnitTests\UserExtensionsTests.cs" />
<Compile Include="UnitTests\UserModelTest.cs" />
<Compile Include="Unit\PasswordServiceTest.cs" />
<Compile Include="Unit\GitAuthorizeAttributeTest.cs" />
<Compile Include="Unit\UserConfigurationTests.cs" />
<Compile Include="Unit\UserExtensionsTests.cs" />
<Compile Include="Unit\UserModelTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bonobo.Git.Server\Bonobo.Git.Server.csproj">
Expand Down Expand Up @@ -208,6 +216,8 @@
<Error Condition="!Exists('..\packages\Selenium.WebDriver.IEDriver.3.3.0\build\Selenium.WebDriver.IEDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.IEDriver.3.3.0\build\Selenium.WebDriver.IEDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.29.0\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.29.0\build\Selenium.WebDriver.ChromeDriver.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<!-- 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. -->
Expand All @@ -217,6 +227,7 @@
<Import Project="..\packages\System.Data.SQLite.Core.1.0.104.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.104.0\build\net46\System.Data.SQLite.Core.targets')" />
<Import Project="..\packages\Selenium.WebDriver.IEDriver.3.3.0\build\Selenium.WebDriver.IEDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.IEDriver.3.3.0\build\Selenium.WebDriver.IEDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.29.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.29.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
<Import Project="..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets')" />
<!-- <Target Name="AfterBuild">
</Target>
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Bonobo.Git.Server.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Bonobo.Git.Server.Test.UnitTests
namespace Bonobo.Git.Server.Test.Unit
{
[TestClass]
public class CustomHtmlHelperTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Bonobo.Git.Server.Data.Update;
using Bonobo.Git.Server.Data;

namespace Bonobo.Git.Server.Test.UnitTests
namespace Bonobo.Git.Server.Test.Unit
{
[TestClass]
public class DatabaseUpdateTestsSqlServer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Bonobo.Git.Server.Data.Update;
using Bonobo.Git.Server.Data;

namespace Bonobo.Git.Server.Test.UnitTests
namespace Bonobo.Git.Server.Test.Unit
{
[TestClass]
public class DatabaseUpdateTestsSqlite
Expand Down
20 changes: 20 additions & 0 deletions Bonobo.Git.Server.Test/Unit/UserConfigurationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Bonobo.Git.Server.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace Bonobo.Git.Server.Test.Unit
{
[TestClass]
public class UserConfigurationTests
{
[TestMethod]
public void UserConfiguration_Current_Can_Be_Used_After_Preparing_PathResolver()
{
Mock<IPathResolver> pathResolverMock = new Mock<IPathResolver>();
pathResolverMock.Setup(pr => pr.ResolveWithConfiguration(It.IsAny<string>()))
.Returns("BonoboTestConfig.config");
UserConfiguration.PathResolver = pathResolverMock.Object;
Assert.IsNotNull(UserConfiguration.Current);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.Linq;

namespace Bonobo.Git.Server.Test.UnitTests
namespace Bonobo.Git.Server.Test.Unit
{
[TestClass]
public class UserExtensionsTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Bonobo.Git.Server.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Bonobo.Git.Server.Test.UnitTests
namespace Bonobo.Git.Server.Test.Unit
{
[TestClass]
public sealed class UserModelTest
Expand Down
14 changes: 13 additions & 1 deletion Bonobo.Git.Server.Test/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
Expand All @@ -54,6 +54,18 @@
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Unity.Abstractions" publicKeyToken="489b6accfaf20ef0" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.11.6.0" newVersion="5.11.6.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
Expand Down
12 changes: 9 additions & 3 deletions Bonobo.Git.Server.Test/packages.config
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="4.4.0" targetFramework="net46" />
<package id="EntityFramework" version="6.1.3" targetFramework="net451" />
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net46" />
<package id="Microsoft.AspNet.Mvc.Futures" version="5.0.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net46" />
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net46" />
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net46" developmentDependency="true" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net451" />
<package id="Moq" version="4.15.2" targetFramework="net46" />
<package id="MSTest.TestAdapter" version="2.1.2" targetFramework="net46" />
<package id="MSTest.TestFramework" version="2.1.2" targetFramework="net46" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" />
<package id="Selenium.Support" version="3.3.0" targetFramework="net46" />
<package id="Selenium.WebDriver" version="3.3.0" targetFramework="net46" />
Expand All @@ -17,4 +21,6 @@
<package id="System.Data.SQLite.Core" version="1.0.104.0" targetFramework="net46" />
<package id="System.Data.SQLite.EF6" version="1.0.104.0" targetFramework="net46" />
<package id="System.Data.SQLite.Linq" version="1.0.104.0" targetFramework="net46" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net46" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net46" />
</packages>
47 changes: 47 additions & 0 deletions Bonobo.Git.Server/App_Start/UnityConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;

using Unity;

namespace Bonobo.Git.Server
{
/// <summary>
/// Specifies the Unity configuration for the main container.
/// </summary>
public static class UnityConfig
{
#region Unity Container
private static Lazy<IUnityContainer> container =
new Lazy<IUnityContainer>(() =>
{
var container = new UnityContainer();
RegisterTypes(container);
return container;
});

/// <summary>
/// Configured Unity Container.
/// </summary>
public static IUnityContainer Container => container.Value;
#endregion

/// <summary>
/// Registers the type mappings with the Unity container.
/// </summary>
/// <param name="container">The unity container to configure.</param>
/// <remarks>
/// There is no need to register concrete types such as controllers or
/// API controllers (unless you want to change the defaults), as Unity
/// allows resolving a concrete type even if it was not previously
/// registered.
/// </remarks>
public static void RegisterTypes(IUnityContainer container)
{
// NOTE: To load from web.config uncomment the line below.
// Make sure to add a Unity.Configuration to the using statements.
// container.LoadConfiguration();

// TODO: Register your type's mappings here.
// container.RegisterType<IProductRepository, ProductRepository>();
}
}
}
38 changes: 38 additions & 0 deletions Bonobo.Git.Server/App_Start/UnityMvcActivator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Linq;
using System.Web.Mvc;

using Unity.AspNet.Mvc;

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(Bonobo.Git.Server.UnityMvcActivator), nameof(Bonobo.Git.Server.UnityMvcActivator.Start))]
[assembly: WebActivatorEx.ApplicationShutdownMethod(typeof(Bonobo.Git.Server.UnityMvcActivator), nameof(Bonobo.Git.Server.UnityMvcActivator.Shutdown))]

namespace Bonobo.Git.Server
{
/// <summary>
/// Provides the bootstrapping for integrating Unity with ASP.NET MVC.
/// </summary>
public static class UnityMvcActivator
{
/// <summary>
/// Integrates Unity when the application starts.
/// </summary>
public static void Start()
{
FilterProviders.Providers.Remove(FilterProviders.Providers.OfType<FilterAttributeFilterProvider>().First());
FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(UnityConfig.Container));

DependencyResolver.SetResolver(new UnityDependencyResolver(UnityConfig.Container));

// TODO: Uncomment if you want to use PerRequestLifetimeManager
// Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));
}

/// <summary>
/// Disposes the Unity container when the application is shut down.
/// </summary>
public static void Shutdown()
{
UnityConfig.Container.Dispose();
}
}
}
2 changes: 1 addition & 1 deletion Bonobo.Git.Server/Attributes/AllViewsAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Bonobo.Git.Server.App_GlobalResources;
using Bonobo.Git.Server.Models;
using Bonobo.Git.Server.Security;
using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Unity;

namespace Bonobo.Git.Server.Attributes
{
Expand Down
Loading

0 comments on commit 6277ecf

Please sign in to comment.