public async Task <IEnumerable <TestClassModel> > GetTestClassesAsync() { List <TestClassModel> classes = new List <TestClassModel>(); string sql = "select * from TestClassRef order by test_class_desc"; SqlCommand command = new SqlCommand(sql); command.Connection = _connection; _connection.Open(); var reader = await command.ExecuteReaderAsync(CommandBehavior.CloseConnection); DataTable table = new DataTable(); table.Load(reader); foreach (DataRow row in table.Rows) { TestClassModel testClass = new TestClassModel { Description = row["TEST_CLASS_DESC"].ToString(), TestClass = row["TESTCLASS"].ToString() }; classes.Add(testClass); } return(classes); }
/// <summary> /// Refresh testclasses /// </summary> /// <param name="sender"></param> public void RefreshTestClasses(Assembly sender) { IList <Tuple <ObjectId, string, int, bool> > testClasses = GetTestClassesData(sender); int count = mongoRepository.GetTestClassRepository.GetAll().Count(); //Add all test classes if count in collection is zero if (count == 0) { //Add new test classes AddTestClasses(testClasses); } else if (count != 0) { //Update the test classes IEnumerable <TestClassModel> updateTestClasses = testClasses. Select(tc => new TestClassModel() { Module_id = tc.Item1, TestClassName = tc.Item2, Order = tc.Item3, IsActive = tc.Item4, }); try { foreach (var testClass in updateTestClasses) { TestClassModel testclass = mongoRepository.GetTestClassRepository.GetByName(testClass.TestClassName); if (testclass != null) { if (testClass.Module_id.Equals(testclass.Module_id) || testClass.Order != testclass.Order || testClass.IsActive != testclass.IsActive) { mongoRepository.GetTestClassRepository.GetId(testClass.TestClassName); UpdateResult result = mongoRepository.GetTestClassRepository.Update(testClass); if (result.IsAcknowledged) { Logger.log.Debug("TestClass is updated Succesfully:" + testClass.TestClassName); } else { throw new MongoException("TestClass is not updated:" + testClass.TestClassName); } } } else if (testclass == null) { mongoRepository.GetTestClassRepository.Create(testClass); Logger.log.Debug("TestClass is created successfully:" + testClass.TestClassName); } } } catch (Exception ex) { Logger.log.Error(ex.Message); } } }