~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceElementTestFixture.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using ICSharpCode.SharpDevelop.Dom;
 
6
using ICSharpCode.WixBinding;
 
7
using NUnit.Framework;
 
8
using WixBinding.Tests.Utils;
 
9
 
 
10
namespace WixBinding.Tests.Gui
 
11
{
 
12
        [TestFixture]
 
13
        public class WixDocumentEditorReplaceElementTestFixture
 
14
        {
 
15
                MockTextEditor textEditor;
 
16
                DomRegion replacementRegion;
 
17
                WixDocumentEditor wixDocumentEditor;
 
18
                
 
19
                [SetUp]
 
20
                public void Init()
 
21
                {
 
22
                        textEditor = new MockTextEditor();
 
23
                        textEditor.Document.Text = GetWixXml();
 
24
                        
 
25
                        string replacementXml = 
 
26
                                "<NewElement>\r\n" +
 
27
                                "</NewElement>";
 
28
                        
 
29
                        wixDocumentEditor = new WixDocumentEditor(textEditor);
 
30
                        replacementRegion = wixDocumentEditor.ReplaceElement("TARGETDIR", "Directory", replacementXml);
 
31
                }
 
32
                
 
33
                string GetWixXml()
 
34
                {
 
35
                        return 
 
36
                                "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>\r\n" +
 
37
                                "\t<Product Name='Test' \r\n" +
 
38
                                "\t         Version='1.0' \r\n" +
 
39
                                "\t         Language='1013' \r\n" +
 
40
                                "\t         Manufacturer='#develop' \r\n" +
 
41
                                "\t         Id='????????-????-????-????-????????????'>\r\n" +
 
42
                                "\t\t<Package/>\r\n" +
 
43
                                "\t\t\t<Directory Id=\"TARGETDIR\" SourceName=\"SourceDir\">\r\n" +
 
44
                                "\t\t\t</Directory>\r\n" +
 
45
                                "\t</Product>\r\n" +
 
46
                                "</Wix>";
 
47
                }
 
48
                
 
49
                [Test]
 
50
                public void XmlIsUpdatedInTextEditor()
 
51
                {
 
52
                        string expectedXml =
 
53
                                "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>\r\n" +
 
54
                                "\t<Product Name='Test' \r\n" +
 
55
                                "\t         Version='1.0' \r\n" +
 
56
                                "\t         Language='1013' \r\n" +
 
57
                                "\t         Manufacturer='#develop' \r\n" +
 
58
                                "\t         Id='????????-????-????-????-????????????'>\r\n" +
 
59
                                "\t\t<Package/>\r\n" +
 
60
                                "\t\t\t<NewElement>\r\n" +
 
61
                                "\t\t\t</NewElement>\r\n" +
 
62
                                "\t</Product>\r\n" +
 
63
                                "</Wix>";
 
64
                        
 
65
                        Assert.AreEqual(expectedXml, textEditor.Document.Text);
 
66
                }
 
67
                
 
68
                [Test]
 
69
                public void ReplacementRegionIsNotEmpty()
 
70
                {
 
71
                        Assert.IsFalse(replacementRegion.IsEmpty);
 
72
                }
 
73
                
 
74
                [Test]
 
75
                public void ReplacingUnknownElementReturnsEmptyRegion()
 
76
                {
 
77
                        DomRegion region = wixDocumentEditor.ReplaceElement("TARGETDIR", "unknown-element", "<test/>");
 
78
                        Assert.IsTrue(region.IsEmpty);
 
79
                }
 
80
        }
 
81
}