Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 50 tests for controllers #884

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions Bonobo.Git.Server.Test/Bonobo.Git.Server.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</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>
<HintPath>..\packages\Castle.Core.4.4.1\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>
Expand All @@ -69,6 +69,7 @@
<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="Microsoft.CSharp" />
<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 @@ -170,13 +171,20 @@
<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="Unit\PasswordServiceTest.cs" />
<Compile Include="Unit\GitAuthorizeAttributeTest.cs" />
<Compile Include="Unit\ControllerDependendencyBuilders.cs" />
<Compile Include="Unit\UserConfigurationTests.cs" />
<Compile Include="Unit\UserExtensionsTests.cs" />
<Compile Include="Unit\UserModelTest.cs" />
<Compile Include="Unit\ControllerTests.cs" />
<Compile Include="Unit\ControllerTests.AccountControllerTests.cs" />
<Compile Include="Unit\ControllerTests.HomeControllerTests.cs" />
<Compile Include="Unit\ControllerTests.SettingsControllerTests.cs" />
<Compile Include="Unit\ControllerTests.TeamControllerTests.cs" />
<Compile Include="Unit\ControllerTests.RepositoryControllerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestCategories.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bonobo.Git.Server\Bonobo.Git.Server.csproj">
Expand Down
73 changes: 73 additions & 0 deletions Bonobo.Git.Server.Test/Unit/ControllerDependendencyBuilders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Bonobo.Git.Server.Data;
using Bonobo.Git.Server.Models;
using Bonobo.Git.Server.Security;
using Moq;
using System;
using System.Collections.Generic;

namespace Bonobo.Git.Server.Test.Unit
{
public static class ControllerDependendencyBuilders
{
// TeamRepository Mock
public static Mock<ITeamRepository> SetupToSucceedWhenCreatingATeam(this Mock<ITeamRepository> teamRepositoryMock)
{
teamRepositoryMock.Setup(r => r.Create(It.IsAny<TeamModel>()))
.Returns(true);
return teamRepositoryMock;
}

public static Mock<ITeamRepository> SetupToReturnASpecificTeamWhenCallingGetTeamMethod(this Mock<ITeamRepository> teamRepositoryMock, Guid requestedGuid)
{
teamRepositoryMock.Setup(t => t.GetTeam(requestedGuid))
.Returns(new TeamModel
{
Id = requestedGuid,
Members = new UserModel[0]
});
return teamRepositoryMock;
}

// MembershipService Mock
public static Mock<IMembershipService> SetupToReturnAnEmptyUserModelListWhenCallingGetAllUsers(this Mock<IMembershipService> membershipServiceMock)
{
membershipServiceMock.Setup(m => m.GetAllUsers())
.Returns(new List<UserModel>());
return membershipServiceMock;
}

public static Mock<IMembershipService> SetupToReturnARequestedUserModel(this Mock<IMembershipService> membershipServiceMock, string requestedUserName)
{
membershipServiceMock.Setup(m => m.GetUserModel(requestedUserName))
.Returns(new UserModel { Username = requestedUserName });
return membershipServiceMock;
}

public static Mock<IMembershipService> SetupToGenerateResetToken(this Mock<IMembershipService> membershipServiceMock, string token, string requestedUserName)
{
membershipServiceMock.Setup(m => m.GenerateResetToken(requestedUserName))
.Returns(token);
return membershipServiceMock;
}

// IRepositoryRepository Mock
public static Mock<IRepositoryRepository> SetupToReturnAnEmptyListForASpecificIdWhenCallingGetTeamRepositories(this Mock<IRepositoryRepository> repositoryRepositoryMock, Guid requestedId)
{
repositoryRepositoryMock.Setup(r => r.GetTeamRepositories(new[] { requestedId }))
.Returns(new List<RepositoryModel>());
return repositoryRepositoryMock;
}

public static Mock<IRepositoryRepository> SetupToReturnAModelWithASpecificIdWhenCallingGetRepositoryMethod(this Mock<IRepositoryRepository> repositoryRepositoryMock, Guid guid)
{
repositoryRepositoryMock.Setup(s => s.GetRepository(guid))
.Returns(new RepositoryModel
{
Id = guid,
Administrators = new UserModel[0],
Name = "name"
});
return repositoryRepositoryMock;
}
}
}