public void TestTryFindFileUri() { //Arrange //The dyn file passed as parameter doesn't exists, so a different part in TryFindFile method will be executed string wspath = Path.Combine(TestDirectory, @"core\callsite\RebindingSingleDimension1.dyn"); var fileCommand = new DynamoModel.OpenFileCommand(wspath); CustomXmlDocument xmlDocument = new CustomXmlDocument(); //We set the URI to be fake so when it's split on TryFindFile it will execute a different code section xmlDocument.CustomBaseURL = "http://localhost/test"; XmlElement elemTest = xmlDocument.CreateElement("TestCommand"); //Act var command = new OpenFileCommandDerivedTest(wspath); command.SerializeCoreTest(elemTest); //Assert Assert.Throws <FileNotFoundException>(() => OpenFileCommand.DeserializeCore(elemTest)); }
public void TestTryFindFile() { //Arrange string wspath = Path.Combine(TestDirectory, @"core\callsite\RebindingSingleDimension.dyn"); var fileCommand = new DynamoModel.OpenFileCommand(wspath); //We need a XmlDocument instance to create a new custom XmlElement XmlDocument xmlDocument = new XmlDocument(); XmlElement elemTest = xmlDocument.CreateElement("TestCommand"); //Act var command = new OpenFileCommandDerivedTest(wspath); command.SerializeCoreTest(elemTest); var deserializedCommand = OpenFileCommand.DeserializeCore(elemTest); //We need to set up the DynamoModel inside the OpenFileCommandDerivedTest class before calling TrackAnalytics() command.ExecuteTest(CurrentDynamoModel); command.TrackAnalytics(); //Assert //It will validate that the Deserialized element is valid Assert.IsNotNull(deserializedCommand); }
/// <summary> /// Call this static method to reconstruct a RecordableCommand-derived /// object given an XmlElement that was previously saved with Serialize /// method. This method simply redirects the XmlElement to respective /// RecordableCommand-derived classes based on its type. /// </summary> /// <param name="element">The XmlElement from which the RecordableCommand /// can be reconstructed.</param> /// <returns>Returns the reconstructed RecordableCommand object. If a /// RecordableCommand cannot be reconstructed, this method throws a /// relevant exception.</returns> /// internal static RecordableCommand Deserialize(XmlElement element) { if (string.IsNullOrEmpty(element.Name)) { throw new ArgumentException("XmlElement without name"); } RecordableCommand command = null; switch (element.Name) { case "OpenFileCommand": command = OpenFileCommand.DeserializeCore(element); break; case "PausePlaybackCommand": command = PausePlaybackCommand.DeserializeCore(element); break; case "RunCancelCommand": command = RunCancelCommand.DeserializeCore(element); break; case "CreateNodeCommand": command = CreateNodeCommand.DeserializeCore(element); break; case "SelectModelCommand": command = SelectModelCommand.DeserializeCore(element); break; case "CreateNoteCommand": command = CreateNoteCommand.DeserializeCore(element); break; case "SelectInRegionCommand": command = SelectInRegionCommand.DeserializeCore(element); break; case "DragSelectionCommand": command = DragSelectionCommand.DeserializeCore(element); break; case "MakeConnectionCommand": command = MakeConnectionCommand.DeserializeCore(element); break; case "DeleteModelCommand": command = DeleteModelCommand.DeserializeCore(element); break; case "UndoRedoCommand": command = UndoRedoCommand.DeserializeCore(element); break; case "ModelEventCommand": command = ModelEventCommand.DeserializeCore(element); break; case "UpdateModelValueCommand": command = UpdateModelValueCommand.DeserializeCore(element); break; case "ConvertNodesToCodeCommand": command = ConvertNodesToCodeCommand.DeserializeCore(element); break; case "CreateCustomNodeCommand": command = CreateCustomNodeCommand.DeserializeCore(element); break; case "SwitchTabCommand": command = SwitchTabCommand.DeserializeCore(element); break; } if (null != command) { command.IsInPlaybackMode = true; command.Tag = element.GetAttribute("Tag"); return(command); } string message = string.Format("Unknown command: {0}", element.Name); throw new ArgumentException(message); }