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 CanSetAutoClose <T>(T sb) where T : ISessionBuilder <T> { var options = DebugSessionFactory.GetCreationOptions(sb); CanSet(sb, sb.AutoClose, () => options.ShouldAutoClose, sb is ISharedSessionBuilder ssb ? ssb.AutoClose : default(Func <ISharedSessionBuilder>), // initial values false, // values true, false); }
private void CanSetFlushMode <T>(T sb) where T : ISessionBuilder <T> { var options = DebugSessionFactory.GetCreationOptions(sb); CanSet(sb, sb.FlushMode, () => options.InitialSessionFlushMode, sb is ISharedSessionBuilder ssb ? ssb.FlushMode : default(Func <ISharedSessionBuilder>), // initial values Sfi.Settings.DefaultFlushMode, // values FlushMode.Always, FlushMode.Auto, FlushMode.Commit, FlushMode.Manual); }
private void CanSetConnectionReleaseMode <T>(T sb) where T : ISessionBuilder <T> { var options = DebugSessionFactory.GetCreationOptions(sb); CanSet(sb, sb.ConnectionReleaseMode, () => options.SessionConnectionReleaseMode, sb is ISharedSessionBuilder ssb ? ssb.ConnectionReleaseMode : default(Func <ISharedSessionBuilder>), // initial values Sfi.Settings.ConnectionReleaseMode, // values ConnectionReleaseMode.OnClose, ConnectionReleaseMode.AfterStatement, ConnectionReleaseMode.AfterTransaction); }
private void CanSetAutoJoinTransactionOnStateless <T>(T sb) where T : IStatelessSessionBuilder { var options = DebugSessionFactory.GetCreationOptions(sb); CanSetOnStateless( sb, sb.AutoJoinTransaction, () => options.ShouldAutoJoinTransaction, sb is ISharedStatelessSessionBuilder ssb ? ssb.AutoJoinTransaction : default(Func <ISharedStatelessSessionBuilder>), // initial value true, // values false, true); }
public void CanSetAutoJoinTransactionOnStateless() { var sb = Sfi.WithStatelessOptions(); var sbType = sb.GetType().Name; var options = DebugSessionFactory.GetCreationOptions(sb); Assert.That(options.ShouldAutoJoinTransaction, Is.True, $"{sbType}: Initial value"); var fsb = sb.AutoJoinTransaction(false); Assert.That(options.ShouldAutoJoinTransaction, Is.False, $"{sbType}: After call with false"); Assert.That(fsb, Is.SameAs(sb), $"{sbType}: Unexpected fluent return after call with false"); fsb = sb.AutoJoinTransaction(true); Assert.That(options.ShouldAutoJoinTransaction, Is.True, $"{sbType}: After call with true"); Assert.That(fsb, Is.SameAs(sb), $"{sbType}: Unexpected fluent return after call with true"); }
private async Task CanSetConnectionAsync <T>(T sb, CancellationToken cancellationToken = default(CancellationToken)) where T : ISessionBuilder <T> { var sbType = sb.GetType().Name; var conn = await(Sfi.ConnectionProvider.GetConnectionAsync(cancellationToken)); try { var options = DebugSessionFactory.GetCreationOptions(sb); Assert.IsNull(options.UserSuppliedConnection, $"{sbType}: Initial value"); var fsb = sb.Connection(conn); Assert.AreEqual(conn, options.UserSuppliedConnection, $"{sbType}: After call with a connection"); Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after call with a connection"); if (sb is ISharedSessionBuilder ssb) { var sharedOptions = (ISharedSessionCreationOptions)options; Assert.IsFalse(sharedOptions.IsTransactionCoordinatorShared, $"{sbType}: Transaction coordinator shared before sharing"); Assert.IsNull(sharedOptions.ConnectionManager, $"{sbType}: Connection manager shared before sharing"); var fssb = ssb.Connection(); // Sharing connection shares the connection manager, not the connection. Assert.IsNull(options.UserSuppliedConnection, $"{sbType}: After call with previous session connection"); Assert.IsTrue(sharedOptions.IsTransactionCoordinatorShared, $"{sbType}: Transaction coordinator not shared after sharing"); Assert.IsNotNull(sharedOptions.ConnectionManager, $"{sbType}: Connection manager not shared after sharing"); Assert.AreEqual(sb, fssb, $"{sbType}: Unexpected fluent return on shared"); fsb = sb.Connection(null); Assert.IsNull(options.UserSuppliedConnection, $"{sbType}: After call with null"); Assert.IsFalse(sharedOptions.IsTransactionCoordinatorShared, $"{sbType}: Transaction coordinator shared after un-sharing"); Assert.IsNull(sharedOptions.ConnectionManager, $"{sbType}: Connection manager shared after un-sharing"); Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after un-sharing"); } else { fsb = sb.Connection(null); Assert.IsNull(options.UserSuppliedConnection, $"{sbType}: After call with null"); Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after call with null"); } } finally { Sfi.ConnectionProvider.CloseConnection(conn); } }
public async Task CanSetConnectionOnStatelessAsync() { var sb = Sfi.WithStatelessOptions(); var sbType = sb.GetType().Name; var conn = await(Sfi.ConnectionProvider.GetConnectionAsync(CancellationToken.None)); try { var options = DebugSessionFactory.GetCreationOptions(sb); Assert.IsNull(options.UserSuppliedConnection, $"{sbType}: Initial value"); var fsb = sb.Connection(conn); Assert.AreEqual(conn, options.UserSuppliedConnection, $"{sbType}: After call with a connection"); Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after call with a connection"); fsb = sb.Connection(null); Assert.IsNull(options.UserSuppliedConnection, $"{sbType}: After call with null"); Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after call with null"); } finally { Sfi.ConnectionProvider.CloseConnection(conn); } }