// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team // // Permission is hereby granted, free of charge, to any person obtaining a copy of this // software and associated documentation files (the "Software"), to deal in the Software // without restriction, including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons // to whom the Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or // substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. using System; using System.Diagnostics; using System.IO; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; using System.Xml; using ICSharpCode.WpfDesign.Designer; using ICSharpCode.WpfDesign.Designer.Services; using ICSharpCode.WpfDesign.Designer.Xaml; using NUnit.Framework; namespace ICSharpCode.WpfDesign.Tests.Designer { [TestFixture] public class ModelTests : ModelTestHelper { [Test] public void SetButtonWidth() { DesignItem button = CreateCanvasContext(""); button.Properties["Width"].SetValue(100.0); AssertCanvasDesignerOutput("", button.Context); AssertLog(""); } [Test] public void UndoRedoTest() { DesignItem button = CreateCanvasContext(""; } else { expectedXamlWithList = @""; } DesignItem exampleClassItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass()); exampleClassItem.Properties["StringProp"].SetValue("String value"); otherListProp.CollectionElements.Add(exampleClassItem); button.Properties["Tag"].SetValue(containerItem); g.Commit(); } Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXamlWithList, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); otherListProp = button.Properties["Tag"].Value.Properties["OtherList"]; Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList)otherListProp.ValueOnInstance).Count == otherListProp.CollectionElements.Count); s.Undo(); Assert.IsFalse(s.CanUndo); Assert.IsTrue(s.CanRedo); AssertCanvasDesignerOutput("", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); s.Redo(); Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXamlWithList, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); otherListProp = button.Properties["Tag"].Value.Properties["OtherList"]; Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList)otherListProp.ValueOnInstance).Count == otherListProp.CollectionElements.Count); AssertLog(""); } [Test] public void UndoRedoImplicitDictionary() { UndoRedoDictionaryInternal(false); } [Test] public void UndoRedoExplicitDictionary() { UndoRedoDictionaryInternal(true); } void UndoRedoDictionaryInternal(bool useExplicitDictionary) { DesignItem button = CreateCanvasContext(""; } else { expectedXamlWithDictionary = @""; } DesignItem exampleClassItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass()); exampleClassItem.Key = "testKey"; exampleClassItem.Properties["StringProp"].SetValue("String value"); dictionaryProp.CollectionElements.Add(exampleClassItem); button.Properties["Tag"].SetValue(containerItem); g.Commit(); } Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXamlWithDictionary, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); dictionaryProp = button.Properties["Tag"].Value.Properties["Dictionary"]; Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary)dictionaryProp.ValueOnInstance).Count == dictionaryProp.CollectionElements.Count); s.Undo(); Assert.IsFalse(s.CanUndo); Assert.IsTrue(s.CanRedo); AssertCanvasDesignerOutput("", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); s.Redo(); Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXamlWithDictionary, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); dictionaryProp = button.Properties["Tag"].Value.Properties["Dictionary"]; Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary)dictionaryProp.ValueOnInstance).Count == dictionaryProp.CollectionElements.Count); AssertLog(""); } [Test] public void AddTextBoxToCanvas() { DesignItem button = CreateCanvasContext("", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); AssertLog(""); } [Test] public void ClearExplicitDictionary() { DesignItem button = CreateCanvasContext("", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); AssertLog(""); } [Test] public void AddMultiBindingToTextBox() { DesignItem button = CreateCanvasContext("