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

Port to .net core #836

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ publish/
*.azurePubxml
*.pubxml
*.pubxml.user
!Release.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
Expand Down
244 changes: 31 additions & 213 deletions Bonobo.Git.Server.Test/Bonobo.Git.Server.Test.csproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System.IO;
using System.Linq;
using Bonobo.Git.Server.Data;
using Microsoft.AspNetCore.Hosting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;

namespace Bonobo.Git.Server.Test.MembershipTests.ADTests
{
Expand Down Expand Up @@ -42,7 +44,8 @@ private void SafelyDeleteTestData()

private static ADBackendStore<StorableClass> MakeStore()
{
return new ADBackendStore<StorableClass>(Path.GetTempPath(), "BonoboTestStore");
var hostingEnvironment = Substitute.For<IHostingEnvironment>();
return new ADBackendStore<StorableClass>(hostingEnvironment, Path.GetTempPath(), "BonoboTestStore");
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ private void InitialiseTestObjects()
_users = new ADMembershipServiceTestFacade(new ADMembershipService(), _testSupport);
_repos = new ADRepositoryRepository();

_service = new RepositoryPermissionService
{
Repository = _repos, RoleProvider = _roles, TeamRepository = _teams
};
_service = new RepositoryPermissionService(_repos, _roles, _teams);
}

protected override TeamModel CreateTeam()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Bonobo.Git.Server.Data.Update;
using Bonobo.Git.Server.Security;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;

namespace Bonobo.Git.Server.Test.MembershipTests.EFTests
{
Expand All @@ -19,7 +20,7 @@ public abstract class EFMembershipServiceTest : MembershipServiceTestBase
public void UpdatesCanBeRunOnAlreadyUpdatedDatabase()
{
// Run all the updates again - this should be completely harmless
new AutomaticUpdater().RunWithContext(GetContext());
new AutomaticUpdater().RunWithContext(GetContext(), Substitute.For<IAuthenticationProvider>());
}

[TestMethod]
Expand Down Expand Up @@ -123,8 +124,8 @@ private BonoboGitServerContext GetContext()

protected void InitialiseTestObjects()
{
_service = new EFMembershipService {CreateContext = GetContext};
new AutomaticUpdater().RunWithContext(GetContext());
_service = new EFMembershipService(GetContext);
new AutomaticUpdater().RunWithContext(GetContext(), Substitute.For<IAuthenticationProvider>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Bonobo.Git.Server.Models;
using Bonobo.Git.Server.Security;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;

namespace Bonobo.Git.Server.Test.MembershipTests.EFTests
{
Expand Down Expand Up @@ -44,19 +45,14 @@ public abstract class EFPermissionServiceTest : PermissionServiceTestBase

protected void InitialiseTestObjects()
{
_teams = new EFTeamRepository { CreateContext = () => _connection.GetContext() };
_users = new EFMembershipService { CreateContext = () => _connection.GetContext() };
_repos = new EFRepositoryRepository { CreateContext = () => _connection.GetContext() };
_roles = new EFRoleProvider { CreateContext = () => _connection.GetContext() };
_teams = new EFTeamRepository(() => _connection.GetContext());
_users = new EFMembershipService(() => _connection.GetContext());
_repos = new EFRepositoryRepository(() => _connection.GetContext());
_roles = new EFRoleProvider(() => _connection.GetContext() );

_service = new RepositoryPermissionService
{
Repository = _repos,
TeamRepository = _teams,
RoleProvider = _roles
};
_service = new RepositoryPermissionService(_repos, _roles, _teams);

new AutomaticUpdater().RunWithContext(_connection.GetContext());
new AutomaticUpdater().RunWithContext(_connection.GetContext(), Substitute.For<IAuthenticationProvider>());
}

protected override TeamModel CreateTeam()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Bonobo.Git.Server.Models;
using Bonobo.Git.Server.Security;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;

namespace Bonobo.Git.Server.Test.MembershipTests.EFTests
{
Expand Down Expand Up @@ -44,14 +45,14 @@ public abstract class EFRepositoryRepositoryTest : RepositoryRepositoryTestBase

protected override UserModel AddUserFred()
{
IMembershipService memberService = new EFMembershipService { CreateContext = GetContext };
IMembershipService memberService = new EFMembershipService(GetContext);
memberService.CreateUser("fred", "letmein", "Fred", "Blogs", "fred@aol");
return memberService.GetUserModel("fred");
}

protected override TeamModel AddTeam()
{
EFTeamRepository teams = new EFTeamRepository { CreateContext = GetContext };
EFTeamRepository teams = new EFTeamRepository(GetContext);
var newTeam = new TeamModel { Name="Team1" };
teams.Create(newTeam);
return newTeam;
Expand All @@ -64,8 +65,8 @@ BonoboGitServerContext GetContext()

protected void InitialiseTestObjects()
{
_repo = new EFRepositoryRepository {CreateContext = () => _connection.GetContext()};
new AutomaticUpdater().RunWithContext(_connection.GetContext());
_repo = new EFRepositoryRepository(() => _connection.GetContext());
new AutomaticUpdater().RunWithContext(_connection.GetContext(), Substitute.For<IAuthenticationProvider>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Bonobo.Git.Server.Data.Update;
using Bonobo.Git.Server.Security;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;

namespace Bonobo.Git.Server.Test.MembershipTests.EFTests
{
Expand Down Expand Up @@ -48,7 +49,7 @@ public abstract class EFRoleProviderTest
public void UpdatesCanBeRunOnAlreadyUpdatedDatabase()
{
// Run all the updates again - this should be completely harmless
new AutomaticUpdater().RunWithContext(GetContext());
new AutomaticUpdater().RunWithContext(GetContext(), Substitute.For<IAuthenticationProvider>());
}

[TestMethod]
Expand Down Expand Up @@ -148,14 +149,14 @@ public void TestRoleCanBeDeletedWhilePopulatedIfAllowed()

Guid AddUserFred()
{
EFMembershipService memberService = new EFMembershipService { CreateContext = GetContext };
EFMembershipService memberService = new EFMembershipService(GetContext);
memberService.CreateUser("fred", "letmein", "Fred", "FredBlogs", "fred@aol");
return memberService.GetUserModel("fred").Id;
}

Guid GetAdminId()
{
EFMembershipService memberService = new EFMembershipService { CreateContext = GetContext };
EFMembershipService memberService = new EFMembershipService(GetContext);
return memberService.GetUserModel("Admin").Id;
}

Expand All @@ -166,8 +167,8 @@ private BonoboGitServerContext GetContext()

protected void InitialiseTestObjects()
{
_provider = new EFRoleProvider {CreateContext = () => _connection.GetContext()};
new AutomaticUpdater().RunWithContext(_connection.GetContext());
_provider = new EFRoleProvider(() => _connection.GetContext());
new AutomaticUpdater().RunWithContext(_connection.GetContext(), Substitute.For<IAuthenticationProvider>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Bonobo.Git.Server.Models;
using Bonobo.Git.Server.Security;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;

namespace Bonobo.Git.Server.Test.MembershipTests.EFTests
{
Expand Down Expand Up @@ -49,9 +50,9 @@ public abstract class EFTeamRepositoryTests : TeamRepositoryTestsBase

protected void InitialiseTestObjects()
{
_repo = new EFTeamRepository {CreateContext = () => _connection.GetContext()};
_membershipService = new EFMembershipService { CreateContext = () => _connection.GetContext() };
new AutomaticUpdater().RunWithContext(_connection.GetContext());
_repo = new EFTeamRepository(() => _connection.GetContext());
_membershipService = new EFMembershipService(() => _connection.GetContext());
new AutomaticUpdater().RunWithContext(_connection.GetContext(), Substitute.For<IAuthenticationProvider>());
}

protected override bool CreateTeam(TeamModel team)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
using System.Data.SqlClient;
using System.IO;
using Bonobo.Git.Server.Data;
using Microsoft.EntityFrameworkCore;

namespace Bonobo.Git.Server.Test.MembershipTests.EFTests
{
class SqlServerTestConnection : IDatabaseTestConnection
{
readonly SqlConnection _connection;
readonly DbContextOptionsBuilder<BonoboGitServerContext> _optionsBuilder;
private readonly string _databaseName;
private static readonly string _instanceName;

Expand Down Expand Up @@ -52,13 +53,15 @@ public SqlServerTestConnection()

Console.WriteLine("Created test database: " + fileName);

_connection = new SqlConnection(String.Format(@"Data Source=(LocalDB)\{0};Integrated Security=True;AttachDbFilename={1};Initial Catalog={2}", _instanceName, fileName, _databaseName));
_connection.Open();
_optionsBuilder = new DbContextOptionsBuilder<BonoboGitServerContext>();
_optionsBuilder.UseSqlServer(string.Format(
@"Data Source=(LocalDB)\{0};Integrated Security=True;AttachDbFilename={1};Initial Catalog={2}",
_instanceName, fileName, _databaseName));
}

public BonoboGitServerContext GetContext()
{
return BonoboGitServerContext.FromDatabase(_connection);
return new BonoboGitServerContext(_optionsBuilder.Options);
}

void CreateDB(string fileName)
Expand Down Expand Up @@ -96,7 +99,6 @@ private void Exec(SqlConnection connection, string commandText)

public void Dispose()
{
_connection.Dispose();
SqlConnection.ClearAllPools();
TryToDeleteDatabaseFiles();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Data.Common;
using Bonobo.Git.Server.Data;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;

namespace Bonobo.Git.Server.Test.MembershipTests.EFTests
{
Expand All @@ -11,18 +13,20 @@ public interface IDatabaseTestConnection : IDisposable

class SqliteTestConnection : IDatabaseTestConnection
{
readonly DbConnection _connection;
private readonly DbConnection _connection;

public SqliteTestConnection()
{
_connection = DbProviderFactories.GetFactory("System.Data.SQLite").CreateConnection();
_connection.ConnectionString = "Data Source =:memory:;BinaryGUID=False";
_connection = SqliteFactory.Instance.CreateConnection();
_connection.ConnectionString = "Data Source =:memory:";
_connection.Open();
}

public BonoboGitServerContext GetContext()
{
return BonoboGitServerContext.FromDatabase(_connection);
var optionsBuilder = new DbContextOptionsBuilder<BonoboGitServerContext>();
optionsBuilder.UseSqlite(_connection);
return new BonoboGitServerContext(optionsBuilder.Options);
}

public void Dispose()
Expand Down
36 changes: 0 additions & 36 deletions Bonobo.Git.Server.Test/Properties/AssemblyInfo.cs

This file was deleted.

8 changes: 1 addition & 7 deletions Bonobo.Git.Server.Test/TestCategories.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bonobo.Git.Server.Test
{
public static class TestCategories
Expand All @@ -19,4 +13,4 @@ public static class TestCategories
public const string AuthWindows = "AuthWindowsAuth";
public const string AuthADFS = "AuthADFS";
}
}
}
5 changes: 2 additions & 3 deletions Bonobo.Git.Server.Test/UnitTests/CustomHtmlHelperTest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using Bonobo.Git.Server.Data;
using Bonobo.Git.Server.Helpers;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Bonobo.Git.Server.Test.UnitTests
{
[TestClass]
public class CustomHtmlHelperTest
{
readonly HtmlHelper Html = new HtmlHelper(new ViewContext(), new ViewPage());
private readonly IHtmlHelper Html;

[TestMethod]
public void EnumsWithDisplayAttributesAreFormatted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Bonobo.Git.Server.Test.MembershipTests.EFTests;
using Bonobo.Git.Server.Data.Update;
using Bonobo.Git.Server.Data;
using Microsoft.EntityFrameworkCore;

namespace Bonobo.Git.Server.Test.UnitTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using Bonobo.Git.Server.Test.MembershipTests.EFTests;
using Bonobo.Git.Server.Data.Update;
using Bonobo.Git.Server.Data;
using Bonobo.Git.Server.Security;
using Microsoft.EntityFrameworkCore;
using NSubstitute;

namespace Bonobo.Git.Server.Test.UnitTests
{
Expand Down Expand Up @@ -91,7 +94,7 @@ Foreign Key ([Team_Name]) References [Team]([Name])
);

");
new AutomaticUpdater().RunWithContext(_connection.GetContext());
new AutomaticUpdater().RunWithContext(_connection.GetContext(), Substitute.For<IAuthenticationProvider>());
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions Bonobo.Git.Server.Test/UnitTests/GitAuthorizeAttributeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class GitAuthorizeAttributeTest
[TestMethod]
public void GetRepoPathTest()
{
var repo = GitAuthorizeAttribute.GetRepoPath("/other/test.git/info/refs", "/other");
var repo = GitAuthorizationHandler.GetRepoPath("/other/test.git/info/refs", "/other");
Assert.AreEqual("test", repo);
repo = GitAuthorizeAttribute.GetRepoPath("/test.git/info/refs", "/");
repo = GitAuthorizationHandler.GetRepoPath("/test.git/info/refs", "/");
Assert.AreEqual("test", repo);
}
}
Expand Down
Loading