How to use ConnectionStringReader class of NBi.Testing package

Best NBi code snippet using NBi.Testing.ConnectionStringReader

ElasticsearchExecutionEngineTest.cs

Source: ElasticsearchExecutionEngineTest.cs Github

copy

Full Screen

...38 #endregion39 [Test]40 public void Execute_Documents_DataSetFilled()41 {42 ElasticsearchClient client = new ElasticsearchClientFactory().Instantiate(ConnectionStringReader.GetElasticsearch()) as ElasticsearchClient;43 var statement = Mock.Of<IQuery>(44 x => x.Statement == 45 @"GET bank/​_search" +46 @"{" +47 @" ""query"": {""match_all"": { }}"+48 @" , ""size"": 5" +49 @" , ""_source"": [""gender"", ""age"", ""balance""]" +50 @" , ""sort"" : [ { ""balance"" : {""order"" : ""desc""}}]" +51 @"}");52 ElasticsearchCommandOperation ElasticsearchQuery = new ElasticsearchCommandFactory().Instantiate(client, statement).Implementation as ElasticsearchCommandOperation;53 var engine = new ElasticsearchExecutionEngine((ElasticsearchClientOperation)(client.CreateNew()), ElasticsearchQuery);54 var ds = engine.Execute();55 Assert.That(ds.Tables, Has.Count.EqualTo(1));56 Assert.That(ds.Tables[0].Rows, Has.Count.EqualTo(5));57 Assert.That(ds.Tables[0].Columns, Has.Count.EqualTo(3));58 Assert.That(ds.Tables[0].Columns.Cast<DataColumn>().Select(x => x.ColumnName), Has.Member("gender"));59 Assert.That(ds.Tables[0].Columns.Cast<DataColumn>().Select(x => x.ColumnName), Has.Member("age"));60 Assert.That(ds.Tables[0].Columns.Cast<DataColumn>().Select(x => x.ColumnName), Has.Member("balance"));61 var genders = new List<object>();62 var ages = new List<object>();63 foreach (DataRow row in ds.Tables[0].Rows)64 for (int i = 0; i < ds.Tables[0].Columns.Count; i++)65 {66 if (row.Table.Columns[i].ColumnName == "gender")67 genders.Add(row.ItemArray[i]);68 else if (row.Table.Columns[i].ColumnName == "age")69 ages.Add(row.ItemArray[i]);70 }71 foreach (var expectedFirstName in new[] { "F", "M" })72 Assert.That(genders, Has.Member(expectedFirstName));73 foreach (var expectedAge in new object[] { 36, 25, 35, 40, 23 })74 Assert.That(ages, Has.Member(expectedAge));75 foreach (DataRow row in ds.Tables[0].Rows)76 Assert.That(row["balance"], Is.Not.Null.Or.Empty);77 }78 79 [Test]80 public void Execute_Aggregations_DataSetFilled()81 {82 ElasticsearchClient client = new ElasticsearchClientFactory().Instantiate(ConnectionStringReader.GetElasticsearch()) as ElasticsearchClient;83 var statement = Mock.Of<IQuery>(84 x => x.Statement ==85 @"GET /​bank/​_search" +86 @"{" +87 @" ""size"": 5,"+88 @" ""aggs"": {"+89 @" ""group_by_state"": {"+90 @" ""terms"": {"+91 @" ""field"": ""state.keyword""," +92 @" ""size"": 3," +93 @" ""order"": {" +94 @" ""average_balance"": ""desc""" +95 @" }"+96 @" },"+97 @" ""aggs"": {"+98 @" ""average_balance"": {"+99 @" ""avg"": {"+100 @" ""field"": ""balance"""+101 @" }" +102 @" }" +103 @" }" +104 @" }" +105 @" }" +106 @"}");107 ElasticsearchCommandOperation ElasticsearchQuery = new ElasticsearchCommandFactory().Instantiate(client, statement).Implementation as ElasticsearchCommandOperation;108 var engine = new ElasticsearchExecutionEngine((ElasticsearchClientOperation)(client.CreateNew()), ElasticsearchQuery);109 var ds = engine.Execute();110 Assert.That(ds.Tables, Has.Count.EqualTo(1));111 Assert.That(ds.Tables[0].Rows, Has.Count.EqualTo(3));112 Assert.That(ds.Tables[0].Columns, Has.Count.GreaterThanOrEqualTo(2));113 Assert.That(ds.Tables[0].Columns.Cast<DataColumn>().Select(x => x.ColumnName), Has.Member("key"));114 Assert.That(ds.Tables[0].Columns.Cast<DataColumn>().Select(x => x.ColumnName), Has.Member("average_balance"));115 var states = new List<object>();116 foreach (DataRow row in ds.Tables[0].Rows)117 for (int i = 0; i < ds.Tables[0].Columns.Count; i++)118 {119 if (row.Table.Columns[i].ColumnName == "key")120 states.Add(row.ItemArray[i]);121 }122 foreach (var expectedState in new[] { "WA", "AL", "RI" })123 Assert.That(states, Has.Member(expectedState));124 foreach (DataRow row in ds.Tables[0].Rows)125 Assert.That(row["average_balance"], Is.Positive);126 }127 /​/​[Test]128 /​/​public void Execute_Integer_ScalarReturned()129 /​/​{130 /​/​ ElasticsearchClient client = new ElasticsearchClientFactory().Instantiate(ConnectionStringReader.GetElasticsearch()) as ElasticsearchClient;131 /​/​ var statement = Mock.Of<IQuery>(x => x.Statement == "g.V().count()");132 /​/​ ElasticsearchCommandOperation ElasticsearchQuery = new ElasticsearchCommandFactory().Instantiate(client, statement).Implementation as ElasticsearchCommandOperation;133 /​/​ var engine = new ElasticsearchExecutionEngine((ElasticsearchClientOperation)(client.CreateNew()), ElasticsearchQuery);134 /​/​ var count = engine.ExecuteScalar();135 /​/​ Assert.That(count, Is.EqualTo(4));136 /​/​}137 /​/​[Test]138 /​/​public void Execute_String_ScalarReturned()139 /​/​{140 /​/​ ElasticsearchClient client = new ElasticsearchClientFactory().Instantiate(ConnectionStringReader.GetElasticsearch()) as ElasticsearchClient;141 /​/​ var statement = Mock.Of<IQuery>(x => x.Statement == "g.V().has('firstName','Mary').values('lastName')");142 /​/​ ElasticsearchCommandOperation ElasticsearchQuery = new ElasticsearchCommandFactory().Instantiate(client, statement).Implementation as ElasticsearchCommandOperation;143 /​/​ var engine = new ElasticsearchExecutionEngine((ElasticsearchClientOperation)(client.CreateNew()), ElasticsearchQuery);144 /​/​ var count = engine.ExecuteScalar();145 /​/​ Assert.That(count, Is.EqualTo("Andersen"));146 /​/​}147 /​/​[Test]148 /​/​public void Execute_NullString_ScalarReturned()149 /​/​{150 /​/​ ElasticsearchClient client = new ElasticsearchClientFactory().Instantiate(ConnectionStringReader.GetElasticsearch()) as ElasticsearchClient;151 /​/​ var statement = Mock.Of<IQuery>(x => x.Statement == "g.V().has('firstName','Thomas').values('lastName')");152 /​/​ ElasticsearchCommandOperation commandOperation = new ElasticsearchCommandFactory().Instantiate(client, statement).Implementation as ElasticsearchCommandOperation;153 /​/​ var engine = new ElasticsearchExecutionEngine((ElasticsearchClientOperation)(client.CreateNew()), commandOperation);154 /​/​ var count = engine.ExecuteScalar();155 /​/​ Assert.That(count, Is.Null);156 /​/​}157 /​/​[Test]158 /​/​public void Execute_ListOfString_ListReturned()159 /​/​{160 /​/​ ElasticsearchClient client = new ElasticsearchClientFactory().Instantiate(ConnectionStringReader.GetElasticsearch()) as ElasticsearchClient;161 /​/​ var statement = Mock.Of<IQuery>(x => x.Statement == "g.V().values('lastName')");162 /​/​ ElasticsearchCommandOperation ElasticsearchQuery = new ElasticsearchCommandFactory().Instantiate(client, statement).Implementation as ElasticsearchCommandOperation;163 /​/​ var engine = new ElasticsearchExecutionEngine((ElasticsearchClientOperation)(client.CreateNew()), ElasticsearchQuery);164 /​/​ var count = engine.ExecuteList<string>();165 /​/​ Assert.That(count, Has.Member("Andersen"));166 /​/​ Assert.That(count, Has.Member("Miller"));167 /​/​ Assert.That(count, Has.Member("Wakefield"));168 /​/​}169 }170}...

Full Screen

Full Screen

BulkLoadCommandTest.cs

Source: BulkLoadCommandTest.cs Github

copy

Full Screen

...63 [Test]64 public void Execute_LoadTemporaryTableBasedOnCSV_TableHasMoreData()65 {66 /​/​Create table67 CreateTemporaryTable("Temporary", ConnectionStringReader.GetLocalSqlClient());6869 /​/​Check how many elements are available in the table70 var before = CountElementsInTable("Temporary", ConnectionStringReader.GetLocalSqlClient());7172 /​/​Mock the commandXml73 var info = Mock.Of<ILoadCommand>(74 command => command.ConnectionString== ConnectionStringReader.GetLocalSqlClient()75 && command.TableName=="Temporary"76 && command.FileName == FileName77 );7879 /​/​Apply the test80 var cmd = new BulkLoadCommand(info);81 cmd.Execute();8283 /​/​Execute Query on temporary table to knwo the new count of elements84 var after = CountElementsInTable("Temporary", ConnectionStringReader.GetLocalSqlClient());8586 Assert.That(after, Is.GreaterThan(before));87 }8889 }90} ...

Full Screen

Full Screen

BatchRunnerSmoTest.cs

Source: BatchRunnerSmoTest.cs Github

copy

Full Screen

...30 [SetUp]31 public void EnsureLocalSqlServerRunning()32 {33 var startTag = @"(local)\";34 var start = ConnectionStringReader.GetLocalSqlClient().IndexOf(startTag) + startTag.Length;35 var end = ConnectionStringReader.GetLocalSqlClient().IndexOf(';', start);36 var serviceName = "MSSQL$" + ConnectionStringReader.GetLocalSqlClient().Substring(start, end - start);37 using (var service = new ServiceController(serviceName))38 {39 if (service.Status != ServiceControllerStatus.Running)40 Assert.Ignore("Local SQL Server not started.");41 }42 }43 [Test]44 public void Execute_Batch_TablesAreCreated()45 {46 /​/​Create table47 CleanTemporaryTable("TablexxxOne", ConnectionStringReader.GetLocalSqlClient());48 CleanTemporaryTable("TablexxxTwo", ConnectionStringReader.GetLocalSqlClient());49 /​/​Build the fullpath for the file to read50 var fileName = FileOnDisk.CreatePhysicalFile(BATCH_FILE, $"{GetType().Namespace}.Resources.{BATCH_FILE}");51 /​/​Apply the test52 var runner = new BatchRunnerSmo(fileName, ConnectionStringReader.GetLocalSqlClient());53 runner.Execute();54 var countTable = 0;55 using (var conn = new SqlConnection(ConnectionStringReader.GetLocalSqlClient()))56 {57 using (var cmd = new SqlCommand())58 {59 cmd.Connection = conn;60 conn.Open();61 cmd.CommandText = "select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = 'dbo' and TABLE_NAME like 'Tablexxx%'";62 countTable = (int)cmd.ExecuteScalar();63 }64 }65 Assert.That(countTable, Is.EqualTo(2));66 }67 }68}...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

How To Handle Dynamic Dropdowns In Selenium WebDriver With Java

Joseph, who has been working as a Quality Engineer, was assigned to perform web automation for the company’s website.

Test Optimization for Continuous Integration

“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.

What is Selenium Grid &#038; Advantages of Selenium Grid

Manual cross browser testing is neither efficient nor scalable as it will take ages to test on all permutations & combinations of browsers, operating systems, and their versions. Like every developer, I have also gone through that ‘I can do it all phase’. But if you are stuck validating your code changes over hundreds of browsers and OS combinations then your release window is going to look even shorter than it already is. This is why automated browser testing can be pivotal for modern-day release cycles as it speeds up the entire process of cross browser compatibility.

Two-phase Model-based Testing

Most test automation tools just do test execution automation. Without test design involved in the whole test automation process, the test cases remain ad hoc and detect only simple bugs. This solution is just automation without real testing. In addition, test execution automation is very inefficient.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run NBi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful