public void DateTime2ConventionStoresDateTimeWithMilliseconds() { this.fluentMapperConfigurer.RegisterConvention <DateTime2Convention>(); var dateTime = new DateTime(2012, 12, 19, 21, 56, 7, 456); using (var sessionFactory = this.configuration.CreateSessionFactory()) { using (var unitOfWorkFactory = new SQLiteUnitOfWorkFactory(this.configuration, sessionFactory, null, null, null, null, new ConsoleLogger())) { long fooId; using (var unitOfWork = unitOfWorkFactory.Create()) { var foo = new Foo { DateTimeValue = dateTime }; unitOfWork.Add(foo); unitOfWork.Save(); fooId = foo.ID; } using (var unitOfWork = unitOfWorkFactory.Create()) { var foo = unitOfWork.Query <Foo>().Single(c => c.ID == fooId); Assert.AreEqual(dateTime, foo.DateTimeValue); } } } }
public void IfExtensionMethodCanBeUsedWithReferenceProperty() { using (var sessionFactory = this.configuration.CreateSessionFactory()) { using (var unitOfWorkFactory = new SQLiteUnitOfWorkFactory(this.configuration, sessionFactory, null, null, null, null, new ConsoleLogger())) { unitOfWorkFactory.ExecuteSql(string.Format("insert into Foo (Guid, IntEnum, IntValue) values ('{0}', 0, null)", Guid.NewGuid())); unitOfWorkFactory.ExecuteSql(string.Format("insert into Foo (Guid, IntEnum, IntValue) values ('{0}', 0, null)", Guid.NewGuid())); unitOfWorkFactory.ExecuteSql(string.Format("insert into BaseClass (Guid, IntEnum, FooID) values ('{0}', 0, null)", Guid.NewGuid())); unitOfWorkFactory.ExecuteSql(string.Format("insert into BaseClass (Guid, IntEnum, FooID) values ('{0}', 0, 1)", Guid.NewGuid())); unitOfWorkFactory.ExecuteSql(string.Format("insert into BaseClass (Guid, IntEnum, FooID) values ('{0}', 0, 2)", Guid.NewGuid())); unitOfWorkFactory.ExecuteSql(string.Format("insert into BaseClass (Guid, IntEnum, FooID) values ('{0}', 1, 2)", Guid.NewGuid())); using (var unitOfWork = unitOfWorkFactory.Create()) { var x = unitOfWork.Query <BaseClass>() .GroupBy(c => c.IntEnum) .Select(c => new Tuple <IntEnum, int, int>(c.Key, c.Count(), c.Sum(d => Extensions.If(d.Foo == null, 0, 1)))) .ToList(); Assert.AreEqual(2, x.Count); Assert.AreEqual(IntEnum.Zero, x[0].Item1); Assert.AreEqual(3, x[0].Item2); Assert.AreEqual(2, x[0].Item3); Assert.AreEqual(IntEnum.One, x[1].Item1); Assert.AreEqual(1, x[1].Item2); Assert.AreEqual(1, x[1].Item3); } } } }
public void InsertingDuplicateBarNameInDifferentFactoryDoesNotThrowException() { using (var unitOfWorkFactory = new SQLiteUnitOfWorkFactory(this.configuration, this.sessionFactory, null, null, null, null, new ConsoleLogger { DebugLoggingIsEnabled = false })) { using (var unitOfWork = unitOfWorkFactory.Create()) { unitOfWork.Add(new Bar { Name = "myName" }); unitOfWork.Save(); } } using (var unitOfWorkFactory = new SQLiteUnitOfWorkFactory(this.configuration, this.sessionFactory, null, null, null, null, new ConsoleLogger { DebugLoggingIsEnabled = false })) { using (var unitOfWork = unitOfWorkFactory.Create()) { Assert.That(() => unitOfWork.Add(new Bar { Name = "myName" }), Throws.Nothing); } } }
public void InsertingDuplicateBarNameInSameUnitOfWorkThrowsException() { using (var unitOfWorkFactory = new SQLiteUnitOfWorkFactory(this.configuration, this.sessionFactory, null, null, null, null, new ConsoleLogger { DebugLoggingIsEnabled = false })) { using (var unitOfWork = unitOfWorkFactory.Create()) { unitOfWork.Add(new Bar { Name = "myName" }); Assert.That(() => unitOfWork.Add(new Bar { Name = "myName" }), Throws.InstanceOf <GenericADOException>()); } } }
public void ExceptionThrownIfIgnoreVersionConventionNotRegistered() { using (var sessionFactory = this.configuration.CreateSessionFactory()) { using (var unitOfWorkFactory = new SQLiteUnitOfWorkFactory(this.configuration, sessionFactory, null, null, null, null, new ConsoleLogger())) { using (var unitOfWork = unitOfWorkFactory.Create()) { var safeUnitOfWork = unitOfWork; var optimistic = new Optimistic { StringValue = "test" }; Assert.That(() => safeUnitOfWork.Add(optimistic), Throws.InstanceOf <PropertyValueException>()); } } } }
public void OptimisticLockingEntityCanBeAttachedAndChanged() { this.automappingConfiguration.ShouldMapType(c => c == typeof(Optimistic)); this.fluentMapperConfigurer.AutoMapEntitiesFromAssemblyOf <Optimistic>(); using (var sessionFactory = this.configuration.CreateSessionFactory()) { using (var unitOfWorkFactory = new SQLiteUnitOfWorkFactory(this.configuration, sessionFactory, null, null, null, null, new ConsoleLogger())) { var persistedEntity = PersistEntity(unitOfWorkFactory, () => new Optimistic { StringValue = "myValue" }); using (var unitOfWork = unitOfWorkFactory.Create()) { unitOfWork.Attach(persistedEntity); persistedEntity.StringValue = "newStringValue"; unitOfWork.Save(); } } } }