public void TestRecordableCommandDeserialize() { //Arrange var numberNode1 = new DoubleInput(); numberNode1.Value = "1"; var numberNode2 = new DoubleInput(); numberNode2.Value = "2"; DynamoSelection.Instance.ClearSelection(); //create the first state with the numbers selected DynamoSelection.Instance.Selection.Add(numberNode1); DynamoSelection.Instance.Selection.Add(numberNode2); var ids = DynamoSelection.Instance.Selection.OfType <NodeModel>().Select(x => x.GUID).ToList(); var AddPresetCommand = new DynamoModel.AddPresetCommand("PresetName", "Description", ids); // Serialize the command into an XmlElement. XmlDocument xmlDocument = new XmlDocument(); XmlElement elementAddPresetCommand = AddPresetCommand.Serialize(xmlDocument); var jsonAddPresetCommand = AddPresetCommand.Serialize(); var helper = new XmlElementHelper(elementAddPresetCommand); Guid gWorkspace = Guid.NewGuid(); Guid gState = Guid.NewGuid(); var ApplyPresetCommand = new DynamoModel.ApplyPresetCommand(gWorkspace, gState); //This will execute the empty method TrackAnalytics() ApplyPresetCommand.TrackAnalytics(); XmlElement elementApplyPresetCommand = ApplyPresetCommand.Serialize(xmlDocument); //Act // Deserialized the XmlElement into a new instance of the command. var deserializedAddPresetCommand = DynamoModel.RecordableCommand.Deserialize(elementAddPresetCommand); var deserializedApplyPresetCommand = DynamoModel.RecordableCommand.Deserialize(elementApplyPresetCommand); //This will execute the overloaded Deserialize method (the one receiving a string as parameter) var deserializedFromJson = DynamoModel.RecordableCommand.Deserialize(jsonAddPresetCommand); //This will generate a invalid json string, so when it's deserialized will raise an exception jsonAddPresetCommand = jsonAddPresetCommand.Replace('{', '<'); //This is a fake command so when it's deserialized will raise an exception XmlElement elemTest = xmlDocument.CreateElement("TestCommand"); Assert.Throws <ArgumentException>(() => DynamoModel.RecordableCommand.Deserialize(elemTest)); //Assert //This will check that the Deserialized commands are valid Assert.IsNotNull(deserializedAddPresetCommand); Assert.IsNotNull(deserializedApplyPresetCommand); Assert.IsNotNull(deserializedFromJson); Assert.Throws <ApplicationException>(() => DynamoModel.RecordableCommand.Deserialize(jsonAddPresetCommand)); }
public void ApplyPresetCommand_ExecuteCore() { //Arrange XmlDocument xmlDocument = new XmlDocument(); Guid stateGuid = Guid.NewGuid(); //Act var AddPresetCommand = new DynamoModel.ApplyPresetCommand(CurrentDynamoModel.CurrentWorkspace.Guid, stateGuid); AddPresetCommand.Execute(CurrentDynamoModel); var xmlElementPreset = AddPresetCommand.Serialize(xmlDocument); //Assert //Just checking that the xmlelement created with the Serialize method was successfull Assert.IsNotNull(xmlElementPreset); Assert.AreEqual(xmlElementPreset.GetAttribute("WorkspaceID"), CurrentDynamoModel.CurrentWorkspace.Guid.ToString()); }