public void MongoRepository_Generate_Query_With_AllowDiskSave() { const string connectionString = "mongodb://127.0.0.1/test"; if (!MongoDbRepositoryManager.ServerIsRunning(connectionString)) { AssertIgnores.MongoServerIsNotRunning(); } var repo = new MongoDbRepository <Order, string>(connectionString); // Create var create = new Order { Name = "Big sale" }; repo.Add(create); var fetchStrategy = new MongoDbFetchStrategy <Order> { AllowDiskUse = true }; // Read var read = repo.Get(create.OrderId, fetchStrategy); read.Name.ShouldBe(create.Name); var all = repo.GetAll(fetchStrategy); var all2 = repo.AsQueryable(fetchStrategy); }
public void Get() { MongoDbRepository <User> userRepository = new MongoDbRepository <User>(); var user = userRepository.Get(x => x.Email == "*****@*****.**"); Assert.IsNotNull(user); }
public void Delete() { User usr = new User() { Email = "*****@*****.**", Password = "******" }; MongoDbRepository <User> userRepository = new MongoDbRepository <User>(); User result = userRepository.Insert(usr); var deletedUser = userRepository.Get(x => x.Email == usr.Email); userRepository.Delete(deletedUser); var user = userRepository.Get(x => x.Email == usr.Email); Assert.IsNull(user); }
public void MongoRepository_Supports_Basic_Crud_Operations() { const string connectionString = "mongodb://127.0.0.1/test"; if (!MongoDbRepositoryManager.ServerIsRunning(connectionString)) { AssertIgnores.MongoServerIsNotRunning(); } var repo = new MongoDbRepository <Order, string>(connectionString); // Create var create = new Order { Name = "Big sale" }; repo.Add(create); // Read var read = repo.Get(create.OrderId); read.Name.ShouldBe(create.Name); // Update read.Name = "Really big sale"; repo.Update(read); var all = repo.GetAll(); var update = repo.Get(read.OrderId); update.OrderId.ShouldBe(read.OrderId); update.Name.ShouldBe(read.Name); // Delete repo.Delete(update); var delete = repo.Get(read.OrderId); delete.ShouldBeNull(); }
public async void Get_NewEntity_True() { var mongoDbRepository = new MongoDbRepository <Tweet>(_connectionString, _databaseName, _collectionName); var tweet = new Tweet { Content = "This is a tweet" }; await _database.GetCollection <Tweet>(_collectionName).InsertOneAsync(tweet); var result = await mongoDbRepository.Get(tweet.Id); Assert.True(result != null ? result.Id == tweet.Id : false); }
public async Task Run() { //Given const string databaseName = "DATABASE_NAME"; const string clusterConnectionString = "CLUSTER_CONNECTION_STRING"; const string node1ConnectionString = "NODE_1_CONNECTION_STRING"; const string node2ConnectionString = "NODE_2_CONNECTION_STRING"; var clusterDatabaseRepository = new MongoDbRepository(clusterConnectionString, databaseName); var node1DatabaseRepository = new MongoDbRepository(node1ConnectionString, databaseName); var node2DatabaseRepository = new MongoDbRepository(node2ConnectionString, databaseName); var collectionName = Guid.NewGuid().ToString(); var objectId = Guid.NewGuid(); var model = new MyModel { Id = objectId }; //When, Then try { var result = await clusterDatabaseRepository.Upsert(model, collectionName); Assert.IsTrue(result); var resultNode1 = await node1DatabaseRepository.Get <MyModel>(model.Id, collectionName); Assert.IsNotNull(resultNode1); Assert.IsTrue(resultNode1.Id == model.Id); var resultNode2 = await node2DatabaseRepository.Get <MyModel>(model.Id, collectionName); Assert.IsNotNull(resultNode2); Assert.IsTrue(resultNode2.Id == model.Id); } finally { clusterDatabaseRepository.DeleteCollection(collectionName); } }
public async void GetRecentlyAdded_NewEntites_True() { var mongoDbRepository = new MongoDbRepository <Tweet>(_connectionString, _databaseName, _collectionName); var tweets = new List <Tweet>() { new Tweet { Content = "This is a tweet" }, new Tweet { Content = "This is another tweet" } }; await _database.GetCollection <Tweet>(_collectionName).InsertManyAsync(tweets); var all = await _database.GetCollection <Tweet>(_collectionName).Find(FilterDefinition <Tweet> .Empty).ToListAsync(); var result = await mongoDbRepository.Get(); Assert.Equal <RootEntity>(all, result, new RootEntityComparer()); }
public void MongoRepository_Supports_Basic_Crud_Operations() { const string connectionString = "mongodb://127.0.0.1"; if (!MongoDbRepositoryManager.ServerIsRunning(connectionString)) { AssertIgnores.MongoServerIsNotRunning(); } var repo = new MongoDbRepository<Order, string>(connectionString); // Create var create = new Order { Name = "Big sale" }; repo.Add(create); // Read var read = repo.Get(create.OrderId); read.Name.ShouldEqual(create.Name); // Update read.Name = "Really big sale"; repo.Update(read); var all = repo.GetAll(); var update = repo.Get(read.OrderId); update.OrderId.ShouldEqual(read.OrderId); update.Name.ShouldEqual(read.Name); // Delete repo.Delete(update); var delete = repo.Get(read.OrderId); delete.ShouldBeNull(); }
public MyAggregateRoot Get(Guid id) { return(_mongoRepository.Get(id)); }