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

session resolver and multiple data bases #39

Open
wants to merge 4 commits 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
9 changes: 0 additions & 9 deletions source/.nuget/NuGet.Config

This file was deleted.

136 changes: 0 additions & 136 deletions source/.nuget/NuGet.targets

This file was deleted.

4 changes: 0 additions & 4 deletions source/.nuget/packages.config

This file was deleted.

20 changes: 13 additions & 7 deletions source/NHibernate.AspNet.Identity.sln
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30110.0
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.AspNet.Identity", "NHibernate.AspNet.Identity\NHibernate.AspNet.Identity.csproj", "{C620FAAE-F1B6-479E-9959-C46C20ED0A8A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{B4B93010-9348-456C-9F18-1305854364F9}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.AspNet.Identity.Tests", "NHibernate.AspNet.Identity.Tests\NHibernate.AspNet.Identity.Tests.csproj", "{4AB55157-6F8F-423C-9C6F-A3A92B2101CE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample", "Sample", "{3FBC8B33-CB9E-48E4-8D3C-D17CFC61E71B}"
Expand All @@ -19,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.AspNet.Web", "NH
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.AspNet.Web.Specs", "NHibernate.AspNet.Web.Specs\NHibernate.AspNet.Web.Specs.csproj", "{12933FB3-BE28-4F4F-A43A-0BE836788065}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.SessionResolver", "NHibernate.SessionResolver\NHibernate.SessionResolver.csproj", "{63CD19ED-5019-493E-A4BB-1D19FED25C17}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -69,6 +65,16 @@ Global
{12933FB3-BE28-4F4F-A43A-0BE836788065}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{12933FB3-BE28-4F4F-A43A-0BE836788065}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{12933FB3-BE28-4F4F-A43A-0BE836788065}.Release|x86.ActiveCfg = Release|Any CPU
{63CD19ED-5019-493E-A4BB-1D19FED25C17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63CD19ED-5019-493E-A4BB-1D19FED25C17}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63CD19ED-5019-493E-A4BB-1D19FED25C17}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{63CD19ED-5019-493E-A4BB-1D19FED25C17}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{63CD19ED-5019-493E-A4BB-1D19FED25C17}.Debug|x86.ActiveCfg = Debug|Any CPU
{63CD19ED-5019-493E-A4BB-1D19FED25C17}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63CD19ED-5019-493E-A4BB-1D19FED25C17}.Release|Any CPU.Build.0 = Release|Any CPU
{63CD19ED-5019-493E-A4BB-1D19FED25C17}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{63CD19ED-5019-493E-A4BB-1D19FED25C17}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{63CD19ED-5019-493E-A4BB-1D19FED25C17}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
47 changes: 45 additions & 2 deletions source/NHibernate.AspNet.Web.Specs/AssemblyStartup.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using System;
using System.IO;
using NHibernate.AspNet.Identity.Helpers;
using NHibernate.AspNet.Web.Models;
using NUnit.Framework;
using SharpArch.NHibernate;
using SpecsFor.Mvc;
using NHibernate.Mapping.ByCode;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using NHibernate.Context;

namespace NHibernate.AspNet.Web.Specs
{
Expand Down Expand Up @@ -51,12 +56,50 @@ private void ConfigureDataBase()
AppDomain.CurrentDomain.SetData(
"DataDirectory", Path.Combine(root, @"SpecsForMvc.TestSite\App_Data"));

DataConfig.Configure(new SimpleSessionStorage());
var internalTypes = new[] {
typeof(ApplicationUser)
};

var mapping = MappingHelper.GetIdentityMappings(internalTypes);
System.Diagnostics.Debug.WriteLine(mapping.AsString());

var config = new Configuration().Configure();
config.AddDeserializedMapping(mapping, null);
BuildSchema(config);

var factory = config.BuildSessionFactory();
SessionResolver.RegisterFactoryToResolve(factory);
}

private static void BuildSchema(Configuration config)
{
var path = Path.Combine(AppDomain.CurrentDomain.GetData("DataDirectory").ToString(), @"schema.sql");

// this NHibernate tool takes a configuration (with mapping info in)
// and exports a database schema from it
new SchemaExport(config)
.SetOutputFile(path)
.Create(true, true /* DROP AND CREATE SCHEMA */);
}


[TearDown]
public void TearDownTestRun()
{
foreach (var factory in SessionResolver.Current.GetAllFactories())
{
if (CurrentSessionContext.HasBind(factory))
{
ISession session = CurrentSessionContext.Unbind(factory);

if (session.Transaction.IsActive)
session.Transaction.Rollback();

if (session != null && session.IsOpen)
session.Close();
}
}

_host.Shutdown();
}
}
Expand Down
7 changes: 3 additions & 4 deletions source/NHibernate.AspNet.Web.Specs/LoginSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using NHibernate.AspNet.Web.Controllers;
using NHibernate.AspNet.Web.Models;
using NUnit.Framework;
using SharpArch.NHibernate;
using Should;
using SpecsFor;
using SpecsFor.Mvc;
Expand Down Expand Up @@ -49,14 +48,14 @@ public class when_logging_in_with_valid_credentials : SpecsFor<MvcWebApp>
{
protected override void Given()
{
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(NHibernateSession.Current));
var session = SessionResolver.Current.GetCurrentSessionFor<ApplicationUser>();
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(session));
using (var transaction = new TransactionScope())
{
var user = new ApplicationUser() { UserName = "RealUserName" };
var result = userManager.CreateAsync(user, "RealPassword");
userManager.CreateAsync(user, "RealPassword").Wait();

transaction.Complete();
result.Exception.ShouldBeNull();
}

SUT.NavigateTo<AccountController>(c => c.Login("/Home/About"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\MilesiBastos.SharpArch.Domain.4.0.3000\lib\NET40\SharpArch.Domain.dll</HintPath>
</Reference>
<Reference Include="SharpArch.NHibernate, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\MilesiBastos.SharpArch.NHibernate.4.0.3000\lib\NET40\SharpArch.NHibernate.dll</HintPath>
</Reference>
<Reference Include="Should">
<HintPath>..\..\packages\Should.1.1.20\lib\Should.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -171,6 +167,10 @@
<Project>{64ab1955-b578-497e-ac28-2d0641be44a7}</Project>
<Name>NHibernate.AspNet.Web</Name>
</ProjectReference>
<ProjectReference Include="..\NHibernate.SessionResolver\NHibernate.SessionResolver.csproj">
<Project>{63cd19ed-5019-493e-a4bb-1d19fed25c17}</Project>
<Name>NHibernate.SessionResolver</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="..\..\packages\Selenium.WebDriver.ChromeDriver.2.14.0.0\content\chromedriver.exe">
Expand Down
3 changes: 3 additions & 0 deletions source/NHibernate.AspNet.Web.Specs/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<bytecode-provider type="null"/><!-- Important under Medium Trust -->
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider, NHibernate</property>
<property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
<property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
<property name="connection.connection_string_name">DefaultConnection</property>
<property name="connection.release_mode">on_close</property>
<property name="show_sql">true</property>
<property name="current_session_context_class">thread_static</property>
</session-factory>
</hibernate-configuration>
<connectionStrings>
Expand Down
1 change: 0 additions & 1 deletion source/NHibernate.AspNet.Web.Specs/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net451" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net451" />
<package id="MilesiBastos.SharpArch.Domain" version="4.0.3000" targetFramework="net451" />
<package id="MilesiBastos.SharpArch.NHibernate" version="4.0.3000" targetFramework="net451" />
<package id="Moq" version="4.2.1502.0911" targetFramework="net451" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net451" />
<package id="NHibernate" version="4.0.3.4000" targetFramework="net451" />
Expand Down
10 changes: 5 additions & 5 deletions source/NHibernate.AspNet.Web/App_Data/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
create table AspNetUserRoles (
UserId TEXT not null,
RoleId TEXT not null,
constraint FKFAADC1EF92E2FD93 foreign key (RoleId) references AspNetRoles,
constraint FKFAADC1EF526E4265 foreign key (UserId) references AspNetUsers
constraint FK86803B282B87AB2A foreign key (RoleId) references AspNetRoles,
constraint FK86803B28EA778823 foreign key (UserId) references AspNetUsers
)

create table AspNetUserLogins (
UserId TEXT not null,
LoginProvider TEXT,
ProviderKey TEXT,
constraint FK6B768E3C526E4265 foreign key (UserId) references AspNetUsers
constraint FKEF896DAEEA778823 foreign key (UserId) references AspNetUsers
)

create table AspNetRoles (
Expand All @@ -56,11 +56,11 @@
ClaimType TEXT,
ClaimValue TEXT,
UserId TEXT,
constraint FKE3450235526E4265 foreign key (UserId) references AspNetUsers
constraint FKF4F7D992EA778823 foreign key (UserId) references AspNetUsers
)

create table ApplicationUser (
applicationuser_key TEXT not null,
primary key (applicationuser_key),
constraint FKBF196D2F8745E746 foreign key (applicationuser_key) references AspNetUsers
constraint FK4376B148E75DF37 foreign key (applicationuser_key) references AspNetUsers
)
Loading