// [Test] public void CheckAddAndDeleteFoMongoCommandRepositoryUsingGuidAsId() { var mongoDatabase = CreateEmptyMongoDatabase(); var repository = new MongoDbRepository(mongoDatabase); var account = new MyGuidAccount("xyz"); repository.GetEntities<MyGuidAccount>(p => p.Name == account.Name).Any().ShouldEqual(false); repository.Add(account); repository.GetEntities<MyGuidAccount>(p => p.Name == account.Name).Any().ShouldEqual(true); repository.Delete(account); repository.GetEntities<MyGuidAccount>(p => p.Name == account.Name).Any().ShouldEqual(false); repository.Add(new MyGuidAccount("xyz")); }
// [Test] public void CheckAddAndDeleteFoMongoCommandRepositoryUsingGuidAsId() { var mongoDatabase = CreateEmptyMongoDatabase(); var repository = new MongoDbRepository(mongoDatabase); var account = new MyGuidAccount("xyz"); repository.GetEntities <MyGuidAccount>(p => p.Name == account.Name).Any().ShouldEqual(false); repository.Add(account); repository.GetEntities <MyGuidAccount>(p => p.Name == account.Name).Any().ShouldEqual(true); repository.Delete(account); repository.GetEntities <MyGuidAccount>(p => p.Name == account.Name).Any().ShouldEqual(false); repository.Add(new MyGuidAccount("xyz")); }
public void MongoRepository_Collection_Name_Attribute() { const string connectionString = "mongodb://127.0.0.1/test"; if (!MongoDbRepositoryManager.ServerIsRunning(connectionString)) { AssertIgnores.MongoServerIsNotRunning(); } var cli = new MongoClient(connectionString); cli.DropDatabase("test"); var repo = new MongoDbRepository <Order, string>(connectionString); // Create var create = new Order { Name = "Big sale" }; repo.Add(create); var repoExt = new MongoDbRepository <OrderExtension, string>(connectionString); // Create var create2 = new OrderExtension { Name = "Big sale" }; repoExt.Add(create2); Assert.IsTrue(cli.GetDatabase("test").ListCollections().ToList().Any(x => x["name"] == "Order")); Assert.IsTrue(cli.GetDatabase("test").ListCollections().ToList().Any(x => x["name"] == "OrderCustomName")); Assert.IsFalse(cli.GetDatabase("test").ListCollections().ToList().Any(x => x["name"] == "OrderExtended")); }
public async Task <MatchedProfile> MatchProfileAsync(string profileId) { var allProfiles = await _profilesAdapter.GetAsync <Profile[]>("api/profiles"); var results = new List <string>(); if (allProfiles != null) { var profileToMatch = allProfiles.FirstOrDefault(profile => profile.Id == profileId); if (profileToMatch == null) { throw new Exception($"Profile with id {profileId} does not exist"); } var toCheck = allProfiles.Except(new[] { profileToMatch }); foreach (var profile in toCheck) { if (profile.AcceptsProfile(profileToMatch)) { results.Add(profile.Id); } } } var matchedProfile = new MatchedProfile(profileId, results); _matchedProfilesRepository.Add(matchedProfile); return(matchedProfile); }
static void Main(string[] args) { var personBuilder = new PersonBuilder(); var person = personBuilder .Infos .MyNameIs("Raphael") .MyDocumentNumberIs("01234567890") .IWasBornIn(new DateTime(1991, 04, 30)) .Lives .At("Building build") .In("Santos") .Works .At("Avanade") .IsEmployed(true) .WithIncome(1000) .ToPerson(); var repository = new MongoDbRepository(); repository.Add(person); var personGet = repository.GetByName(person.Name); var listOfPeople = repository.GetAll(); person.Company = "New Company"; repository.Update(person); repository.Remove(personGet._id); }
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 CheckSaveInterceptor2() { var repository = new MongoDbRepository(CreateEmptyMongoDatabase()); //BsonDocument nested = new BsonDocument { //{ "name", "JJK" }, //{ "address", new BsonDocument { // { "street", "123 Main St." }, // { "city", "Centerville" }, // { "state", "PA" }, // { "zip", 12345} //}}}; var crappy = new SimpleAccount("JK2"); crappy.SimpleAccount2 = new SimpleAccount("XXX"); repository.Add(crappy); // Create Single Update!!!!!!!!!!!! var result3 = repository.ModifyAll <SimpleAccount>( new ExpressionSpecificationQueryStrategy <SimpleAccount>(p => p.Name == "JK2"), new MongoUpdateItem <SimpleAccount>(p => p.DOB, DateTime.Today.AddDays(77777)), new MongoUpdateItem <SimpleAccount>(p => p.SimpleAccount2.Name, "XCC"), new MongoUpdateItem <SimpleAccount>(p => p.SimpleAccount2.Weigth, 1236)); // Update.Set("DOB", DateTime.Today.AddDays(99999)); }
static async void Run() { var connectionString = "mongodb://localhost"; var dbName = "books"; var db = GetDatabase(connectionString, dbName); IRepository <Book> repo = new MongoDbRepository <Book>(db); var input = ReadInput(); var patrickRothfuss = new Author(input[2], input[3]); await repo.Add(new Book(input[0], input[1], patrickRothfuss)); (await repo.All()) .ToList() .ForEach(Console.WriteLine); //Deleting var first = (await repo.All()) .FirstOrDefault(); Console.WriteLine("Deleting {0}", first.Title); await repo.Delete(first); Console.WriteLine("{0} deleted", first.Title); Console.WriteLine("---------------"); (await repo.All()) .ToList() .ForEach(Console.WriteLine); }
static async void Run() { var connectionString = "mongodb://localhost"; var dbName = "books"; var db = GetDatabase(connectionString, dbName); IRepository<Book> repo = new MongoDbRepository<Book>(db); var input = ReadInput(); var patrickRothfuss = new Author(input[2], input[3]); await repo.Add(new Book(input[0], input[1], patrickRothfuss)); (await repo.All()) .ToList() .ForEach(Console.WriteLine); //Deleting var first = (await repo.All()) .FirstOrDefault(); Console.WriteLine("Deleting {0}", first.Title); await repo.Delete(first); Console.WriteLine("{0} deleted", first.Title); Console.WriteLine("---------------"); (await repo.All()) .ToList() .ForEach(Console.WriteLine); }
public async void Add_NewEntity_True() { var mongoDbRepository = new MongoDbRepository <Tweet>(_connectionString, _databaseName, _collectionName); var tweet = new Tweet { Content = "This is a tweet" }; mongoDbRepository.Add(tweet); var result = await _database.GetCollection <Tweet>(_collectionName).Find(x => x.Id == tweet.Id).SingleOrDefaultAsync(); Assert.True(result != null ? result.Id == tweet.Id : false); }
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(); }
// [Test] public void ModifyAll() { var mongoDatabase = CreateEmptyMongoDatabase(); var repository = new MongoDbRepository(mongoDatabase); repository.Add(new MySimpleAccount("xyz", DateTime.Today.AddDays(-1), 1) { Weigth = 1 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today.AddDays(-1), 2) { Weigth = 2 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today.AddDays(-1), 3) { Weigth = 3 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today, 4) { Weigth = 4 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today, 5) { Weigth = 5 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today, 6) { Weigth = 6 }); var lessThanTodayQuery = new ExpressionSpecificationQueryStrategy <MySimpleAccount>(p => p.DOB < DateTime.Today); repository.GetEntities <MySimpleAccount>(lessThanTodayQuery).Count().ShouldEqual(3); var result3 = repository.ModifyAll <MySimpleAccount>( lessThanTodayQuery, new MongoUpdateItem <MySimpleAccount>(p => p.DOB, DateTime.Today), new MongoUpdateItem <MySimpleAccount>(p => p.Weigth, 100)); result3.DocumentsAffected.ShouldEqual(3); repository.GetEntities <MySimpleAccount>(lessThanTodayQuery).Count().ShouldEqual(0); repository.GetEntities <MySimpleAccount>(p => p.DOB == DateTime.Today).Count().ShouldEqual(6); repository.GetEntities <MySimpleAccount>(p => p.Weigth == 100).Count().ShouldEqual(3); }
// [Test] public void Paging() { var mongoDatabase = CreateEmptyMongoDatabase(); var repository = new MongoDbRepository(mongoDatabase); repository.Add(new MySimpleAccount("xyz", DateTime.Today.AddDays(-1), 1) { Weigth = 1 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today.AddDays(-1), 2) { Weigth = 2 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today.AddDays(-1), 3) { Weigth = 3 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today, 4) { Weigth = 4 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today, 5) { Weigth = 5 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today, 6) { Weigth = 6 }); var rowCountFunc = default(Func <int>); var docs = repository.GetEntities <MySimpleAccount>(new PagingQueryStrategy(2, 2, out rowCountFunc)).ToList(); rowCountFunc().ShouldEqual(6); docs.Count().ShouldEqual(2); }
public void CheckSaveInterceptor2() { var repository = new MongoDbRepository(CreateEmptyMongoDatabase()); //BsonDocument nested = new BsonDocument { //{ "name", "JJK" }, //{ "address", new BsonDocument { // { "street", "123 Main St." }, // { "city", "Centerville" }, // { "state", "PA" }, // { "zip", 12345} //}}}; var crappy = new SimpleAccount("JK2"); crappy.SimpleAccount2 = new SimpleAccount("XXX"); repository.Add(crappy); // Create Single Update!!!!!!!!!!!! var result3 = repository.ModifyAll<SimpleAccount>( new ExpressionSpecificationQueryStrategy<SimpleAccount>(p => p.Name == "JK2"), new MongoUpdateItem<SimpleAccount>(p => p.DOB, DateTime.Today.AddDays(77777)), new MongoUpdateItem<SimpleAccount>(p => p.SimpleAccount2.Name, "XCC"), new MongoUpdateItem<SimpleAccount>(p => p.SimpleAccount2.Weigth, 1236)); // Update.Set("DOB", DateTime.Today.AddDays(99999)); }
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(); }
// [Test] public void Paging() { var mongoDatabase = CreateEmptyMongoDatabase(); var repository = new MongoDbRepository(mongoDatabase); repository.Add(new MySimpleAccount("xyz", DateTime.Today.AddDays(-1), 1) { Weigth = 1 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today.AddDays(-1), 2) { Weigth = 2 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today.AddDays(-1), 3) { Weigth = 3 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today, 4) { Weigth = 4 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today, 5) { Weigth = 5 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today, 6) { Weigth = 6 }); var rowCountFunc = default(Func<int>); var docs = repository.GetEntities<MySimpleAccount>(new PagingQueryStrategy(2, 2, out rowCountFunc)).ToList(); rowCountFunc().ShouldEqual(6); docs.Count().ShouldEqual(2); }
// This method copies the Customer objects with the orders attached to the Mongo db database private static void SetUpMongoDbData() { var mongoDb = GetMongoDatabase(); mongoDb.Drop(); mongoDb = GetMongoDatabase(); using (var efQueryRepository = new EntityFrameworkQueryRepository(new NRepository_NorthwindContext())) { // no proxy objects please var dbContext = (DbContext)efQueryRepository.ObjectContext; dbContext.Configuration.ProxyCreationEnabled = false; // load customers with orders attached var customers = efQueryRepository.GetEntities<Customer>( new EagerLoadingQueryStrategy<Customer>( p => p.Orders)).ToList(); // MongoDbRepository immediately calls the db when adding, modifying or deleting data. Use this implementation // to both set and get the concerns. (MongoDbUnitOfWorkRepository will only return the concerns after all the items have been saved ) using (IRepository mongoRepository = new MongoDbRepository(mongoDb)) { // Copy Ef data to mongo db customers.ForEach(customer => { //var result = mongoRepository.AddWithConcern(customer) mongoRepository.Add(customer); }); } } }
// [Test] public void ModifyAll() { var mongoDatabase = CreateEmptyMongoDatabase(); var repository = new MongoDbRepository(mongoDatabase); repository.Add(new MySimpleAccount("xyz", DateTime.Today.AddDays(-1), 1) { Weigth = 1 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today.AddDays(-1), 2) { Weigth = 2 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today.AddDays(-1), 3) { Weigth = 3 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today, 4) { Weigth = 4 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today, 5) { Weigth = 5 }); repository.Add(new MySimpleAccount("xyz", DateTime.Today, 6) { Weigth = 6 }); var lessThanTodayQuery = new ExpressionSpecificationQueryStrategy<MySimpleAccount>(p => p.DOB < DateTime.Today); repository.GetEntities<MySimpleAccount>(lessThanTodayQuery).Count().ShouldEqual(3); var result3 = repository.ModifyAll<MySimpleAccount>( lessThanTodayQuery, new MongoUpdateItem<MySimpleAccount>(p => p.DOB, DateTime.Today), new MongoUpdateItem<MySimpleAccount>(p => p.Weigth, 100)); result3.DocumentsAffected.ShouldEqual(3); repository.GetEntities<MySimpleAccount>(lessThanTodayQuery).Count().ShouldEqual(0); repository.GetEntities<MySimpleAccount>(p => p.DOB == DateTime.Today).Count().ShouldEqual(6); repository.GetEntities<MySimpleAccount>(p => p.Weigth == 100).Count().ShouldEqual(3); }