DataSet GetTopTwoDepartments() { DataSet ds = null; SQLDataLayer dl = null; try { dl = new SQLDataLayer(ResourceSettings.Instance.GetDBConnString()); dl.BeginTransaction(); ds = dl.ExecuteSQL("select top 2 Department_SID, Department from dbo.tb_Department;"); dl.Commit(); if (ds.Tables[0].Rows.Count <= 1) { throw new Exception("not enough departments to test with"); } } catch (Exception ex) { dl.Rollback(); ErrorOnThread = true; TestContext.WriteLine(string.Format("Exception: ", ex.Message)); } finally { dl.Dispose(); } return(ds); }
void UpdateDepartment(object p) { SQLDataLayer dl = null; UpdateDepartmentParams par = (UpdateDepartmentParams)p; try { dl = new SQLDataLayer(ResourceSettings.Instance.GetDBConnString()); dl.BeginTransaction(); DataSet ds = dl.ExecuteSP("dbo.sp_Department_Update", dl.CreateParam("piDepartmentSid", par.DepartmentSid), dl.CreateParam("piDepartment", par.DeptValue), dl.CreateParam("piIsIT", true), dl.CreateParam("piActive", true)); dl.Commit(); if ((int)ds.Tables[0].Rows[0]["RowsAffected"] > 0) { TestContext.WriteLine(string.Format("INSERTED for {0}{1}", par.DeptValue, par.ThreadNum)); } else { TestContext.WriteLine(string.Format("Already exists for {0}{1}", par.DeptValue, par.ThreadNum)); } } catch (Exception ex) { dl.Rollback(); ErrorOnThread = true; TestContext.WriteLine(string.Format("Exception for {0}:{1}", par.ThreadNum, ex.Message)); } finally { dl.Dispose(); } }
public SQLDataLayerTest() { _settings = new NameValueCollection(); _settings["ProjectName"] = "12345_000"; _settings["XmlPath"] = @"..\SQLDataLayer.NUnit\12345_000\"; _settings["ApplicationName"] = "SQL"; _settings["TestMode"] = "WriteFiles"; //UseFiles/WriteFiles _baseDirectory = Directory.GetCurrentDirectory(); _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\bin")); _settings["BaseDirectoryPath"] = _baseDirectory; Directory.SetCurrentDirectory(_baseDirectory); _adapterSettings = new AdapterSettings(); _adapterSettings.AppendSettings(_settings); string appSettingsPath = String.Format("{0}{1}.{2}.config", _adapterSettings["XmlPath"], _settings["ProjectName"], _settings["ApplicationName"] ); if (File.Exists(appSettingsPath)) { AppSettingsReader appSettings = new AppSettingsReader(appSettingsPath); _adapterSettings.AppendSettings(appSettings); } _dataLayer = new SQLDataLayer(_adapterSettings); }
public EmotionClient() { client = new EmoHttpClient(); DbLayer = new SQLDataLayer(); history = new OrderedDictionary(); aggHistory = new OrderedDictionary(); camHistory = new OrderedDictionary(); }
public async Task StartStopExecution() { IDataLayer dbAccess = new SQLDataLayer(_connection); int vHeight = 200; int vWidth = 200; string vName = "unitTestName"; VideoExecution ve = new VideoExecution() { Height = vHeight, Width = vWidth, FileName = vName }; int executionId = await dbAccess.WithDataLayerAsync <int>(async db => await db.GetExecutionContext(ve)); var query1 = @"SELECT * FROM [emo].[ExecutionInstance] WHERE Id = @exeId;"; this.Open(); using (var reader = await ExecuteReaderAsync(query1, false, "@exeId", executionId)) { if (reader.Read()) { var fname = reader["Filename"] as string; var fwidth = Convert.ToInt32(reader["Width"]); var fheight = Convert.ToInt32(reader["Height"]); Assert.AreEqual(fname, vName); Assert.AreEqual(vHeight, fheight); Assert.AreEqual(vWidth, fwidth); } } this.Close(); double scoreValue = 0.5; DateTime now = DateTime.UtcNow; EmotionScore score = new EmotionScore() { startTime = now, endTime = now, scores = new Scores() { anger = scoreValue, contempt = scoreValue, disgust = scoreValue, fear = scoreValue, happiness = scoreValue, neutral = scoreValue, sadness = scoreValue, surprise = scoreValue }, executionId = executionId, }; OrderedDictionary od = new OrderedDictionary(); od.Add(now, score); var finish = await dbAccess.WithDataLayerAsync <bool>(async db => await db.FinishExecution(od, executionId)); Assert.AreEqual(finish, true); var query2 = @"SELECT * FROM [emo].[EmotionScore] WHERE ExecutionId = @exeId ORDER BY TimeStamp ASC;"; this.Open(); using (var reader = await this.ExecuteReaderAsync(query2, false, "@exeId", executionId)) { if (reader.Read()) { var start = Convert.ToDateTime(reader["StartTime"]); var end = Convert.ToDateTime(reader["EndTime"]); var time = Convert.ToDateTime(reader["TimeStamp"]); var angerScore = Convert.ToDouble(reader["Anger"]); Assert.AreEqual(angerScore, scoreValue); } } this.Close(); }