public IMongoAdminTests() { using (var admin = new MongoAdmin(TestHelper.ConnectionString("strict=false"))) { admin.DropDatabase(); } }
public MongoDatabaseTest() { using (var admin = new MongoAdmin(_connectionString)) { admin.DropDatabase(); } }
public void Find_Subset_Returns_Appropriate_Subset() { using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { admin.SetProfileLevel(2); } using (var db = Mongo.Create(TestHelper.ConnectionString())) { var coll = db.GetCollection <TestProduct>(); coll.Delete(new { }); var oid = ObjectId.NewObjectId(); coll.Insert(new TestProduct { _id = oid, Price = 42.42f, Supplier = new Supplier { Name = "Bob's house of pancakes", RefNum = 12, CreatedOn = DateTime.MinValue } }); var subset = db.GetCollection <TestProduct>().Find(new { }, new { }, Int32.MaxValue, 0, j => new { SupplierName = j.Supplier.Name, Cost = j.Price, Id = j._id }).ToArray(); Assert.Equal("Bob's house of pancakes", subset[0].SupplierName); Assert.Equal(42.42f, subset[0].Cost); Assert.Equal(oid, subset[0].Id); } }
public void ReturnsBuildInfo() { string gitVersion; string version; using (var process = new Process()) { process.StartInfo = new ProcessStartInfo("mongod", "--version") { RedirectStandardOutput = true, UseShellExecute = false }; process.Start(); using (var stream = process.StandardOutput) { var data = stream.ReadToEnd(); gitVersion = Regex.Match(data, "git version: ([a-f0-9]+)\r\n").Groups[1].Value; version = Regex.Match(data, "db version v([^,]+),").Groups[1].Value; } } using (var admin = new MongoAdmin(TestHelper.ConnectionString(null, "admin", null, null))) { var info = admin.BuildInfo(); Assert.Equal(true, info.WasSuccessful); Assert.Equal(gitVersion, info.GitVersion); Assert.Equal(version, info.Version); } }
public void Get_CurrentOp_Returns() { using (var mAdmin = new MongoAdmin(TestHelper.ConnectionString())) { var currOps = mAdmin.GetCurrentOperations().ToArray(); } }
public MongoDatabaseTest() { using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { admin.DropDatabase(); } }
public void Reset_Last_Error_Returns() { using (var mAdmin = new MongoAdmin(TestHelper.ConnectionString())) { Assert.True(mAdmin.ResetLastError()); } }
public void Repair_Database_Returns() { using (var mAdmin = new MongoAdmin(TestHelper.ConnectionString())) { Assert.True(mAdmin.RepairDatabase(false, false)); } }
public MongoAdminTests() { using (var admin = new MongoAdmin(TestHelper.ConnectionString("strict=false"))) { admin.DropDatabase(); } }
public UpdateModifiersTests() { var admin = new MongoAdmin("mongodb://localhost/admin?pooling=false&strict=true"); _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false&strict=true"); _collection = _server.GetCollection<Post>("Posts"); _buildInfo = admin.BuildInfo(); }
public void GetsServerStatus() { using (var admin = new MongoAdmin(ConnectionString())) { var status = admin.ServerStatus(); } }
public void BuildInfoThrowsExceptionIfNotConnectedToAdmin() { using (var admin = new MongoAdmin(ConnectionString("temp"))) { var ex = Assert.Throws<MongoException>(() => admin.BuildInfo()); Assert.Equal("This command is only valid when connected to admin", ex.Message); } }
public UpdateModifiersTests() { var admin = new MongoAdmin("mongodb://localhost/admin?pooling=false&strict=true"); _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false&strict=true"); _collection = _server.GetCollection <Post>("Posts"); _buildInfo = admin.BuildInfo(); }
public void Get_CurrentOp_Returns_Results() { using (var mAdmin = new MongoAdmin(TestHelper.ConnectionString())) { var a = mAdmin.PreviousErrors(); Assert.Equal(true, a.WasSuccessful); } }
public void ListsAllDatabasesThrowsExceptionIfNotConnectedToAdmin() { using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { var ex = Assert.Throws <MongoException>(() => admin.GetAllDatabases()); Assert.Equal("This command is only valid when connected to admin", ex.Message); } }
public void ForceSyncThrowsExceptionIfNotConnectedToAdmin() { using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { var ex = Assert.Throws <MongoException>(() => admin.ForceSync(true)); Assert.Equal("This command is only valid when connected to admin", ex.Message); } }
public void GetsServerStatus() { using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { var status = admin.ServerStatus(); Assert.Equal(true, status.WasSuccessful); } }
public void ForceSyncThrowsExceptionIfNotConnectedToAdmin() { using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { var ex = Assert.Throws<MongoException>(() => admin.ForceSync(true)); Assert.Equal("This command is only valid when connected to admin", ex.Message); } }
public void ReturnsEmptyInProcessResponse() { using (var admin = new MongoAdmin(TestHelper.ConnectionString(null, "admin", null, null))) { var response = admin.GetCurrentOperations(); Assert.Equal(0, response.Count()); } }
public void Dispose() { _server.Database.DropCollection("CheeseClubContacts"); using (var admin = new MongoAdmin("mongodb://localhost/NormTests?pooling=false")) { admin.DropDatabase(); } _server.Dispose(); }
public void Dispose() { _server.Database.DropCollection("TestClasses"); using (var admin = new MongoAdmin(TestHelper.ConnectionString("pooling=false"))) { admin.DropDatabase(); } _server.Dispose(); }
public void Dispose() { _server.Database.DropCollection("TestClasses"); using (var admin = new MongoAdmin("mongodb://localhost/NoRMTests?pooling=false")) { admin.DropDatabase(); } _server.Dispose(); }
public void Dispose() { _server.Database.DropCollection("TestClasses"); using (var admin = new MongoAdmin("mongodb://localhost/NormTests?pooling=false")) { admin.DropDatabase(); } _server.Dispose(); }
public void Get_Assert_Info_Returns_Results() { using (var mAdmin = new MongoAdmin(TestHelper.ConnectionString())) { var aInfo = mAdmin.AssertionInfo(); Assert.NotNull(aInfo); Assert.Equal(true, aInfo.WasSuccessful); } }
public sealed override void Update() { if (String.IsNullOrEmpty(this.Script)) { throw new InvalidOperationException("MigrationBase.GenerateMigrationScript() method should not returns null or empty script"); } MongoAdmin.ExecuteScript(this.Database, this.Script); }
public void ForceSyncDoesSomethingOk() { using (var admin = new MongoAdmin(ConnectionString())) { var response = admin.ForceSync(true); Assert.Equal(1d, response.OK); Assert.Equal(2, response.NumFiles); //don't know what this is } }
public QueryTests() { var admin = new MongoAdmin("mongodb://localhost/admin?pooling=false&strict=true"); _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false"); _collection = _server.GetCollection<Person>("People"); _buildInfo = admin.BuildInfo(); //cause the collection to exist on the server by inserting, then deleting some things. _collection.Insert(new Person()); _collection.Delete(new { }); }
public void Kill_Operation_Returns() { //since we don't have any long-running ops, this is all we can test without mocks. using (var mAdmin = new MongoAdmin("mongodb://127.0.0.1/admin")) { var x = mAdmin.KillOperation(double.MaxValue); Assert.Equal(false, x.WasSuccessful); Assert.Equal("no op number field specified?", x["err"]); } }
public QueryTests() { var admin = new MongoAdmin("mongodb://localhost/admin?pooling=false&strict=true"); _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false"); _collection = _server.GetCollection <Person>("People"); _buildInfo = admin.BuildInfo(); //cause the collection to exist on the server by inserting, then deleting some things. _collection.Insert(new Person()); _collection.Delete(new { }); }
public void Set_Profile_Level_Changes_Profile_Level_And_Reports_Change() { using (var mAdmin = new MongoAdmin(TestHelper.ConnectionString())) { int prev; if (mAdmin.SetProfileLevel(2, out prev)) { mAdmin.SetProfileLevel(prev); } } }
public void Get_Current_Profile_Level() { using (var mAdmin = new MongoAdmin(TestHelper.ConnectionString())) { var level = mAdmin.GetProfileLevel(); if (level != 2d) { mAdmin.SetProfileLevel(2); } Assert.Equal(2, mAdmin.GetProfileLevel()); mAdmin.SetProfileLevel(level); } }
public MongoConfigurationTests() { MongoConfiguration.RemoveMapFor<User2>(); MongoConfiguration.RemoveMapFor<User>(); MongoConfiguration.RemoveMapFor<TestProduct>(); MongoConfiguration.RemoveMapFor<Shopper>(); MongoConfiguration.RemoveMapFor<Cart>(); MongoConfiguration.RemoveMapFor<TestProduct>(); using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { admin.DropDatabase(); } }
public MongoConfigurationTests() { MongoConfiguration.RemoveMapFor<User2>(); MongoConfiguration.RemoveMapFor<User>(); MongoConfiguration.RemoveMapFor<TestProduct>(); MongoConfiguration.RemoveMapFor<Shopper>(); MongoConfiguration.RemoveMapFor<Cart>(); MongoConfiguration.RemoveMapFor<TestProduct>(); MongoConfiguration.RemoveTypeConverterFor<NonSerializableValueObject>(); using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { admin.DropDatabase(); } }
public MongoConfigurationTests() { MongoConfiguration.RemoveMapFor <User2>(); MongoConfiguration.RemoveMapFor <User>(); MongoConfiguration.RemoveMapFor <TestProduct>(); MongoConfiguration.RemoveMapFor <Shopper>(); MongoConfiguration.RemoveMapFor <Cart>(); MongoConfiguration.RemoveMapFor <TestProduct>(); MongoConfiguration.RemoveTypeConverterFor <NonSerializableValueObject>(); using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { admin.DropDatabase(); } }
public async Task <IEnumerable <IScanInstanceModel> > GetListBy(IEnumerable <object> scanIds) { List <ScanInstance> ret = new List <ScanInstance>(); if (!scanIds.IsEmptyList()) { var filter = Builders <ScanInstance> .Filter.In(p => p.ScanId, System.Linq.Enumerable.Select(scanIds, p => (ObjectId)p)); var coll = MongoAdmin.GetCollection <ScanInstance>(this.Db.Database); var find = await coll.FindAsync(filter); ret.AddRange(await find.ToListAsync()); } return(ret); }
public void ForceSyncDoesSomethingOk() { using (var admin = new MongoAdmin(TestHelper.ConnectionString(null, "admin", null, null))) { if (!admin.BuildInfo().SystemInformation.ToLower().Contains("windows")) { var response = admin.ForceSync(true); Assert.Equal(1d, response.Ok); Assert.True(response.NumberOfFiles > 0); //don't know what this is } else { Assert.Throws(typeof(MongoException),()=> admin.ForceSync(true)); Console.WriteLine("FSync is not supported on windows version of MongoDB and will throw an exception."); } } }
public void ForceSyncDoesSomethingOk() { using (var admin = new MongoAdmin(TestHelper.ConnectionString(null, "admin", null, null))) { if (!admin.BuildInfo().SystemInformation.ToLower().Contains("windows")) { var response = admin.ForceSync(true); Assert.Equal(true, response.WasSuccessful); Assert.True(response.NumberOfFiles > 0); //don't know what this is } else { Assert.Throws(typeof(MongoException), () => admin.ForceSync(true)); Console.WriteLine("FSync is not supported on windows version of MongoDB and will throw an exception."); } } }
public GridFSTests() { //construct a random 10MB stream. Random r = new Random(DateTime.Now.Millisecond); for (int i = 0; i < 1024 * 1024 * 1.5; i++) { this._randomBytes.Write(BitConverter.GetBytes(r.NextDouble()), 0, 8); } this._randomBytes.Position = 0; this._randomByteHash = _hasher.ComputeHash(_randomBytes); this._randomBytes.Position = 0; this._db = Mongo.Create(TestHelper.ConnectionString()); using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { admin.DropDatabase(); } }
public DbContext(IConnectionStringProvider provider) { if (null == provider) { throw new ArgumentNullException("Please register ConnectionStringProvider using Startup.Register method"); } this.Database = MongoAdmin.GetDatabase(new MongoClient(provider.ConnectionString), provider.DatabaseName); this.MongoClient = this.Database.Client;//for all clients. this._scanPrerequisites = this.GetLazy <ScanPrerequisite>(); this._scanResources = this.GetLazy <ScanResource>(); this._scans = this.GetLazy <Scan>(); this._scanInstances = this.GetLazy <ScanInstance>(); this._nodes = this.GetLazy <Node>(); this._authes = this.GetLazy <Auth>(); this._scanSchedules = this.GetLazy <ScanSchedule>(); }
public static void Register(IConnectionStringProvider connectionStringProvider) { if (null == connectionStringProvider) { throw new ArgumentNullException(nameof(connectionStringProvider)); } ServiceCollection.AddSingleton(typeof(IConnectionStringProvider), connectionStringProvider.GetType()); ServiceCollection.AddTransient <DbContext, DbContext>(); MongoClientProxy.SetConnectionString(connectionStringProvider.ConnectionString); var _db = MongoAdmin.GetDatabase(MongoClientProxy.Instance, connectionStringProvider.DatabaseName); InitializeMigration(_db); }
public void Dispose() { try { _server.Database.DropCollection("CheeseClubContacts"); } catch (MongoException e) { if (e.Message != "ns not found") { throw; } } using (var admin = new MongoAdmin("mongodb://localhost/NormTests?pooling=false")) { admin.DropDatabase(); } _server.Dispose(); }
public void DropsDatabase() { //create another database using (var mongo = Mongo.ParseConnection(ConnectionString("temp"))) { mongo.GetCollection<FakeObject>().Insert(new FakeObject()); } using (var admin = new MongoAdmin(ConnectionString("temp"))) { admin.DropDatabase(); } using (var admin = new MongoAdmin(ConnectionString())) { foreach (var db in admin.GetAllDatabases()) { Assert.NotEqual("temp", db.Name); } } }
public void ListsAllDatabases() { var expected = new List<string> {"admin", "temp", "local"}; //create another database using (var mongo = Mongo.ParseConnection(ConnectionString("temp"))) { mongo.GetCollection<FakeObject>().Insert(new FakeObject()); } using (var admin = new MongoAdmin(ConnectionString())) { foreach (var db in admin.GetAllDatabases()) { Assert.Contains(db.Name, expected); expected.Remove(db.Name); } } Assert.Equal(0, expected.Count); }
public void DropsDatabase() { //create another database using (var mongo = Mongo.Create(TestHelper.ConnectionString())) { mongo.GetCollection<FakeObject>().Insert(new FakeObject()); } using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { admin.DropDatabase(); } using (var admin = new MongoAdmin(TestHelper.ConnectionString(null, "admin", null, null))) { foreach (var db in admin.GetAllDatabases()) { Assert.NotEqual("NormTests", db.Name); } } }
public void DropsDatabase() { //create another database using (var mongo = Mongo.Create(TestHelper.ConnectionString())) { mongo.GetCollection <FakeObject>().Insert(new FakeObject()); } using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { admin.DropDatabase(); } using (var admin = new MongoAdmin(TestHelper.ConnectionString(null, "admin", null, null))) { foreach (var db in admin.GetAllDatabases()) { Assert.NotEqual("NormTests", db.Name); } } }
public void Dispose() { try { _server.Database.DropCollection("CheeseClubContacts"); } catch(MongoException e) { if (e.Message != "ns not found") { throw; } } using (var admin = new MongoAdmin("mongodb://localhost/NormTests?pooling=false")) { admin.DropDatabase(); } _server.Dispose(); }
public void ListsAllDatabases() { var expected = new List <string> { "admin", "NormTests", "local" }; //create another database using (var mongo = Mongo.Create(TestHelper.ConnectionString())) { mongo.GetCollection <FakeObject>().Insert(new FakeObject()); } using (var admin = new MongoAdmin(TestHelper.ConnectionString(null, "admin", null, null))) { foreach (var db in admin.GetAllDatabases()) { expected.Remove(db.Name); } } Assert.Equal(0, expected.Count); }
public void ListsAllDatabasesThrowsExceptionIfNotConnectedToAdmin() { using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { var ex = Assert.Throws<MongoException>(() => admin.GetAllDatabases()); Assert.Equal("This command is only valid when connected to admin", ex.Message); } }
public void ReturnsBuildInfo() { string gitVersion; string version; using (var process = new Process()) { process.StartInfo = new ProcessStartInfo("mongod", "--version"){ RedirectStandardOutput = true, UseShellExecute = false}; process.Start(); using (var stream = process.StandardOutput) { var data = stream.ReadToEnd(); gitVersion = Regex.Match(data, "git version: ([a-f0-9]+)\r\n").Groups[1].Value; version = Regex.Match(data, "db version v([^,]+),").Groups[1].Value; } } using (var admin = new MongoAdmin(TestHelper.ConnectionString(null, "admin", null, null))) { var info = admin.BuildInfo(); Assert.Equal(1d, info.Ok); Assert.Equal(gitVersion, info.GitVersion); Assert.Equal(version, info.Version); } }
public void ListsAllDatabases() { var expected = new List<string> { "admin", "NormTests", "local" }; //create another database using (var mongo = Mongo.Create(TestHelper.ConnectionString())) { mongo.GetCollection<FakeObject>().Insert(new FakeObject()); } using (var admin = new MongoAdmin(TestHelper.ConnectionString(null, "admin", null, null))) { foreach (var db in admin.GetAllDatabases()) { expected.Remove(db.Name); } } Assert.Equal(0, expected.Count); }
public void Find_Subset_Returns_Appropriate_Subset() { using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { admin.SetProfileLevel(2); } using (var db = Mongo.Create(TestHelper.ConnectionString())) { var coll = db.GetCollection<TestProduct>(); coll.Delete(new { }); var oid = ObjectId.NewObjectId(); coll.Insert(new TestProduct { _id = oid, Price = 42.42f, Supplier = new Supplier { Name = "Bob's house of pancakes", RefNum = 12, CreatedOn = DateTime.MinValue } }); var subset = db.GetCollection<TestProduct>().Find(new { }, new { }, Int32.MaxValue, 0, j => new { SupplierName = j.Supplier.Name, Cost = j.Price, Id = j._id }).ToArray(); Assert.Equal("Bob's house of pancakes", subset[0].SupplierName); Assert.Equal(42.42f, subset[0].Cost); Assert.Equal(oid, subset[0].Id); } }