public void Can_disable_AutoIncrement_field() { //Can't insert in identity column if ((Dialect & Dialect.AnySqlServer) == Dialect) { return; } using (var db = OpenDbConnection()) { db.DropAndCreateTable <PersonWithAutoId>(); typeof(PersonWithAutoId) .GetModelMetadata() .PrimaryKey.AutoIncrement = false; var row = new PersonWithAutoId { Id = 100, FirstName = "Jimi", LastName = "Hendrix", Age = 27 }; db.Insert(row); row = db.SingleById <PersonWithAutoId>(100); Assert.That(row.Id, Is.EqualTo(100)); typeof(PersonWithAutoId) .GetModelMetadata() .PrimaryKey.AutoIncrement = true; } }
public void Insert_TypedDocumentWithAutoAssignedId_IsStored() { var document = new PersonWithAutoId { Name = "Daniel" }; using (var session = new SimoSession(TestHelper.CreateConnection())) { session[DbName][PersonsCollectionName].Insert(document); } var numOfDocs = TestHelper.GetDocumentCount(new { document._id }, Constants.Collections.PersonsCollectionName); Assert.AreEqual(1, numOfDocs); }
public void Save_populates_AutoIncrementId() { using var db = OpenDbConnection(); db.DropAndCreateTable <PersonWithAutoId>(); var row = new PersonWithAutoId { FirstName = "Jimi", LastName = "Hendrix", Age = 27 }; db.Save(row); Assert.That(row.Id, Is.Not.EqualTo(0)); }
public void Save_populates_AutoIncrementId() { using (var db = OpenDbConnection()) { db.CreateTable <PersonWithAutoId>(overwrite: true); var row = new PersonWithAutoId { FirstName = "Jimi", LastName = "Hendrix", Age = 27 }; db.Save(row); Assert.That(row.Id, Is.EqualTo(1)); } }
public void InsertSingle_TypedDocumentWithAutoId_IsStoredAndAssignedId() { var person2Insert = new PersonWithAutoId { Name = "Daniel", Age = 29 }; using (var cn = TestHelper.CreateConnection()) { var insertCommand = new InsertDocumentsCommand(cn) { FullCollectionName = Constants.Collections.PersonsFullCollectionName, Documents = new[] { person2Insert } }; insertCommand.Execute(); } var refetched = TestHelper.GetDocuments <PersonWithId>(new { person2Insert._id }, Constants.Collections.PersonsCollectionName); Assert.AreEqual(1, refetched.Count); }