main
cs 95 lines 3.94 KB
Raw
1 // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3 namespace WixToolsetTest.Converters
4 {
5 using System;
6 using System.IO;
7 using System.Xml.Linq;
8 using WixInternal.TestSupport;
9 using WixToolset.Converters;
10 using WixToolsetTest.Converters.Mocks;
11 using Xunit;
12
13 public class CustomActionFixture : BaseConverterFixture
14 {
15 [Fact]
16 public void CanConvertCustomAction()
17 {
18 var parse = String.Join(Environment.NewLine,
19 "<?xml version='1.0' encoding='utf-8'?>",
20 "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>",
21 " <CustomAction Id='Foo1' BinaryKey='WixCA' DllEntry='CAQuietExec' />",
22 " <CustomAction Id='Foo2' BinaryKey='WixCA_x64' DllEntry='CAQuietExec64' />",
23 " <CustomAction Id='Foo3' BinaryKey='UtilCA' DllEntry='WixQuietExec' />",
24 " <CustomAction Id='Foo4' BinaryKey='UtilCA_x64' DllEntry='WixQuietExec64' />",
25 " <CustomAction Id='Foo5' BinaryKey='WixCA' DllEntry='CAQuietExec64' Execute='deferred' Return='check' Impersonate='no' />",
26 "</Wix>");
27
28 var expected = new[]
29 {
30 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
31 " <CustomAction Id=\"Foo1\" DllEntry=\"WixQuietExec\" BinaryRef=\"Wix4UtilCA_X86\" />",
32 " <CustomAction Id=\"Foo2\" DllEntry=\"WixQuietExec64\" BinaryRef=\"Wix4UtilCA_X64\" />",
33 " <CustomAction Id=\"Foo3\" DllEntry=\"WixQuietExec\" BinaryRef=\"Wix4UtilCA_X86\" />",
34 " <CustomAction Id=\"Foo4\" DllEntry=\"WixQuietExec64\" BinaryRef=\"Wix4UtilCA_X64\" />",
35 " <CustomAction Id=\"Foo5\" DllEntry=\"WixQuietExec64\" Execute=\"deferred\" Return=\"check\" Impersonate=\"no\" BinaryRef=\"Wix4UtilCA_X86\" />",
36 "</Wix>",
37 };
38
39 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
40
41 var messaging = new MockMessaging();
42 var converter = new WixConverter(messaging, 2, null, null);
43
44 var errors = converter.ConvertDocument(document);
45
46 var actual = UnformattedDocumentLines(document);
47
48 WixAssert.CompareLineByLine(expected, actual);
49 Assert.Equal(14, errors);
50 }
51
52 [Fact]
53 public void CanConvertCustomActionScript()
54 {
55 var parse = String.Join(Environment.NewLine,
56 "<?xml version='1.0' encoding='utf-8'?>",
57 "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>",
58 " <CustomAction Id='Foo' Script='jscript'>",
59 " function() {",
60 " var x = 0;",
61 " return x;",
62 " }",
63 " </CustomAction>",
64 "</Wix>");
65
66 var expected = new[]
67 {
68 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
69 " <CustomAction Id=\"Foo\" Script=\"jscript\" ScriptSourceFile=\"Foo.js\" />",
70 "</Wix>",
71 };
72
73 var expectedScript = String.Join("\n",
74 "function() {",
75 " var x = 0;",
76 " return x;",
77 " }");
78
79 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
80
81 var messaging = new MockMessaging();
82 var converter = new WixConverter(messaging, 2, null, null);
83
84 var errors = converter.ConvertDocument(document);
85
86 var actual = UnformattedDocumentLines(document);
87
88 Assert.Equal(2, errors);
89 WixAssert.CompareLineByLine(expected, actual);
90
91 var script = File.ReadAllText("Foo.js");
92 WixAssert.StringEqual(expectedScript, script);
93 }
94 }
95 }