public void TestMoleUnitChange() { MainPage mp1 = new MainPage(); Workspace w = mp1.GetLogicalWorkspace(); // Add a new stream with a table to the workspace ChemicalStream cs1 = new ChemicalStream(1); cs1.PropertiesTable = new StreamPropertiesTable(cs1); w.AddStream(cs1); // The DrawingCanvas control should have added a stream control ChemProV.PFD.Streams.StreamControl streamControl = mp1.WorkspaceReference.DrawingCanvasReference.GetStreamControl(cs1); Assert.IsNotNull(streamControl, "DrawingCanvas control did not correctly create a " + "stream control for a stream that was added to the workspace."); // From the stream control we can get the properties window control UI.StreamTableControl props = streamControl.Table; Assert.IsNotNull(props, "Stream control had a null table control."); // Add a default data row with label "M1" if it's not already there if (0 == cs1.PropertiesTable.RowCount) { ChemicalStreamData csd = cs1.PropertiesTable.AddNewRow() as ChemicalStreamData; csd.SelectedCompound = "Overall"; csd.Label = "M1"; csd.UserHasRenamed = false; } // Find the text box in the properties window with the text "M1" TextBox tbLabel = props.GetControl(cs1.PropertiesTable.Rows[0], "Label") as TextBox; Assert.IsNotNull(tbLabel, "Could not find text box for row label. If the code has changed " + "such that there is no longer a default row in chemical streams tables or the default " + "row has different units, then this test needs to be altered."); Assert.IsTrue(tbLabel.Text.Equals("M1"), "Default label was not M1"); // Find the combo box for the units ComboBox cbUnits = props.GetControl(cs1.PropertiesTable.Rows[0], "SelectedUnits") as ComboBox; Assert.IsNotNull(cbUnits, "Could not find combo box control for selected units"); // Select mole %, which should change the label from M1 to N1 cbUnits.SelectedItem = "mol %"; // Verify that the label changed to "N1" Assert.IsTrue(tbLabel.Text.Equals("N1"), "Test Failed: After unit change, the label " + "did not change from M1 to N1"); // What would be nice to add to this test in the future: // Change the text in tbLabel which simulates the user manually renaming the row. Change it to // something like "nn1". Then change the units again to something like fractions, which would // normally change 'n' to 'x', but shouldn't after a manual rename. }
private static void DeleteStreamWithUndo(ChemProV.PFD.Streams.StreamControl stream, DrawingCanvas canvas) { AbstractStream s = stream.Stream; // Special case: the old version (before I rewrote a bunch of logic) didn't let // you delete heat streams whose destination was a heat exchanger with utility. // I will keep this functionality. if (s is HeatStream && s.Destination is HeatExchangerWithUtility) { return; } // We need to build a list of undos List <IUndoRedoAction> actions = new List <IUndoRedoAction>(); if (null != s.Source) { // If the stream has a non-null source then we need to detach it and // make sure the undo would reattach it actions.Add(new Logic.Undos.AttachOutgoingStream(s.Source, s)); actions.Add(new Logic.Undos.SetStreamSource(s, s.Source, null, s.SourceLocation)); // Do the detachment so that the process unit (which is staying around) won't // have an outgoing stream that's been deleted s.Source.DetachOutgoingStream(s); s.Source = null; } if (null != s.Destination) { // If the stream has a non-null destination then we need to detach it and // make sure the undo would reattach it actions.Add(new Logic.Undos.AttachIncomingStream(s.Destination, s)); actions.Add(new Logic.Undos.SetStreamDestination(s, s.Destination, null, s.DestinationLocation)); // Do the detachment so that the process unit (which is staying around) won't // have an incoming stream that's been deleted s.Destination.DetachIncomingStream(s); s.Destination = null; } // In all cases we will need to add the stream back to the workspace actions.Add(new Logic.Undos.AddToWorkspace(stream.Stream)); // Delete the stream from the workspace. Event handlers will take care of updating the UI. canvas.GetWorkspace().RemoveStream(stream.Stream); // Add the undo that we built canvas.GetWorkspace().AddUndo( new UndoRedoCollection("Undo deletion of stream", actions.ToArray())); }