public static void AddAllSQLTables(YellowstonePathology.Business.Mongo.TransferCollection transferCollection) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "SELECT Table_Name, Column_Name " + "FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE " + "WHERE OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey') = 1 " + "AND table_name like 'tbl%'"; cmd.CommandType = CommandType.Text; YellowstonePathology.Business.Mongo.Server server = new Business.Mongo.TestServer(Business.Mongo.TestServer.SQLTransferDatabasename); using (SqlConnection cn = new SqlConnection(YellowstonePathology.Business.Properties.Settings.Default.CurrentConnectionString)) { cn.Open(); cmd.Connection = cn; using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { YellowstonePathology.Business.Mongo.Transfer transfer = new Transfer(); transfer.ObjectId = BsonObjectId.GenerateNewId().ToString(); transfer.TableName = dr.GetString(0); transfer.PrimaryKeyName = dr.GetString(1); transferCollection.Add(transfer); } } } }
public void TestBsonObjectIdEquals() { var a = BsonObjectId.GenerateNewId(); var b = new BsonObjectId(a.Value); var c = BsonObjectId.GenerateNewId(); var n = (BsonObjectId)null; Assert.IsTrue(object.Equals(a, b)); Assert.IsFalse(object.Equals(a, c)); Assert.IsFalse(object.Equals(a, BsonNull.Value)); Assert.IsFalse(a.Equals(n)); Assert.IsFalse(a.Equals(null)); Assert.IsTrue(a == b); Assert.IsFalse(a == c); Assert.IsFalse(a == BsonNull.Value); Assert.IsFalse(a == null); Assert.IsFalse(null == a); Assert.IsTrue(n == null); Assert.IsTrue(null == n); Assert.IsFalse(a != b); Assert.IsTrue(a != c); Assert.IsTrue(a != BsonNull.Value); Assert.IsTrue(a != null); Assert.IsTrue(null != a); Assert.IsFalse(n != null); Assert.IsFalse(null != n); }
public WikiTextVersion() { Id = BsonObjectId.GenerateNewId(); SupportingUserIds = new List <MongoObjectId>(); SupportingUsers = new List <SupportingUser>(); Attachments = new List <Website>(); }
/// <summary> /// Generates an Id for a document. /// </summary> /// <param name="container">The container of the document (will be a MongoCollection when called from the C# driver). </param> /// <param name="document">The document.</param> /// <returns>An Id.</returns> public object GenerateId( object container, object document ) { return(BsonObjectId.GenerateNewId()); }
public void TestCompareTypeTo() { BsonValue[] values = { BsonMinKey.Value, BsonNull.Value, BsonInt32.Zero, BsonString.Empty, new BsonDocument(), new BsonArray(), new BsonBinaryData(new byte[] { 1 }), BsonObjectId.GenerateNewId(), BsonBoolean.False, new BsonDateTime(DateTime.UtcNow), new BsonRegularExpression("pattern") }; for (int i = 0; i < values.Length - 2; i++) { Assert.AreEqual(-1, values[i].CompareTypeTo(values[i + 1])); Assert.AreEqual(1, values[i + 1].CompareTypeTo(values[i])); Assert.IsTrue(values[i] < values[i + 1]); Assert.IsTrue(values[i] <= values[i + 1]); Assert.IsTrue(values[i] != values[i + 1]); Assert.IsFalse(values[i] == values[i + 1]); Assert.IsFalse(values[i] > values[i + 1]); Assert.IsFalse(values[i] >= values[i + 1]); Assert.AreEqual(1, values[i].CompareTypeTo(null)); } }
private BsonDocument CreateBsonDocument(string userId, string userName, DateTime date, string leaveCodeName, string reason) { var leave = new BsonDocument(); leave.Add("_id", BsonObjectId.GenerateNewId().ToString()); leave.Add("tag", "Leave"); leave.Add("type", "leave"); var createdBy = new BsonDocument(); createdBy.Add("id", userId); createdBy.Add("name", userName); leave.Add("createBy", createdBy); leave.Add("engineer", createdBy); leave.Add("hours", 8); leave.Add("reason", reason); leave.Add("leave_type", leaveCodeName); leave.Add("isApproved", false); leave.Add("date", date); leave.Add("created_on", DateTime.Now); return(leave); }
public Organization() { WebSites = new List <Website>(); ProfilePictureHistory = new List <MongoObjectId>(); Projects = new List <OrganizationProject>(); IsPrivate = true; Id = BsonObjectId.GenerateNewId(); }
public void TestGenerateNewIdWithTimestamp() { var timestamp = 0x01020304; var objectId = BsonObjectId.GenerateNewId(timestamp); Assert.IsTrue(objectId.Timestamp == timestamp); Assert.IsTrue(objectId.Machine != 0); Assert.IsTrue(objectId.Pid != 0); }
public void TestGenerateNewIdWithDateTime() { var timestamp = new DateTime(2011, 1, 2, 3, 4, 5, DateTimeKind.Utc); var objectId = BsonObjectId.GenerateNewId(timestamp); Assert.IsTrue(objectId.CreationTime == timestamp); Assert.IsTrue(objectId.Machine != 0); Assert.IsTrue(objectId.Pid != 0); }
public void TestGenerateNewIdWithDateTime() { #pragma warning disable 618 var timestamp = new DateTime(2011, 1, 2, 3, 4, 5, DateTimeKind.Utc); var objectId = BsonObjectId.GenerateNewId(timestamp); Assert.True(objectId.CreationTime == timestamp); Assert.True(objectId.Machine != 0); Assert.True(objectId.Pid != 0); #pragma warning restore }
public void TestMapBsonObjectId() { var value = BsonObjectId.GenerateNewId(); var bsonValue = (BsonObjectId)BsonTypeMapper.MapToBsonValue(value); Assert.AreSame(value, bsonValue); var bsonObjectId = (BsonObjectId)BsonTypeMapper.MapToBsonValue(value, BsonType.ObjectId); Assert.AreSame(value, bsonObjectId); }
public void TestGenerateNewIdWithTimestamp() { #pragma warning disable 618 var timestamp = 0x01020304; var objectId = BsonObjectId.GenerateNewId(timestamp); Assert.IsTrue(objectId.Timestamp == timestamp); Assert.IsTrue(objectId.Machine != 0); Assert.IsTrue(objectId.Pid != 0); #pragma warning restore }
public void TestIComparable() { var objectId1 = BsonObjectId.GenerateNewId(); var objectId2 = BsonObjectId.GenerateNewId(); Assert.AreEqual(0, objectId1.CompareTo(objectId1)); Assert.AreEqual(-1, objectId1.CompareTo(objectId2)); Assert.AreEqual(1, objectId2.CompareTo(objectId1)); Assert.AreEqual(0, objectId2.CompareTo(objectId2)); }
public Issue() { Comments = new List <Comment>(); SummaryWiki = new WikiText(); CategoryIds = new List <int>(); OfficialVote = ForAgainst.Neutral; Urls = new List <Website>(); Id = BsonObjectId.GenerateNewId(); AdditionalVotes = new List <SupportingUser>(); AllowSummaryWiki = true; }
/// <summary> /// Uploads a GridFS file. /// </summary> /// <param name="stream">The source stream.</param> /// <param name="remoteFileName">The remote file name.</param> /// <returns>The file info of the new GridFS file.</returns> public MongoGridFSFileInfo Upload(Stream stream, string remoteFileName) { var options = new MongoGridFSCreateOptions { ChunkSize = _settings.ChunkSize, Id = BsonObjectId.GenerateNewId(), UploadDate = DateTime.UtcNow }; return(Upload(stream, remoteFileName, options)); }
public Idea() { Comments = new List <Comment>(); SummaryWiki = new WikiTextWithHistory(); CategoryIds = new List <int>(); Urls = new List <Website>(); RelatedIdeas = new List <string>(); IsDraft = false; Id = BsonObjectId.GenerateNewId(); Visibility = ObjectVisibility.Public; }
public void TestGenerateNewId() { // compare against two timestamps in case seconds since epoch changes in middle of test var timestamp1 = (int)Math.Floor((DateTime.UtcNow - BsonConstants.UnixEpoch).TotalSeconds); var objectId = BsonObjectId.GenerateNewId(); var timestamp2 = (int)Math.Floor((DateTime.UtcNow - BsonConstants.UnixEpoch).TotalSeconds); Assert.IsTrue(objectId.Timestamp == timestamp1 || objectId.Timestamp == timestamp2); Assert.IsTrue(objectId.Machine != 0); Assert.IsTrue(objectId.Pid != 0); }
public void TestCompareLargerGeneratedId() { var objectId2 = BsonObjectId.GenerateNewId(); // generate before objectId2 var objectId1 = BsonObjectId.GenerateNewId(); Assert.IsFalse(objectId1 < objectId2); Assert.IsFalse(objectId1 <= objectId2); Assert.IsTrue(objectId1 != objectId2); Assert.IsFalse(objectId1 == objectId2); Assert.IsTrue(objectId1 > objectId2); Assert.IsTrue(objectId1 >= objectId2); }
public void TestDoesNotThrowStackOverflowExceptionWhenConvertingToBsonString() { BsonObjectId id1 = BsonObjectId.GenerateNewId(); BsonString id2 = null; Assert.DoesNotThrow(() => { id2 = (BsonString)((IConvertible)id1).ToType(typeof(BsonString), null); }); Assert.AreEqual(id1.ToString(), id2.AsString); }
public void TestCompareEqualGeneratedIds() { var objectId1 = BsonObjectId.GenerateNewId(); var objectId2 = objectId1; Assert.IsFalse(objectId1 < objectId2); Assert.IsTrue(objectId1 <= objectId2); Assert.IsFalse(objectId1 != objectId2); Assert.IsTrue(objectId1 == objectId2); Assert.IsFalse(objectId1 > objectId2); Assert.IsTrue(objectId1 >= objectId2); }
public User() { Educations = new List <Education>(); Positions = new List <WorkPosition>(); MemberOfParties = new List <PoliticalParty>(); PhoneNumbers = new List <PhoneNumber>(); WebSites = new List <Website>(); ProfilePictureHistory = new List <MongoObjectId>(); Settings = new Settings(); Comments = new List <Comment>(); Id = BsonObjectId.GenerateNewId(); }
public ToDoModel AddToDo(ProjectToDosModel model) { var project = GetProject(model.Id); var todo = new ToDo() { Id = BsonObjectId.GenerateNewId(), Subject = model.InsertSubject, ResponsibleUserId = model.InsertResponsibleUserId, DueDate = model.InsertDueDate, Position = project.ToDos.Where(td => !td.FinishDate.HasValue && (!td.IsPrivate || IsProjectEditable(project, false))).Count(), IsPrivate = model.InsertToDoIsPrivate, CreatedByUserId = CurrentUser.Id }; if (!string.IsNullOrEmpty(model.InsertMileStoneId)) { var milestone = project.MileStones.Where(m => m.Id == model.InsertMileStoneId).Single(); todo.Position = milestone.ToDos.Where( td => !td.FinishDate.HasValue && (!td.IsPrivate || IsProjectEditable(project, false))).Count(); milestone.ToDos.Add(todo); } else { project.ToDos.Add(todo); } UpdateProject(project); var idea = GetIdea(project.IdeaId); bus.Send(new ProjectCommand() { ActionType = ActionTypes.ToDoAdded, ProjectId = project.Id, UserId = CurrentUser.Id, ToDoId = todo.Id, Text = todo.Subject, ProjectSubject = idea.Subject, Link = GetProjectUrl(project.Id), MileStoneId = model.InsertMileStoneId, IsPrivate = idea.IsPrivateToOrganization && !string.IsNullOrEmpty(idea.OrganizationId) || model.InsertToDoIsPrivate, SendNotifications = model.InsertSendNotifications, UserFullName = CurrentUser.FullName, UserLink = Url.ActionAbsolute("Details", "Account", new { userObjectId = CurrentUser.Id }) }); return(GetToDoModelFromToDo(todo, project, IsProjectEditable(project, false), model.InsertMileStoneId)); }
public ActionResult Register(string email, string name, string password) { var userEmail = email.ToLower(); var userName = name; var userPassword = Md5.CalculateMd5(password); var validation = new Validation(); var ajaxResponse = validation.ValidateNewUserData(userEmail, userName, userPassword); if (!ajaxResponse.Success) { return(Json(ajaxResponse)); } var userCollection = Dbh.GetCollection <User>("Users"); var newUser = new User { Id = BsonObjectId.GenerateNewId().ToString(), Email = userEmail, Name = userName, Password = userPassword, }; var playerCollection = Dbh.GetCollection <Player>("Players"); var newPlayer = new Player { Id = BsonObjectId.GenerateNewId().ToString(), Email = userEmail, Name = userName, Password = userPassword, }; playerCollection.Save(newPlayer); userCollection.Save(newUser); var accessToken = Main.Session.CreateNewAccessTokenOnUser(newUser); Main.Session.SaveAccessToken(accessToken); ajaxResponse.Data = new { AccessToken = Main.Session.BuildSessionInfo(accessToken, newUser) }; return(Json(ajaxResponse)); }
public ActionResult Register(string email, string name, string password) { var userEmail = email.ToLower(); var userName = name; var userPassword = Md5.CalculateMd5(password); var validation = new Validation(); var response = validation.ValidateNewUserData(userEmail, userName, userPassword); if (!response.Success) { return(Json(response)); } var userCollection = Dbh.GetCollection <User>("Users"); var newUser = new User { Id = BsonObjectId.GenerateNewId().ToString(), Email = userEmail, Name = userName, Password = userPassword, }; var playerCollection = Dbh.GetCollection <Player>("Players"); var newPlayer = new Player { Id = BsonObjectId.GenerateNewId().ToString(), Email = userEmail, Name = userName, Password = userPassword, }; playerCollection.Save(newPlayer); userCollection.Save(newUser); Login(newUser); Events.SubmitEvent(EventType.PlayerCreate, newUser, newUser.Id); response.Data = GetSession(refresh: true); return(Json(response)); }
public void TestBsonDocumentWithBsonObjectId() { _collection.RemoveAll(); var doc = new BsonDocument { { "_id", BsonNull.Value }, { "X", 1 } }; _collection.Insert(doc); Assert.AreEqual(BsonNull.Value, doc["_id"]); doc = new BsonDocument { { "_id", BsonObjectId.Empty }, { "X", 1 } }; _collection.Insert(doc); Assert.AreNotEqual(ObjectId.Empty, doc["_id"].AsObjectId); doc = new BsonDocument { { "_id", BsonObjectId.GenerateNewId() }, { "X", 1 } }; _collection.Insert(doc); }
private void MenuItemBuildPanelSetCollection_Click(object sender, RoutedEventArgs e) { MongoDatabase mongoDatabase = YellowstonePathology.Business.Mongo.MongoTestServer.Instance.LIS; mongoDatabase.DropCollection("PanelSet"); MongoCollection mongoPanelSetCollection = mongoDatabase.GetCollection <BsonDocument>("PanelSet"); YellowstonePathology.Business.PanelSet.Model.PanelSetCollection psCollection = YellowstonePathology.Business.PanelSet.Model.PanelSetCollection.GetAll(); foreach (YellowstonePathology.Business.PanelSet.Model.PanelSet panelSet in psCollection) { panelSet.ObjectId = BsonObjectId.GenerateNewId().ToString(); YellowstonePathology.Business.Test.PanelSetOrder panelSetOrder = YellowstonePathology.Business.Test.PanelSetOrderFactory.CreatePanelSetOrder(panelSet); YellowstonePathology.Business.Persistence.PersistentClass persistentClassAttribute = (YellowstonePathology.Business.Persistence.PersistentClass)panelSetOrder.GetType().GetCustomAttributes(typeof(YellowstonePathology.Business.Persistence.PersistentClass), false).Single(); string assemblyQualifiedName = panelSetOrder.GetType().AssemblyQualifiedName; panelSet.PanelSetOrderClassName = assemblyQualifiedName; panelSet.PanelSetOrderTableName = persistentClassAttribute.StorageName; BsonDocument bsonDocument = YellowstonePathology.Business.Mongo.BSONBuilder.Build(panelSet); mongoPanelSetCollection.Insert(bsonDocument); } }
public void TestClassWithBsonObjectId() { _collection.RemoveAll(); var doc = new ClassWithBsonObjectId { Id = null, X = 1 }; _collection.Insert(doc); Assert.IsNotNull(doc.Id); Assert.AreNotEqual(ObjectId.Empty, doc.Id.AsObjectId); doc = new ClassWithBsonObjectId { Id = BsonObjectId.Empty, X = 1 }; _collection.Insert(doc); Assert.AreNotEqual(ObjectId.Empty, doc.Id.AsObjectId); doc = new ClassWithBsonObjectId { Id = BsonObjectId.GenerateNewId(), X = 1 }; _collection.Insert(doc); }
public PoliticalParty() { Id = BsonObjectId.GenerateNewId(); }
/// <summary> /// Uploads a GridFS file. /// </summary> /// <param name="stream">The source stream.</param> /// <param name="remoteFileName">The remote file name.</param> /// <param name="createOptions">The create options.</param> /// <returns>The file info of the new GridFS file.</returns> public MongoGridFSFileInfo Upload( Stream stream, string remoteFileName, MongoGridFSCreateOptions createOptions ) { using (database.RequestStart()) { EnsureIndexes(); var files_id = createOptions.Id ?? BsonObjectId.GenerateNewId(); var chunkSize = createOptions.ChunkSize == 0 ? settings.ChunkSize : createOptions.ChunkSize; var buffer = new byte[chunkSize]; var length = 0; string md5Client; using (var md5Algorithm = MD5.Create()) { for (int n = 0; true; n++) { // might have to call Stream.Read several times to get a whole chunk var bytesNeeded = chunkSize; var bytesRead = 0; while (bytesNeeded > 0) { var partialRead = stream.Read(buffer, bytesRead, bytesNeeded); if (partialRead == 0) { break; // EOF may or may not have a partial chunk } bytesNeeded -= partialRead; bytesRead += partialRead; } if (bytesRead == 0) { break; // EOF no partial chunk } length += bytesRead; byte[] data = buffer; if (bytesRead < chunkSize) { data = new byte[bytesRead]; Buffer.BlockCopy(buffer, 0, data, 0, bytesRead); } var chunk = new BsonDocument { { "_id", BsonObjectId.GenerateNewId() }, { "files_id", files_id }, { "n", n }, { "data", new BsonBinaryData(data) } }; chunks.Insert(chunk, settings.SafeMode); md5Algorithm.TransformBlock(data, 0, data.Length, null, 0); if (bytesRead < chunkSize) { break; // EOF after partial chunk } } md5Algorithm.TransformFinalBlock(new byte[0], 0, 0); md5Client = BsonUtils.ToHexString(md5Algorithm.Hash); } var md5Command = new CommandDocument { { "filemd5", files_id }, { "root", settings.Root } }; var md5Result = database.RunCommand(md5Command); var md5Server = md5Result.Response["md5"].AsString; if (!md5Client.Equals(md5Server, StringComparison.OrdinalIgnoreCase)) { throw new MongoGridFSException("Upload client and server MD5 hashes are not equal."); } var uploadDate = createOptions.UploadDate == DateTime.MinValue ? DateTime.UtcNow : createOptions.UploadDate; BsonDocument fileInfo = new BsonDocument { { "_id", files_id }, { "filename", remoteFileName }, { "length", length }, { "chunkSize", chunkSize }, { "uploadDate", uploadDate }, { "md5", md5Server }, { "contentType", createOptions.ContentType }, // optional { "aliases", BsonArray.Create((IEnumerable <string>)createOptions.Aliases) }, // optional { "metadata", createOptions.Metadata } // optional }; files.Insert(fileInfo, settings.SafeMode); return(FindOneById(files_id)); } }
public void TestClassWithBsonValueId() { // repeats all tee TestClassWithBsonXyzId tests using ClassWithBsonValueId { // same as TestClassWithBonArrayId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = new BsonArray(), X = 1 }; Assert.Throws <MongoSafeModeException>(() => { _collection.Insert(doc); }); doc = new ClassWithBsonValueId { Id = new BsonArray { 1, 2, 3 }, X = 1 }; Assert.Throws <MongoSafeModeException>(() => { _collection.Insert(doc); }); } { // same as TestClastWithBsonBinaryDataId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonBinaryData.Create(new byte[] { }), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonBinaryData.Create(new byte[] { 1, 2, 3 }), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonBooleanId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonBoolean.Create(false), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonBoolean.Create(true), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonDocumentId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = new BsonDocument(), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = new BsonDocument { { "A", 1 }, { "B", 2 } }, X = 3 }; _collection.Insert(doc); } { // same as TestClassWithBsonDateTimeId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonDateTime.Create(DateTime.MinValue), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonDateTime.Create(DateTime.UtcNow), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonDateTime.Create(DateTime.MaxValue), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonDoubleId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonDouble.Create(0.0), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonDouble.Create(1.0), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonInt32Id _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonInt32.Create(0), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonInt32.Create(1), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonInt64Id _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonInt64.Create(0), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonInt64.Create(1), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonMaxKeyId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); Assert.AreEqual(null, doc.Id); doc = new ClassWithBsonValueId { Id = BsonMaxKey.Value, X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonMinKeyId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); Assert.AreEqual(null, doc.Id); doc = new ClassWithBsonValueId { Id = BsonMinKey.Value, X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonNullId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); Assert.AreEqual(null, doc.Id); doc = new ClassWithBsonValueId { Id = BsonNull.Value, X = 1 }; Assert.Throws <MongoSafeModeException>(() => { _collection.Insert(doc); }); } { // same as TestClassWithBsonObjectId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); Assert.IsNull(doc.Id); // BsonObjectIdGenerator is not invoked when nominalType is BsonValue doc = new ClassWithBsonValueId { Id = BsonObjectId.Empty, X = 1 }; _collection.Insert(doc); Assert.AreEqual(ObjectId.Empty, doc.Id.AsObjectId); // BsonObjectIdGenerator is not invoked when nominalType is BsonValue doc = new ClassWithBsonValueId { Id = BsonObjectId.GenerateNewId(), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonStringId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); Assert.IsNull(doc.Id); doc = new ClassWithBsonValueId { Id = "", X = 1 }; _collection.Insert(doc); Assert.AreEqual("", doc.Id.AsString); doc = new ClassWithBsonValueId { Id = "123", X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonTimestampId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); Assert.IsNull(doc.Id); doc = new ClassWithBsonValueId { Id = BsonTimestamp.Create(0, 0), X = 1 }; _collection.Insert(doc); Assert.AreEqual(BsonTimestamp.Create(0, 0), doc.Id); doc = new ClassWithBsonValueId { Id = BsonTimestamp.Create(1, 2), X = 1 }; _collection.Insert(doc); } }