public void Update <TEntity>(TEntity entity)
            where TEntity : class
        {
            IMongoCollection <TEntity> mongoCollection = (IMongoCollection <TEntity>)GetCollection(typeof(TEntity));

            mongoCollection.WithWriteConcern(WriteConcern.Acknowledged).ReplaceOne(DynamicLambdaBuilder.GetIdLE(entity, typeof(PersistenceIdAttribute)), entity);
        }
        public void Remove <TEntity>(TEntity entity)
            where TEntity : class
        {
            ICollection <TEntity> collection = (ICollection <TEntity>)GetCollection(typeof(TEntity));
            TEntity entityStored             = collection.SingleOrDefault(DynamicLambdaBuilder.GetIdLE(entity).Compile());

            collection.Remove(entityStored);
        }
Exemplo n.º 3
0
 public void GetIdLE_PersistenceIdAttributeWithDuplicateId_DuplicatedIdException()
 {
     Assert.ThrowsException <DuplicateIdException>(() =>
     {
         VersionWithDuplicateId version = new VersionWithDuplicateId()
         {
             Name = "versionWithId", Descpription = "D"
         };
         var expression = DynamicLambdaBuilder.GetIdLE(version, typeof(PersistenceIdAttribute));
     });
 }
Exemplo n.º 4
0
        public void GetIdLE_PersistenceIdAttributeWithoutIdAttribute_DuplicatedIdException()
        {
            VersionWithoutIdAttribute version = new VersionWithoutIdAttribute()
            {
                Name = "versionWithId", Descpription = "D"
            };
            var expression       = DynamicLambdaBuilder.GetIdLE(version, typeof(PersistenceIdAttribute));
            var binaryExpression = (BinaryExpression)expression.Body;
            var memberExpression = (MemberExpression)binaryExpression.Left;

            Assert.AreEqual("Id", memberExpression.Member.Name);
        }