Пример #1
0
 public void CanCreateRepository()
 {
     using (var database = new MongoDbTest())
     {
         var repository = new Repository<ToDoItem>(database.Database);
     }
 }
Пример #2
0
        public void CanCount()
        {
            using (var database = new MongoDbTest())
            {
                var repository = new Repository<ToDoItem>(database.Database);

                var item = new ToDoItem() { Item = "Item", Title = "Title" };
                item = repository.Insert(item);

                Assert.NotNull(item);

                Assert.Equal(1, repository.Count(e => e.Title == "Title"));
                Assert.Equal(0, repository.Count(e => e.Title == "test"));
            }
        }
Пример #3
0
        public void CanAny()
        {
            using (var database = new MongoDbTest())
            {
                var repository = new Repository<ToDoItem>(database.Database);

                var item = new ToDoItem() { Item = "Item", Title = "Title" };
                item = repository.Insert(item);

                Assert.NotNull(item);

                Assert.True(repository.Any(e => e.Title == "Title"));
                Assert.False(repository.Any(e => e.Title == "test"));
            }
        }
Пример #4
0
        public void CanDelete()
        {
            using (var database = new MongoDbTest())
            {
                var repository = new Repository<ToDoItem>(database.Database);

                var item = new ToDoItem() { Item = "Item", Title = "Title" };
                item = repository.Insert(item);

                Assert.NotNull(item);

                Assert.NotNull(repository.Delete(item));

                Assert.Null(repository.ById(item.Id));
            }
        }
Пример #5
0
        public void CanFind()
        {
            using (var database = new MongoDbTest())
            {
                var repository = new Repository<ToDoItem>(database.Database);

                var item = new ToDoItem() { Item = "Item", Title = "Title" };
                item = repository.Insert(item);

                Assert.NotNull(item);

                var result = repository.Find(e => e.Title == "Title");
                Assert.NotNull(result);
                Assert.Single(result);

                result = repository.Find(e => e.Title == "test");
                Assert.NotNull(result);
                Assert.Empty(result);
            }
        }
Пример #6
0
        public void CanUpdate()
        {
            using (var database = new MongoDbTest())
            {
                var repository = new Repository<ToDoItem>(database.Database);

                var item = new ToDoItem() { Item = "Item", Title = "Title" };
                item = repository.Insert(item);

                Assert.NotNull(item);

                item.Title = "Changed";
                repository.Update(item);

                item = repository.ById(item.Id);
                Assert.Equal("Changed", item.Title);
            }
        }