public void NewId_GetTwo_NotEqualToEachOther()
        {
            var id1 = SimoId.NewId();
            var id2 = SimoId.NewId();

            Assert.AreNotEqual(id1, id2);
        }
        public void TimeStamp_NewId_HasTodaysUtcDate()
        {
            //TODO: Isolate date
            var id = SimoId.NewId();

            Assert.AreEqual(DateTime.UtcNow.Date, id.TimeStamp.Date);
        }
Esempio n. 3
0
        public SimoReference Reference(string entityName, SimoId id)
        {
            entityName = Session.Pluralizer.Pluralize(entityName);

            return(new SimoReference {
                CollectionName = entityName, Id = id
            });
        }
        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 void NewRelation_UsingAnonymousTypes_ReferenceCreated()
        {
            var parentId        = SimoId.NewId();
            var parent          = new { _id = parentId, Name = "Daniel" };
            var fatherReference = new SimoReference
            {
                CollectionName = Constants.Collections.ParentsCollectionName,
                Id             = parent._id
            };
            var child = new { _id = SimoId.NewId(), Name = "Isabell", Father = fatherReference };

            TestHelper.InsertDocument(Constants.Collections.ParentsFullCollectionName, parent);
            TestHelper.InsertDocument(Constants.Collections.ChildsFullCollectionName, child);

            var refetchedChild = TestHelper.GetDocument(new { child._id }, child, Constants.Collections.ChildsFullCollectionName);

            Assert.AreEqual(fatherReference.Id, refetchedChild.Father.Id);
            Assert.AreEqual(fatherReference.CollectionName, refetchedChild.Father.CollectionName);
        }
        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 override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var oid = value as SimoId;

            if (SimoId.IsNullOrEmpty(oid))
            {
                throw new SerializationException(ExceptionMessages.SimoObjectIdJsonConverter_InvalidId);
            }

            var bsonWriter = writer as BsonWriter;

            if (bsonWriter != null)
            {
                bsonWriter.WriteObjectId(oid);
            }
            else
            {
                writer.WriteValue(oid.Value);
            }
        }
 public void Ctor_NullBytes_ThrowsException()
 {
     var id = new SimoId(null as byte[]);
 }
 public void IsNullOrEmpty_ForNull_IsTrue()
 {
     Assert.IsTrue(SimoId.IsNullOrEmpty(null));
 }
        public void IsNullOrEmpty_ForEmpty_IsTrue()
        {
            var id = SimoId.Empty;

            Assert.IsTrue(SimoId.IsNullOrEmpty(id));
        }
        public void NewId_NotEqualToEmptyObjectId()
        {
            var id = SimoId.NewId();

            Assert.AreNotEqual(SimoId.Empty, id);
        }
 public void Ctor_ToManyBytes_ThrowsException()
 {
     var id = new SimoId(new byte[13]);
 }
 public void Ctor_ToFewBytes_ThrowsException()
 {
     var id = new SimoId(new byte[11]);
 }
 public void Ctor_NullBytes_ThrowsException()
 {
     var id = new SimoId(null as byte[]);
 }
Esempio n. 15
0
 private SimoAutoId(SimoId id)
 {
     Id = id;
 }
 public void Ctor_ToFewBytes_ThrowsException()
 {
     var id = new SimoId(new byte[11]);
 }
 public void Ctor_ToManyBytes_ThrowsException()
 {
     var id = new SimoId(new byte[13]);
 }
Esempio n. 18
0
        public SimoReference Reference <T>(SimoId id) where T : class
        {
            var entityName = EntityMetadata <T> .EntityName;

            return(Reference(entityName, id));
        }