public void TestSqliteDbInterface() { //Run tests sequentially //These tests are run sequentially because they will be using the same disk file //The tests are not interdependent on each other; the disk file is overwritten with each new test OpenEmptyFile(); OpenInvalidFile(); TestCreateNewFile(); TestCreateProblemStatement(); TestCreateNewNode(); TestChangeNodeText(); TestAddLink(); TestRemoveLink(); TestRemoveFinalLink(); TestUndoRemoveFinalLink(); TestRemoveNode(); TestRemoveNodeChain(); TestMoveNodeCommand(); TestUndoMoveNodeCommand(); TestUndoRemoveNodeChain(); TestUndoRemoveNode(); TestRemoveTopLevel(); TestLoadFile(); TestOpenInUseFile(); SqliteDb.GetInstance().CloseConnection(); }
/*This is the model that is created by CreateComplexModelForText * * Problem * | * ------------- * | | * Node 1.1 Node 1.2 * | | * | ------------------------- * | | | | * |---Node 2.1 Node 2.2 Node 2.3 * | | | * | ------------- | * | | | | * |---Node 3.1 Node 3.2- */ private Dictionary <string, Node> CreateComplexModelForTest() { var db = SqliteDb.GetInstance(); Node problem = NodeFactory.CreateProblem("Problem", SequentialId.NewId()); db.InsertTopLevel(problem); Node node1_1 = new AddNodeCommand(db, problem, "Node 1.1", true).NewNode; Node node1_2 = new AddNodeCommand(db, problem, "Node 1.2", true).NewNode; Node node2_1 = new AddNodeCommand(db, node1_2, "Node 2.1", true).NewNode; Node node2_2 = new AddNodeCommand(db, node1_2, "Node 2.2", true).NewNode; Node node2_3 = new AddNodeCommand(db, node1_2, "Node 2.3", true).NewNode; Node node3_1 = new AddNodeCommand(db, node2_2, "Node 3.1", true).NewNode; Node node3_2 = new AddNodeCommand(db, node2_2, "Node 3.2", true).NewNode; new AddLinkCommand(db, node1_1, node2_1, true); new AddLinkCommand(db, node2_1, node3_1, true); new AddLinkCommand(db, node2_3, node3_2, true); return(new Dictionary <string, Node>() { { problem.Text, problem }, { node1_1.Text, node1_1 }, { node1_2.Text, node1_2 }, { node2_1.Text, node2_1 }, { node2_2.Text, node2_2 }, { node2_3.Text, node2_3 }, { node3_1.Text, node3_1 }, { node3_2.Text, node3_2 } }); }
private void TestCreateNewNode() { var command = CreateCommandForNewDb("Tester.rootcause"); var problem = NodeFactory.CreateProblem("Problem", SequentialId.NewId()); SqliteDb.GetInstance().InsertTopLevel(problem); var node = NodeFactory.CreateCause("Node 1", SequentialId.NewId()); SqliteDb.GetInstance().AddNode(problem, node); string sql = $"SELECT * FROM nodes WHERE nodeid = '{node.NodeId}'"; command.CommandText = sql; SQLiteDataReader reader = command.ExecuteReader(); reader.Read(); string newNodeText = reader["nodetext"].ToString(); reader.Close(); sql = $"SELECT count(*) AS result FROM hierarchy WHERE parentid = '{problem.NodeId}' AND childid = '{node.NodeId}';"; command.CommandText = sql; reader = command.ExecuteReader(); reader.Read(); string hierarchies = reader["result"].ToString(); reader.Close(); CleanUpCommand(command); Assert.AreEqual("Node 1", newNodeText); Assert.AreEqual("1", hierarchies); }
public void TestSingletonPattern() { SqliteDb db1 = SqliteDb.GetInstance(); SqliteDb db2 = SqliteDb.GetInstance(); Assert.ReferenceEquals(db1, db2); }
private SQLiteCommand CreateCommandForNewDb(string fileName) { string filePath = GetPath(fileName); var conn = SqliteDb.GetInstance().CreateNewFile(filePath); return(conn.CreateCommand()); }
public void CreateProblem(string text) { var newProblem = new CreateProblemContainer(SqliteDb.GetInstance(), text, true).Container; Problems.Add(newProblem); CurrentProblem = newProblem; }
private void TestRemoveNodeChain() { var command = CreateCommandForNewDb("Tester.rootcause"); Dictionary <string, Node> nodes = CreateComplexModelForTest(); SqliteDb.GetInstance().RemoveNodeChain(nodes["Node 1.2"]); var expectedLinks = new Node[3, 2] { { nodes["Problem"], nodes["Node 1.1"] }, { nodes["Node 1.1"], nodes["Node 2.1"] }, { nodes["Node 2.1"], nodes["Node 3.1"] } }; TestHierarchy(command, expectedLinks); var expectedNodes = new Node[4] { nodes["Problem"], nodes["Node 1.1"], nodes["Node 2.1"], nodes["Node 3.1"] }; TestNodes(command, expectedNodes); CleanUpCommand(command); }
private void TestCreateProblemStatement() { var command = CreateCommandForNewDb("Tester.rootcause"); var node = NodeFactory.CreateProblem("This is my problem", SequentialId.NewId()); SqliteDb.GetInstance().InsertTopLevel(node); string nodeId = node.NodeId.ToString(); string sql = $"SELECT count(*) AS result FROM toplevel WHERE nodeid = '{nodeId}'"; command.CommandText = sql; SQLiteDataReader reader = command.ExecuteReader(); reader.Read(); string toplevels = reader["result"].ToString(); reader.Close(); sql = $"SELECT * FROM nodes WHERE nodeid = '{nodeId}'"; command.CommandText = sql; reader = command.ExecuteReader(); reader.Read(); string topLevelId = reader["nodeid"].ToString(); string topLevelText = reader["nodetext"].ToString(); reader.Close(); CleanUpCommand(command); Assert.AreEqual("1", toplevels); Assert.AreEqual(nodeId, topLevelId); Assert.AreEqual("This is my problem", topLevelText); }
public bool OpenFile(string path) { CloseFile(); CheckForNetworkPath(path); SqliteDb.GetInstance().LoadFile(path).ToList().ForEach(Problems.Add); Path = path; IsFileOpen = true; NotifyFileChanged(); return(true); }
public void CloseFile() { SqliteDb.GetInstance().CloseConnection(); Path = string.Empty; IsFileOpen = false; Problems.Clear(); CurrentProblem = null; Graph = new Graphing.RootCauseGraph(); NotifyFileChanged(); }
private void OpenInvalidFile() { try { SqliteDb.GetInstance().LoadFile("InvalidFile.rootcause"); } catch (InvalidRootCauseFileException) { return; } }
public bool NewFile(string path) { CloseFile(); CheckForNetworkPath(path); var conn = SqliteDb.GetInstance().CreateNewFile(path); Path = path; IsFileOpen = (conn != null); NotifyFileChanged(); return(IsFileOpen); }
private void TestUndoRemoveNodeChain() { var command = CreateCommandForNewDb("Tester.rootcause"); Dictionary <string, Node> nodes = CreateComplexModelForTest(); SqliteDb.GetInstance().RemoveNodeChain(nodes["Node 1.2"]); SqliteDb.GetInstance().UndoRemoveNodeChain(nodes["Node 1.2"], new Node[1] { nodes["Problem"] }); VerifyDefaultComplexModel(command, nodes); CleanUpCommand(command); }
private void TestRemoveTopLevel() { var command = CreateCommandForNewDb("Tester.rootcause"); Dictionary <string, Node> nodes = CreateComplexModelForTest(); SqliteDb.GetInstance().RemoveTopLevel(nodes["Problem"]); var expectedLinks = new Node[0, 2] { }; TestHierarchy(command, expectedLinks); var expectedNodes = new Node[0] { }; TestNodes(command, expectedNodes); CleanUpCommand(command); }
public void DeleteProblem() { try { new RemoveNodeChainCommand(SqliteDb.GetInstance(), currentProblem.InitialProblem, true); } catch (System.Data.SQLite.SQLiteException) { ProcessConnectionLost(); } catch (Exception) { throw; } Problems.Remove(currentProblem); currentProblem = null; GenerateGraph(); }
private void TestLoadFile() { CreateCommandForNewDb("Tester.rootcause").Dispose(); CreateComplexModelForTest(); IEnumerable <ProblemContainer> problems = SqliteDb.GetInstance().LoadFile(GetPath("Tester.rootcause")); HashSet <string> links = new HashSet <string>(); Func <HashSet <string>, Node, int> fillLinks = null; fillLinks = (HashSet <string> listOfLinks, Node parent) => { int linkCount = 0; foreach (var child in parent.ChildNodes) { if (listOfLinks.Add($"{parent.Text} links to {child.Text}")) { linkCount++; } linkCount = linkCount + fillLinks(listOfLinks, child); } return(linkCount); }; int totalLinks = 0; foreach (var problem in problems) { totalLinks = fillLinks(links, problem.InitialProblem); } Assert.AreEqual(10, totalLinks); Assert.IsTrue(links.Contains("Problem links to Node 1.1")); Assert.IsTrue(links.Contains("Problem links to Node 1.2")); Assert.IsTrue(links.Contains("Node 1.1 links to Node 2.1")); Assert.IsTrue(links.Contains("Node 1.2 links to Node 2.1")); Assert.IsTrue(links.Contains("Node 1.2 links to Node 2.2")); Assert.IsTrue(links.Contains("Node 1.2 links to Node 2.3")); Assert.IsTrue(links.Contains("Node 2.1 links to Node 3.1")); Assert.IsTrue(links.Contains("Node 2.2 links to Node 3.1")); Assert.IsTrue(links.Contains("Node 2.2 links to Node 3.2")); Assert.IsTrue(links.Contains("Node 2.3 links to Node 3.2")); }
private void TestChangeNodeText() { var command = CreateCommandForNewDb("Tester.rootcause"); var problem = NodeFactory.CreateProblem("Problem", SequentialId.NewId()); SqliteDb.GetInstance().InsertTopLevel(problem); SqliteDb.GetInstance().ChangeNodeText(problem, "This is my problem"); string sql = $"SELECT * FROM nodes WHERE nodeid = '{problem.NodeId}';"; command.CommandText = sql; SQLiteDataReader reader = command.ExecuteReader(); reader.Read(); string newText = reader["nodetext"].ToString(); reader.Close(); CleanUpCommand(command); Assert.AreEqual("This is my problem", newText); }
private void TestRemoveLink() { var command = CreateCommandForNewDb("Tester.rootcause"); var problem = NodeFactory.CreateProblem("Problem", SequentialId.NewId()); var node1 = NodeFactory.CreateCause("Node 1", SequentialId.NewId()); var node2 = NodeFactory.CreateCause("Node 2", SequentialId.NewId()); SqliteDb.GetInstance().InsertTopLevel(problem); SqliteDb.GetInstance().AddNode(problem, node1); SqliteDb.GetInstance().AddNode(node1, node2); SqliteDb.GetInstance().AddLink(problem, node2); SqliteDb.GetInstance().RemoveLink(problem, node2); var expectedLinks = new Node[2, 2] { { problem, node1 }, { node1, node2 } }; TestHierarchy(command, expectedLinks); CleanUpCommand(command); }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { SqliteDb.GetInstance().CloseConnection(); }
public void CreateChildNode(string text, Node parent) { ExecuteCommand(new AddNodeCommand(SqliteDb.GetInstance(), parent, text)); }
public void EditNodeText(string text, Node parent) { ExecuteCommand(new ChangeNodeTextCommand(SqliteDb.GetInstance(), parent, text)); }
public void DeleteCauseChain(Node node) { ExecuteCommand(new RemoveNodeChainCommand(SqliteDb.GetInstance(), node)); }
public void RemoveLink(Node parent, Node child) { ExecuteCommand(new RemoveLinkCommand(SqliteDb.GetInstance(), parent, child)); }