public void SameSessionInSameTransaction() { using (var threaded = new ResolveScope <ThreadedService>(container)) { threaded.Service.VerifySameSession(); } }
public void SameSession_WithRecursion() { using (var threaded = new ResolveScope <ThreadedService>(container)) { threaded.Service.VerifyRecursingSession(); } }
private void Start() { container = new WindsorContainer(); container.AddFacility <LoggingFacility>(f => f.UseNLog()); container .AddFacility <AutoTxFacility>() .Register( Component.For <IConfigurationPersister>().ImplementedBy <FileConfigurationPersister>(), Component.For <INHibernateInstaller>().ImplementedBy <NHibInstaller>().LifeStyle.Singleton, Component.For <Logger>().LifeStyle.Singleton) .AddFacility <NHibernateFacility>(); using (var scope = new ResolveScope <Logger>(container)) { using (var up = new ResolveScope <Configuration>(container)) { new SchemaUpdate(up.Service).Execute(false, true); } Console.WriteLine("Current log contents:"); Console.WriteLine("[utc date] - [text]"); Console.WriteLine("-------------------"); scope.Service.ReadLog(Console.WriteLine); // read everything from saved log scope.Service.WriteToLog(string.Format("{0} - Started", DateTime.UtcNow)); // write simple line to log } }
public void InheritanceKeepTransaction() { using (var scope = new ResolveScope <InheritedMyService>(_Container)) { scope.Service.VerifyInAmbient(); } }
private void Start() { container = new WindsorContainer(); container.AddFacility<LoggingFacility>(f => f.UseNLog()); container .AddFacility<AutoTxFacility>() .Register( Component.For<IConfigurationPersister>().ImplementedBy<FileConfigurationPersister>(), Component.For<INHibernateInstaller>().ImplementedBy<NHibInstaller>().LifeStyle.Singleton, Component.For<Logger>().LifeStyle.Singleton) .AddFacility<NHibernateFacility>(); using (var scope = new ResolveScope<Logger>(container)) { using (var up = new ResolveScope<Configuration>(container)) { new SchemaUpdate(up.Service).Execute(false, true); } Console.WriteLine("Current log contents:"); Console.WriteLine("[utc date] - [text]"); Console.WriteLine("-------------------"); scope.Service.ReadLog(Console.WriteLine); // read everything from saved log scope.Service.WriteToLog(string.Format("{0} - Started", DateTime.UtcNow)); // write simple line to log } }
public void InheritanceKeepTransaction() { using (var scope = new ResolveScope<InheritedMyService>(_Container)) { scope.Service.VerifyInAmbient(); } }
public void Forking_NewTransaction_Means_AnotherISessionReference() { using (var threaded = new ResolveScope <ThreadedService>(container)) { threaded.Service.MainThreadedEntry(); Assert.That(threaded.Service.CalculationsIds.Count, Is.EqualTo(Environment.ProcessorCount)); } }
public void Forking_NewTransaction_Means_AnotherISessionReference() { using (var threaded = new ResolveScope<ThreadedService>(_Container)) { threaded.Service.MainThreadedEntry(); Assert.That(threaded.Service.CalculationsIds.Count, Is.EqualTo(Environment.ProcessorCount)); } }
public void InheritedFromBaseClass() { using (var scope = new ResolveScope<ExtendedConcreteService>(_Container)) { scope.Service.Foo(); scope.Service.VerifyInAmbient(); } }
public void Recursive() { using (var scope = new ResolveScope<ConcreteService>(_Container)) { scope.Service.VerifyInAmbient(() => scope.Service.VerifyInAmbient(() => Assert.That(Transaction.Current != null && Transaction.Current is DependentTransaction) )); } }
public void Recursive() { using (var scope = new ResolveScope <ConcreteService>(_Container)) { scope.Service.VerifyInAmbient(() => scope.Service.VerifyInAmbient(() => Assert.That(Transaction.Current != null && Transaction.Current is DependentTransaction) )); } }
private void Stop() { using (var scope = new ResolveScope <Logger>(container)) scope.Service.WriteToLog(string.Format("{0} - Stopped", DateTime.UtcNow)); foreach (var target in LogManager.Configuration.AllTargets) { target.Dispose(); } container.Dispose(); container = null; }
public void RecursiveTransactions_Inner_Should_Be_DependentTransaction() { using (var txM = new ResolveScope <ITransactionManager>(_Container)) using (var scope = new ResolveScope <MyService>(_Container)) scope.Service.VerifyInAmbient(() => { Assert.That(txM.Service.CurrentTransaction.Value.Inner.TransactionInformation.Status == System.Transactions.TransactionStatus.Active); Assert.That(txM.Service.CurrentTransaction.Value.Inner, Is.InstanceOf <CommittableTransaction>()); scope.Service.VerifyInAmbient(() => Assert.That(txM.Service.CurrentTransaction.Value.Inner, Is.InstanceOf <DependentTransaction>())); }); }
public void RecursiveTransactions_Inner_Should_Be_DependentTransaction() { using (var txM = new ResolveScope<ITransactionManager>(_Container)) using (var scope = new ResolveScope<MyService>(_Container)) scope.Service.VerifyInAmbient(() => { Assert.That(txM.Service.CurrentTransaction.Value.Inner.TransactionInformation.Status == System.Transactions.TransactionStatus.Active); Assert.That(txM.Service.CurrentTransaction.Value.Inner, Is.InstanceOf<CommittableTransaction>()); scope.Service.VerifyInAmbient(() => Assert.That(txM.Service.CurrentTransaction.Value.Inner, Is.InstanceOf<DependentTransaction>())); }); }
public void Method_Can_RollbackItself() { TransactionState state = TransactionState.Default; using (var txM = new ResolveScope <ITransactionManager>(_Container)) using (var scope = new ResolveScope <MyService>(_Container)) { scope.Service.VerifyInAmbient(() => { txM.Service.CurrentTransaction.Value.Rollback(); state = txM.Service.CurrentTransaction.Value.State; }); } Assert.That(state, Is.EqualTo(TransactionState.Aborted)); }
public void Dont_Fork_New_Transaction_In_Already_Forked_One() { // given var c = new WindsorContainer(); c.AddFacility<AutoTxFacility>(); c.AddFacility<FactorySupportFacility>(); c.AddFacility<TypedFactoryFacility>(); c.Register( Component.For<ThreadedService>()); using (var threaded = new ResolveScope<ThreadedService>(c)) { threaded.Service.MainThreadedEntry(); Assert.That(threaded.Service.CalculationsIds.Count, Is.EqualTo(Environment.ProcessorCount)); } }
public void Inline_Rollback_ResourceGetsRolledBack() { var resource = new ThrowingResource(false); using (var txM = new ResolveScope <ITransactionManager>(_Container)) using (var scope = new ResolveScope <MyService>(_Container)) { scope.Service.VerifyInAmbient(() => { txM.Service.CurrentTransaction.Value.Inner.EnlistVolatile(resource, EnlistmentOptions.EnlistDuringPrepareRequired); txM.Service.CurrentTransaction.Value.Rollback(); }); } Assert.That(resource.WasRolledBack); }
public void retrying_twice_on_timeout() { // on app-start var counter = 0; _TransactionManager.AddRetryPolicy("timeouts", e => e is TimeoutException && ++counter <= 2); using (var tx = _TransactionManager.CreateTransaction(new DefaultTransactionOptions()).Value.Transaction) using (var s = new ResolveScope<IMyService>(_Container)) { // in action s.Service.VerifyInAmbient(() => { if (_TransactionManager.CurrentTransaction .Do(x => x.FailedPolicy) .Do(x => x.Failures < 2) .OrThrow(() => new Exception("Test failure; maybe doesn't have value!"))) throw new TimeoutException("database not responding in a timely manner"); }); } }
public void IsDisposed_OnException_And_ActiveDuring_MethodCall() { using (var txM = new ResolveScope<ITransactionManager>(_Container)) { System.Transactions.Transaction ambient = null; ITransaction ourTx = null; try { using (var scope = new ResolveScope<MyService>(_Container)) scope.Service.VerifyInAmbient(() => { ambient = System.Transactions.Transaction.Current; ourTx = txM.Service.CurrentTransaction.Value; Assert.That(ourTx.State, Is.EqualTo(TransactionState.Active)); throw new ApplicationException("should trigger rollback"); }); } catch (ApplicationException) { } Assert.That(ourTx.State, Is.EqualTo(TransactionState.Disposed)); } }
public void IsDisposed_OnException_And_ActiveDuring_MethodCall() { using (var txM = new ResolveScope <ITransactionManager>(_Container)) { System.Transactions.Transaction ambient = null; ITransaction ourTx = null; try { using (var scope = new ResolveScope <MyService>(_Container)) scope.Service.VerifyInAmbient(() => { ambient = System.Transactions.Transaction.Current; ourTx = txM.Service.CurrentTransaction.Value; Assert.That(ourTx.State, Is.EqualTo(TransactionState.Active)); throw new ApplicationException("should trigger rollback"); }); } catch (ApplicationException) { } Assert.That(ourTx.State, Is.EqualTo(TransactionState.Disposed)); } }
private void Start() { container = new Container(); container.Register <ILoggerFactory, NLogLoggerFactory>(Reuse.Singleton, FactoryMethod.ConstructorWithResolvableArguments); container.AddLoggerResolving(); container.Register <INHibernateInstaller, NHibInstaller>(Reuse.Singleton); container.Register <Logger>(Reuse.Singleton); container.AddAutoTx(); container.AddNHibernate(); using (var scope = new ResolveScope <Logger>(container)) { using (var up = new ResolveScope <Configuration>(container)) new SchemaUpdate(up.Service).Execute(false, true); Console.WriteLine("Current log contents:"); Console.WriteLine("[utc date] - [text]"); Console.WriteLine("-------------------"); scope.Service.ReadLog(Console.WriteLine); scope.Service.WriteToLog(string.Format("{0} - Started", DateTime.UtcNow)); } }
public void Automatically_Starts_CommitableTransaction() { using (var scope = new ResolveScope<MyService>(_Container)) scope.Service.VerifyInAmbient(); }
public void Inline_Rollback_ResourceGetsRolledBack() { var resource = new ThrowingResource(false); using (var txM = new ResolveScope<ITransactionManager>(_Container)) using (var scope = new ResolveScope<MyService>(_Container)) { scope.Service.VerifyInAmbient(() => { txM.Service.CurrentTransaction.Value.Inner.EnlistVolatile(resource, EnlistmentOptions.EnlistDuringPrepareRequired); txM.Service.CurrentTransaction.Value.Rollback(); }); } Assert.That(resource.WasRolledBack); }
public void Forking_InDependentTransaction_Means_PerTransactionLifeStyle_SoSameInstances() { using (var threaded = new ResolveScope<ThreadedService>(_Container)) threaded.Service.VerifySameSessionInFork(); }
public void SupressedTransaction_NoCurrentTransaction() { using (var scope = new ResolveScope<IMyService>(_Container)) scope.Service.VerifySupressed(); }
public void SameSession_WithRecursion() { using (var threaded = new ResolveScope<ThreadedService>(_Container)) threaded.Service.VerifyRecursingSession(); }
public void SameSessionInSameTransaction() { using (var threaded = new ResolveScope<ThreadedService>(_Container)) threaded.Service.VerifySameSession(); }
public void SupressedTransaction_InCurrentTransaction() { using (var scope = new ResolveScope<MyService>(_Container)) scope.Service.VerifyInAmbient(() => scope.Service.VerifySupressed()); }
public void SupressedTransaction_InCurrentTransaction() { using (var scope = new ResolveScope <MyService>(_Container)) scope.Service.VerifyInAmbient(() => scope.Service.VerifySupressed()); }
public void NonRecursive() { using (var scope = new ResolveScope<ConcreteService>(_Container)) scope.Service.VerifyInAmbient(); }
public void Forking_InDependentTransaction_Means_PerTransactionLifeStyle_SoSameInstances() { using (var threaded = new ResolveScope <ThreadedService>(container)) threaded.Service.VerifySameSessionInFork(); }
public void Method_Can_RollbackItself() { TransactionState state = TransactionState.Default; using (var txM = new ResolveScope<ITransactionManager>(_Container)) using (var scope = new ResolveScope<MyService>(_Container)) { scope.Service.VerifyInAmbient(() => { txM.Service.CurrentTransaction.Value.Rollback(); state = txM.Service.CurrentTransaction.Value.State; }); } Assert.That(state, Is.EqualTo(TransactionState.Aborted)); }
public void NonRecursive() { using (var scope = new ResolveScope <ConcreteService>(_Container)) scope.Service.VerifyInAmbient(); }
private void Stop() { using (var scope = new ResolveScope<Logger>(container)) scope.Service.WriteToLog(string.Format("{0} - Stopped", DateTime.UtcNow)); foreach (var target in LogManager.Configuration.AllTargets) target.Dispose(); container.Dispose(); container = null; }
public void Automatically_Starts_CommitableTransaction() { using (var scope = new ResolveScope <MyService>(_Container)) scope.Service.VerifyInAmbient(); }