public void Can_Write_And_Read_A_Null_LocalTime_Stored_As_Time() { var timeZone = DateTimeZoneProviders.Tzdb.GetSystemDefault(); LocalTime startLocalTime = TestClock.Now.InZone(timeZone).TimeOfDay; var testEvent = new LocalTimeTestEntity { Description = "Can_Write_And_Read_A_Null_LocalTime_Stored_As_Time", StartLocalTime = startLocalTime, FinishLocalTime = null }; using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.Save(testEvent); transaction.Commit(); } LocalTimeTestEntity retrievedEvent; using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { retrievedEvent = session.Get <LocalTimeTestEntity>(testEvent.Id); transaction.Commit(); } Assert.That(retrievedEvent.StartLocalTime, Is.EqualTo(testEvent.StartLocalTime)); Assert.That(retrievedEvent.FinishLocalTime, Is.EqualTo(testEvent.FinishLocalTime)); }
public void Can_Write_LocalTime_Stored_As_Time() { using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { var timeZone = DateTimeZoneProviders.Tzdb.GetSystemDefault(); LocalTime startLocalTime = TestClock.Now.InZone(timeZone).TimeOfDay; var testEvent = new LocalTimeTestEntity { Description = "Can_Write_LocalTime_Stored_As_Time", StartLocalTime = startLocalTime }; session.Save(testEvent); transaction.Commit(); Assert.That(testEvent.Id, Is.Not.Null); } }
public void Can_Query_By_GreaterThan_LocalTime_Stored_As_Time() { var timeZone = DateTimeZoneProviders.Tzdb.GetSystemDefault(); LocalTime startLocalTime = TestClock.Now.InZone(timeZone).TimeOfDay.Plus(Period.FromHours(1)); LocalTime finishLocalTime = startLocalTime.PlusHours(3); var testEvent = new LocalTimeTestEntity { Description = "Can_Query_By_GreaterThan_LocalTime_Stored_As_Time", StartLocalTime = startLocalTime, FinishLocalTime = finishLocalTime }; using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.Save(testEvent); transaction.Commit(); } LocalTime beforeLocalTime = startLocalTime.Minus(Period.FromHours(1)); using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { var query = session.Query <LocalTimeTestEntity>() .Where(x => x.Id == testEvent.Id && x.StartLocalTime > beforeLocalTime); var retrievedEvent = query.SingleOrDefault(); transaction.Commit(); Assert.That(testEvent, Is.Not.Null); Assert.That(testEvent, Is.EqualTo(retrievedEvent)); } using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { var query = session.Query <LocalTimeTestEntity>() .Where(x => x.Id == testEvent.Id && x.StartLocalTime > beforeLocalTime && x.FinishLocalTime >= finishLocalTime); var retrievedEvent = query.SingleOrDefault(); transaction.Commit(); Assert.That(testEvent, Is.Not.Null); Assert.That(testEvent, Is.EqualTo(retrievedEvent)); } }