public void Insert_TypedDocumentWithAssignedId_IsStored() { var document = new PersonWithId { _id = SimoId.NewId(), 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 bool Equals(PersonWithId other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (other.ID == ID && Equals(other.LastName, LastName) && Equals(other.MiddleName, MiddleName) && other.Gender == Gender && Equals(other.FirstName, FirstName)); }
public void InsertSingle_TypedDocumentWithEmptyAssignedId_ThrowsException() { var person2Insert = new PersonWithId { _id = SimoId.Empty, Name = "Daniel", Age = 29 }; using (var cn = TestHelper.CreateConnection()) { var insertCommand = new InsertDocumentsCommand(cn) { FullCollectionName = Constants.Collections.PersonsFullCollectionName, Documents = new[] { person2Insert } }; insertCommand.Execute(); } Assert.Fail("Should not have been able to insert document with Empty ObjectId."); }
public void InsertSingle_TypedDocumentWithAssignedId_IsStored() { var person2Insert = new PersonWithId { _id = SimoId.NewId(), 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.GetDocument <PersonWithId>(person2Insert, Constants.Collections.PersonsCollectionName); Assert.AreEqual(person2Insert._id, refetched._id); }
public static void Main() { Person p = new Person(); p.Name = "John"; try { PersonWithId pid = (PersonWithId)p; Console.WriteLine("Conversion succeeded."); } catch (InvalidCastException) { Console.WriteLine("Conversion failed."); } PersonWithId pid1 = new PersonWithId(); pid1.Name = "John"; pid1.Id = "246"; Person p1 = pid1; try { PersonWithId pid1a = (PersonWithId)p1; Console.WriteLine("Conversion succeeded."); } catch (InvalidCastException) { Console.WriteLine("Conversion failed."); } Person p2 = null; try { PersonWithId pid2 = (PersonWithId)p2; Console.WriteLine("Conversion succeeded."); } catch (InvalidCastException) { Console.WriteLine("Conversion failed."); } }