Skip to content
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
2 changes: 1 addition & 1 deletion Tools/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<package id="NUnit.Extension.NUnitV2ResultWriter" version="3.6.0" targetFramework="net461" />
<package id="NUnit.Extension.TeamCityEventListener" version="1.0.2" targetFramework="net461" />
<package id="NUnit.Extension.VSProjectLoader" version="3.6.0" targetFramework="net461" />
<package id="CSharpAsyncGenerator.CommandLine" version="0.8.2.9" targetFramework="net461" />
<package id="CSharpAsyncGenerator.CommandLine" version="0.8.2.10" targetFramework="net461" />
<package id="vswhere" version="2.1.4" targetFramework="net461" />
<package id="gitreleasemanager" version="0.7.0" targetFramework="net461" />
</packages>
45 changes: 0 additions & 45 deletions src/NHibernate.Test/Async/SessionBuilder/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,51 +189,6 @@ private void CanSetFlushMode<T>(T sb) where T : ISessionBuilder<T>
FlushMode.Always, FlushMode.Auto, FlushMode.Commit, FlushMode.Manual);
}

[Test]
public async Task CanSetInterceptorAsync()
{
var sb = Sfi.WithOptions();
await (CanSetInterceptorAsync(sb));
using (var s = sb.OpenSession())
{
await (CanSetInterceptorAsync(s.SessionWithOptions()));
}
}

private Task CanSetInterceptorAsync<T>(T sb) where T : ISessionBuilder<T>
{
try
{
var sbType = sb.GetType().Name;
// Do not use .Instance here, we want another instance.
var interceptor = new EmptyInterceptor();
var options = DebugSessionFactory.GetCreationOptions(sb);

Assert.AreEqual(Sfi.Interceptor, options.SessionInterceptor, $"{sbType}: Initial value");
var fsb = sb.Interceptor(interceptor);
Assert.AreEqual(interceptor, options.SessionInterceptor, $"{sbType}: After call with an interceptor");
Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after call with an interceptor");

if (sb is ISharedSessionBuilder ssb)
{
var fssb = ssb.Interceptor();
Assert.AreEqual(EmptyInterceptor.Instance, options.SessionInterceptor, $"{sbType}: After call with shared interceptor");
Assert.AreEqual(sb, fssb, $"{sbType}: Unexpected fluent return on shared");
}

Assert.Throws<ArgumentNullException>(() => sb.Interceptor(null), $"{sbType}: After call with null");

fsb = sb.NoInterceptor();
Assert.AreEqual(EmptyInterceptor.Instance, options.SessionInterceptor, $"{sbType}: After no call");
Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after no call");
return Task.CompletedTask;
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}

private void CanSet<T, V>(T sb, Func<V, T> setter, Func<V> getter, Func<ISharedSessionBuilder> shared, V initialValue,
params V[] values) where T : ISessionBuilder<T>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace NHibernate.Test.Bytecode
{
[TestFixture]
[TestFixture, Obsolete]
public class ActivatorObjectFactoryFixture
{
public class WithOutPublicParameterLessCtor
Expand Down
41 changes: 41 additions & 0 deletions src/NHibernate.Test/Bytecode/ActivatorServiceProviderFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using NHibernate.Bytecode;
using NUnit.Framework;

namespace NHibernate.Test.Bytecode
{
[TestFixture]
public class ActivatorServiceProviderFixture
{
public class WithOutPublicParameterLessCtor
{
public string Something { get; set; }
protected WithOutPublicParameterLessCtor() { }

public WithOutPublicParameterLessCtor(string something)
{
Something = something;
}
}

public class PublicParameterLessCtor
{
}

protected virtual IServiceProvider GetServiceProvider()
{
return new ActivatorServiceProvider();
}

[Test]
public void CreateInstanceDefCtor()
{
var sp = GetServiceProvider();
Assert.Throws<ArgumentNullException>(() => sp.GetService(null));
Assert.Throws<MissingMethodException>(() => sp.GetService(typeof(WithOutPublicParameterLessCtor)));
var instance = sp.GetService(typeof(PublicParameterLessCtor));
Assert.That(instance, Is.Not.Null);
Assert.That(instance, Is.InstanceOf<PublicParameterLessCtor>());
}
}
}
8 changes: 4 additions & 4 deletions src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ public void IgnoreSystemOutOfAppConfig()
}

[Test]
public void ObjectsFactory()
public void ServiceProvider()
{
Assume.That(TestsContext.ExecutingWithVsTest, Is.False);

var xml =
@"<?xml version='1.0' encoding='utf-8' ?>
<hibernate-configuration xmlns='urn:nhibernate-configuration-2.2'>
<objects-factory type='test'/>
<service-provider type='test'/>
<session-factory>
</session-factory>
</hibernate-configuration>";
Expand All @@ -89,11 +89,11 @@ public void ObjectsFactory()
using (var xtr = new XmlTextReader(xml, XmlNodeType.Document, null))
{
hc = new HibernateConfiguration(xtr);
Assert.That(hc.ObjectsFactoryType, Is.Null);
Assert.That(hc.ServiceProviderType, Is.Null);
}

hc = HibernateConfiguration.FromAppConfig(xml);
Assert.That(hc.ObjectsFactoryType, Is.EqualTo("test"));
Assert.That(hc.ServiceProviderType, Is.EqualTo("test"));
}

[Test]
Expand Down
66 changes: 0 additions & 66 deletions src/NHibernate.Test/CfgTest/CustomObjectsFactoryTest.cs

This file was deleted.

56 changes: 56 additions & 0 deletions src/NHibernate.Test/CfgTest/CustomServiceProviderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using NHibernate.Bytecode;
using NUnit.Framework;
using Environment = NHibernate.Cfg.Environment;

namespace NHibernate.Test.CfgTest
{
[TestFixture]
public class CustomServiceProviderTest
{
private class MyServiceProvider : IServiceProvider
{
public object GetService(System.Type serviceType)
{
throw new NotImplementedException();
}
}
private class InvalidServiceProvider
{
}
private class InvalidNoCtorServiceProvider : MyServiceProvider
{
public InvalidNoCtorServiceProvider(string pizza) {}
}

[Test]
public void WhenNoShortCutUsedThenCanBuildServiceProvider()
{
var properties = new Dictionary<string, string> { { Environment.PropertyBytecodeProvider, typeof(MyServiceProvider).AssemblyQualifiedName } };
Assert.That(() => Environment.BuildServiceProvider(properties), Throws.Nothing);
}

[Test]
public void WhenNoShortCutUsedThenCanBuildInstanceOfConfiguredServiceProvider()
{
var properties = new Dictionary<string, string> { { Environment.PropertyServiceProvider, typeof(MyServiceProvider).AssemblyQualifiedName } };
Assert.That(Environment.BuildServiceProvider(properties), Is.InstanceOf<MyServiceProvider>());
}

[Test]
public void WhenInvalidThenThrow()
{
var properties = new Dictionary<string, string> { { Environment.PropertyServiceProvider, typeof(InvalidServiceProvider).AssemblyQualifiedName } };
Assert.That(() => Environment.BuildServiceProvider(properties), Throws.TypeOf<HibernateServiceProviderException>());
}

[Test]
public void WhenNoDefaultCtorThenThrow()
{
var properties = new Dictionary<string, string> { { Environment.PropertyServiceProvider, typeof(InvalidNoCtorServiceProvider).AssemblyQualifiedName } };
Assert.That(() => Environment.BuildServiceProvider(properties), Throws.TypeOf<HibernateServiceProviderException>()
.And.InnerException.Message.Contains("constructor was not found"));
}
}
}
Loading