Esempio n. 1
0
        public async Task TestGetById(string id)
        {
            var repository = new MongoDBRepository();
            var entity     = await repository.Get <BaseEntity>(Guid.Parse(id));

            Assert.Equal <Guid>(Guid.Parse(id), entity.Id);
        }
Esempio n. 2
0
        public async Task TestMultiInsert(int max)
        {
            var repository = new MongoDBRepository();
            var tasks      = new List <Task <BaseEntity> >();

            for (int count = 0; count < max; count++)
            {
                tasks.Add(repository.Insert(new BaseEntity()
                {
                    Name = String.Format("Alice{0}", count)
                }));
            }

            var names = new List <string>();

            // Run collection of Inserts concurrently
            foreach (var bucket in TaskProcessor.Interleaved(tasks))
            {
                var t = await bucket;
                try { var entity = await t;
                      names.Add(entity.Name); }
                catch (OperationCanceledException) { }
                catch (Exception exc) {
                    Debug.WriteLine(exc);
                }
            }

            Assert.Equal(max, names.Count);
        }
Esempio n. 3
0
        public async Task TestGet()
        {
            var repository = new MongoDBRepository();
            var entities   = await repository.Get <BaseEntity>();

            Assert.NotNull(entities);
            Assert.NotEmpty(entities);
        }
Esempio n. 4
0
        public async Task TestInsert()
        {
            var repository = new MongoDBRepository();
            var entity     = await repository.Insert(new BaseEntity()
            {
                Name = "Alice"
            });

            Assert.Equal <string>("Alice", entity.Name);
        }
Esempio n. 5
0
        public async Task TestDelete(string id)
        {
            var repository = new MongoDBRepository();
            await repository.Delete <BaseEntity>(Guid.Parse(id));

            Assert.Throws(typeof(AggregateException), delegate
            {
                var entity = repository.Get <BaseEntity>(Guid.Parse(id)).Result;
            });
        }