public void InitializeShouldLog() { var sfp = new SessionFactoryProvider(); Assert.That(Spying.Logger <SessionFactoryProvider>().Execute(sfp.Initialize).WholeMessage, Text.Contains("Initialize a new session factory")); }
public void InitializeShouldLog() { var sfp = new MultiSessionFactoryProvider(); Assert.That(Spying.Logger <MultiSessionFactoryProvider>().Execute(sfp.Initialize).WholeMessage, Text.Contains("Initialize new session factories reading the configuration.")); }
public void ShouldLogMultiConfigurationIgnored() { var sfp = new SessionFactoryProvider(new MultiConfStub()); Assert.That(Spying.Logger <SessionFactoryProvider>().Execute(sfp.Initialize).WholeMessage, Text.Contains("More than one configurations are available")); }
public void DisposeDoNotInitialize() { var sfp = new SessionFactoryProvider(); Assert.That(Spying.Logger <SessionFactoryProvider>().Execute(sfp.Dispose).WholeMessage, Text.DoesNotContain("Initialize a new session factory")); }
public virtual void ShouldWorkWithServiceCtorInterceptor() { IServiceLocator serviceLocator = NewServiceLocator(); RegisterAsTransient <ISillyCrudModel, InheritedSillyCrudModelWithServiceConversationCreationInterceptor>( serviceLocator); var convFactory = new ConversationFactoryStub(delegate(string id) { IConversation result = new NoOpConversationStub(id); return(result); }); RegisterInstanceForService <IConversationFactory>(serviceLocator, convFactory); // Registr the IConversationCreationInterceptor implementation RegisterAsTransient <IMyServiceConversationCreationInterceptor, ConversationCreationInterceptor>(serviceLocator); var scm = serviceLocator.GetInstance <ISillyCrudModel>(); Assert.That( Spying.Logger <ConversationCreationInterceptor>().Execute(() => scm.GetIfAvailable(Guid.NewGuid())).MessageSequence, Is.EqualTo(new[] { ConversationCreationInterceptor.StartingMessage, ConversationCreationInterceptor.StartedMessage })); // cleanup var conversationContainer = (ThreadLocalConversationContainerStub)serviceLocator.GetInstance <IConversationContainer>(); conversationContainer.Reset(); }
public void DisposeDoNotInitialize() { var sfp = new MultiSessionFactoryProvider(); Assert.That(Spying.Logger <MultiSessionFactoryProvider>().Execute(sfp.Dispose).WholeMessage, Text.DoesNotContain("Initialize new session factories reading the configuration.")); }
public void ShouldStartUnitOfWorkWhenFirstMethodCalledOnConversationModel() { //given var scm = ServiceLocator.Current.GetInstance <ISillyCrudModel>(); Assert.That(Spying.Logger(NHibernateSessionLoggerName).Execute(() => scm.GetEntirelyList()).WholeMessage, Text.Contains(SessionOpenedMessage)); }
public void ShouldWorkFine() { Assert.That( Spying.Logger <LoggedClassStub>() .Execute(() => (new LoggedClassStub()).LogDebug("my message")) .MessageSequence, Is.EqualTo(new[] { "my message" })); }
public void CallingMethodThatEndsConversationShouldFlushUnitOfWork() { //given var scm = ServiceLocator.Current.GetInstance <ISillyCrudModel>(); scm.Save(new Silly()); Assert.That(Spying.Logger(NHibernateFlushEventsLoggerName).Execute(scm.AcceptAll).WholeMessage, Text.Contains(ExecutingFlushMessage)); }
public void ShouldInitializeOnlyOneTime() { var sfp = new SessionFactoryProvider(); Assert.That(sfp.GetFactory(null), Is.Not.Null); Assert.That(Spying.Logger <SessionFactoryProvider>().Execute(sfp.Initialize).WholeMessage, Text.DoesNotContain("Initialize a new session factory")); }
public void ShouldInitializeOnlyOneTime() { var sfp = new MultiSessionFactoryProvider(); Assert.That(sfp.GetFactory(null), Is.Not.Null); Assert.That(Spying.Logger <MultiSessionFactoryProvider>().Execute(sfp.Initialize).WholeMessage, Text.DoesNotContain("Initialize new session factories reading the configuration.")); }
public void SubsequentCallsAfterAbortingConversationShouldStartAnotherUnitOfWork() { //given var scm = ServiceLocator.Current.GetInstance <ISillyCrudModel>(); scm.Save(new Silly()); scm.Abort(); Assert.That(Spying.Logger(NHibernateSessionLoggerName).Execute(() => scm.GetEntirelyList()).WholeMessage, Text.Contains(SessionOpenedMessage)); }
public void ShouldRetainUnitOfWorkBetweenMethodCallsToConversationModel() { //given var scm = ServiceLocator.Current.GetInstance <ISillyCrudModel>(); Assert.That(Spying.Logger(NHibernateSessionLoggerName).Execute(() => { scm.GetEntirelyList(); scm.GetEntirelyList(); }).WholeMessage, Text.DoesNotContain(SessionDisposedMessage)); }
public void SusequentCallsShouldExecuteWithinSameUnitOfWork() { //given var scm = ServiceLocator.Current.GetInstance <ISillyCrudModel>(); Assert.That(Spying.Logger(NHibernateSessionLoggerName).Execute(() => { scm.GetEntirelyList(); scm.GetEntirelyList(); }).MessageSequence.Where( msg => msg.Contains(SessionOpenedMessage)).Count(), Is.EqualTo(1)); }
public void persisting_an_order_should_log_message() { var purchaseOrder = new PurchaseOrder { Date = DateTime.Now, Number = "N1" }; Assert.That(Spying.Logger(typeof(MyConversationCreationInterceptor <>)) .Execute(() => modifyOrderModel.Persist(purchaseOrder)) .MessageSequence, Is.EqualTo(new[] { "My conversation ended" })); }
public void ManualBindSessionToConversationShouldUnbindOrphanedSession() { // TODO: recreate this test in ConversationFixtureBase to check the wrapper NhConversation c = NewStartedConversation(); ISession s = sessions.OpenSession(); Assert.That(Spying.Logger <NhConversation>().Execute(() => c.Bind(s)).WholeMessage, Text.Contains("Already session bound on call to Bind()")); ISession sessionFromConversation = c.GetSession(sessions); Assert.That(c.Wrapper.IsWrapped(sessionFromConversation), "The new bind session should be wrapped and managed by the Wrapper."); Assert.That(sessionFromConversation.FlushMode, Is.EqualTo(FlushMode.Never), "The FlushMode of new bind session should be changed to Never."); }
public void PauseAndFlushCallSequence() { using (var t = new TestConversation()) { const string pausing = "Pausing called."; const string paused = "Paused called."; t.Pausing += ((x, y) => t.Log.Debug(pausing)); t.Paused += ((x, y) => t.Log.Debug(paused)); Assert.That(Spying.Logger <TestConversation>() .Execute(t.FlushAndPause) .MessageSequence, Is.EqualTo(new[] { pausing, TestConversation.FlushAndPauseMessage, paused })); } }
public void ResumeCallSequence() { using (var t = new TestConversation()) { const string resuming = "Resuming called."; const string resumed = "Resumed called."; t.Resuming += ((x, y) => t.Log.Debug(resuming)); t.Resumed += ((x, y) => t.Log.Debug(resumed)); Assert.That(Spying.Logger <TestConversation>() .Execute(t.Resume) .MessageSequence, Is.EqualTo(new[] { resuming, TestConversation.ResumeMessage, resumed })); } }
public void SessionCloseOutsideTheConversation() { NhConversation c = NewStartedConversation(); ISession session = c.GetSession(sessions); session.Close(); Assert.That(c.GetSession(sessions), Is.SameAs(session)); Assert.DoesNotThrow(c.Pause); Assert.That(Spying.Logger <NhConversation>().Execute(c.Resume).WholeMessage, Text.DoesNotContain("Already session bound on call to Bind()"), "No warning is needed for a closed session."); Assert.That(c.GetSession(sessions), Is.Not.SameAs(session)); c.Dispose(); }
public void CallingMethodThatAbortsConversationShouldThrowAwayUnitOfWork() { //given var scm = ServiceLocator.Current.GetInstance <ISillyCrudModel>(); scm.Save(new Silly()); //when string msgs = Spying.Logger(NHibernateSessionLoggerName).Execute(scm.Abort).WholeMessage; //then Assert.That(msgs, Text.DoesNotContain(ExecutingFlushMessage)); Assert.That(msgs, Text.Contains(SessionDisposedMessage)); }
public void StartCallSequence() { // I'm using log instad a mock, I know using (var t = new TestConversation()) { const string starting = "Starting called."; const string started = "Started called."; t.Starting += ((x, y) => t.Log.Debug(starting)); t.Started += ((x, y) => t.Log.Debug(started)); Assert.That(Spying.Logger <TestConversation>() .Execute(t.Start) .MessageSequence, Is.EqualTo(new[] { starting, TestConversation.StartMessage, started })); } }
public void DisposeCallSequence() { const string ended = "End called."; Assert.That(Spying.Logger <TestConversation>() .Execute(() => { using (var t = new TestConversation()) { t.Ended += ((x, y) => t.Log.Debug(ended)); t.Ended += ((x, y) => Assert.That(y.Disposing)); } }) .MessageSequence, Is.EqualTo(new[] { TestConversation.AbortMessage, ended, TestConversation.DisposeMessage })); }
public void EndCallSequence() { using (var t = new TestConversation()) { const string ending = "Ending called."; const string ended = "Ended called."; t.Ending += ((x, y) => t.Log.Debug(ending)); t.Ended += ((x, y) => t.Log.Debug(ended)); t.Ended += AssertEndedOutOfDisposing; Assert.That(Spying.Logger <TestConversation>() .Execute(t.End) .MessageSequence, Is.EqualTo(new[] { ending, TestConversation.EndMessage, ended })); t.Ended -= AssertEndedOutOfDisposing; } }
public void SessionDisposeOutsideTheConversation() { NhConversation c = NewStartedConversation(); using (c.GetSession(sessions)) { // Do nothing only simulate a possible usage // of sessions.GetCurrentSession() outside conversation management } // Need some new events in NH about session.Close (Event/Listener) // Assert.That(c.GetSession(sessions), Is.Null, "should auto unbind the session."); Assert.DoesNotThrow(c.Pause); Assert.That(Spying.Logger <NhConversation>().Execute(c.Resume).WholeMessage, Text.DoesNotContain("Already session bound on call to Bind()"), "No warning is needed for a closed session."); Assert.That(c.GetSession(sessions), Is.Not.Null); c.Dispose(); }
public void ShouldNotStartUnitOfWorkWhenConversationModelFirstCreated() { Assert.That( Spying.Logger(NHibernateSessionLoggerName).Execute(() => ServiceLocator.Current.GetInstance <ISillyCrudModel>()). WholeMessage, Text.DoesNotContain(SessionOpenedMessage)); }