public void CanSelectThenInsert() { String key = "test"; String value = TestUtil.NextString(); var dbConn = ConnectionFactory.Create(); var item = TestUtil.MakeWorkItem(dbConn); Assert.AreNotEqual(item, null); // there should be no data (aka key value pairs) now: var list = WorkItemData.SelectAll(dbConn, item.Id); Assert.AreNotEqual(list, null); // ensure SelectAll returns empty list, not null Assert.AreEqual(list.Count, 0); // now put one key/value pair in: var inserted = WorkItemData.Insert(dbConn, item, key, value); var selected = WorkItemData.SelectAll(dbConn, item.Id); Assert.AreNotEqual(selected, null); // ensure SelectAll returns empty list, not null Assert.AreEqual(selected.Count, 1); Assert.GreaterOrEqual(inserted.Id, 1); Assert.AreEqual(inserted.Id, selected[0].Id); Assert.AreEqual(inserted.WorkItemId, selected[0].WorkItemId); Assert.AreEqual(inserted.VariableName, selected[0].VariableName); Assert.AreEqual(inserted.VariableName, key); Assert.AreEqual(inserted.VariableValue, selected[0].VariableValue); }
public void FinishItem(WorkItemInfo toBeFinished) { IDbTransaction transaction = null; try { transaction = dbConn_.BeginTransaction(); var item = WorkItem.Select(dbConn_, toBeFinished.Id); if (item == null) { var msg = new StringBuilder(); msg.Append("cannot finish item ["); msg.Append(item.Name); msg.Append("], #"); msg.Append(item.Id); msg.Append("; not found in database"); throw new Exception(msg.ToString()); } var currentStep = Step.Select(dbConn_, item.StepId); if (currentStep == null) { throw new Exception("internal error, no such current step on " + item.ToString()); } var calc = new RuleCalculator(); var nextStep = calc.FindNextStep(dbConn_, toBeFinished, currentStep); if (nextStep == null) { // RuleCalculator enforces that this is a // terminating step, that there is no next step // etc. So we're clear to just delete the item // here: item.Delete(dbConn_); } else { item.StepId = nextStep.Id; item.ItemState = WorkItemState.Available; item.Entered = DateTime.UtcNow; item.SessionId = session_.Id; item.Priority = toBeFinished.Priority; item.Name = toBeFinished.Name; item.Update(dbConn_); WorkItemData.DeleteAll(dbConn_, item.Id); WorkItemData.Insert(dbConn_, item, toBeFinished); } transaction.Commit(); transaction = null; } finally { DbUtil.ReallyBackout(transaction); } }
public void CanInsert() { var dbConn = ConnectionFactory.Create(); var item = TestUtil.MakeWorkItem(dbConn); int before = TestUtil.SelectCount(dbConn, WorkItemData.TABLE); WorkItemData.Insert(dbConn, item, "variable0", TestUtil.NextString()); int after = TestUtil.SelectCount(dbConn, WorkItemData.TABLE); Assert.AreEqual(before + 1, after); }
public void CreateItem(String mapName , String itemName , String stepName , IKeyValuePairs data , int priority = 0 ) { IDbTransaction transaction = null; try { transaction = dbConn_.BeginTransaction(); var map = Map.Select(dbConn_, mapName); if (map == null) { var msg = new StringBuilder(); msg.Append("No such map ["); msg.Append(mapName); msg.Append("]"); throw new Exception(msg.ToString()); } var step = Step.Select(dbConn_, stepName, map.Id); if (step == null) { var msg = new StringBuilder(); msg.Append("No such step ["); msg.Append(stepName); msg.Append("] in map ["); msg.Append(map.Name); msg.Append("]"); throw new Exception(msg.ToString()); } if (step.Type != Step.StepType.Start) { var msg = new StringBuilder(); msg.Append("One may only CreateItem() on start steps. "); msg.Append("["); msg.Append(step.Name); msg.Append("] is type ["); msg.Append(step.Type); msg.Append("]"); throw new Exception(msg.ToString()); } if (map.Id != step.MapId) { var msg = new StringBuilder(); msg.Append("Step ["); msg.Append(stepName); msg.Append("] is in map #"); msg.Append(step.MapId); msg.Append(", not #"); msg.Append(map.Id); // TODO: look up correct map name and report it here throw new Exception(msg.ToString()); } var item = WorkItem.Insert(dbConn_ , step , itemName , priority , session_ ); if (data != null) { foreach (String key in data.Keys) { var kvp = WorkItemData.Insert(dbConn_, item, key, data[key]); } } transaction.Commit(); transaction = null; } finally { DbUtil.ReallyClose(transaction); } }