~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/WixBinding/Test/Utils/WixBindingTestsHelper.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 System.ComponentModel;
 
6
using System.IO;
 
7
using System.Resources;
 
8
 
 
9
using ICSharpCode.Core;
 
10
using ICSharpCode.SharpDevelop.Internal.Templates;
 
11
using ICSharpCode.SharpDevelop.Project;
 
12
using ICSharpCode.WixBinding;
 
13
 
 
14
namespace WixBinding.Tests.Utils
 
15
{
 
16
        /// <summary>
 
17
        /// Helper class for WixBinding tests.
 
18
        /// </summary>
 
19
        public class WixBindingTestsHelper
 
20
        {
 
21
                class DummyWixProject : WixProject
 
22
                {
 
23
                        public DummyWixProject(ProjectCreateInformation info) : base (info)
 
24
                        {
 
25
                        }
 
26
                        
 
27
                        public override bool ReadOnly {
 
28
                                get { return false; }
 
29
                        }
 
30
                }
 
31
                
 
32
                WixBindingTestsHelper()
 
33
                {
 
34
                }
 
35
                
 
36
                /// <summary>
 
37
                /// Creates a WixProject that contains no WixObject or WixLibrary items.
 
38
                /// </summary>
 
39
                public static WixProject CreateEmptyWixProject()
 
40
                {
 
41
                        // Make sure the MSBuildEngine is initialised correctly.
 
42
                        InitMSBuildEngine();
 
43
                        
 
44
                        // create the project.
 
45
                        ProjectCreateInformation info = new ProjectCreateInformation();
 
46
                        info.Solution = new Solution(new MockProjectChangeWatcher());
 
47
                        info.ProjectName = "Test";
 
48
                        info.OutputProjectFileName = @"C:\Projects\Test\Test.wixproj";
 
49
 
 
50
                        return new DummyWixProject(info);
 
51
                }
 
52
                
 
53
                /// <summary>
 
54
                /// Returns the EditorAttribute in the AttributeCollection.
 
55
                /// </summary>
 
56
                public static EditorAttribute GetEditorAttribute(AttributeCollection attributes)
 
57
                {
 
58
                        foreach (Attribute attribute in attributes) {
 
59
                                EditorAttribute editorAttribute = attribute as EditorAttribute;
 
60
                                if (editorAttribute != null) {
 
61
                                        return editorAttribute;
 
62
                                }
 
63
                        }
 
64
                        return null;
 
65
                }
 
66
                
 
67
                /// <summary>
 
68
                /// The MSBuildEngine sets the SharpDevelopBinPath so if
 
69
                /// the SharpDevelop.Base assembly is shadow copied it refers
 
70
                /// to the shadow copied assembly not the original. This
 
71
                /// causes problems for wix projects that refer to the
 
72
                /// wix.targets import via $(SharpDevelopBinPath) so here
 
73
                /// we change it so it points to the real SharpDevelop 
 
74
                /// binary.
 
75
                /// </summary>
 
76
                public static void InitMSBuildEngine()
 
77
                {
 
78
                        // Remove existing SharpDevelopBinPath property.
 
79
                        MSBuildEngine.MSBuildProperties.Remove("SharpDevelopBinPath");
 
80
 
 
81
                        // Set the SharpDevelopBinPath property so it points to
 
82
                        // the actual bin path where SharpDevelop was built not
 
83
                        // to the shadow copy folder.
 
84
                        string codeBase = typeof(MSBuildEngine).Assembly.CodeBase.Replace("file:///", String.Empty);
 
85
                        string folder = Path.GetDirectoryName(codeBase);
 
86
                        folder = Path.GetFullPath(Path.Combine(folder, @"..\"));
 
87
                        MSBuildEngine.MSBuildProperties["SharpDevelopBinPath"] = folder;
 
88
                }
 
89
                
 
90
                /// <summary>
 
91
                /// Registers embedded strings with SharpDevelop's resource Manager 
 
92
                /// </summary>
 
93
                public static void RegisterResourceStringsWithSharpDevelopResourceManager()
 
94
                {
 
95
                        ResourceManager rm = new ResourceManager("WixBinding.Tests.Strings", typeof(WixBindingTestsHelper).Assembly);
 
96
                        ResourceService.RegisterNeutralStrings(rm);
 
97
                }
 
98
        }
 
99
}