diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/WixToolsetTest.Data/TupleDefinitionFixture.cs | 135 | ||||
-rw-r--r-- | src/test/WixToolsetTest.Data/WixToolsetTest.Data.csproj | 19 |
2 files changed, 154 insertions, 0 deletions
diff --git a/src/test/WixToolsetTest.Data/TupleDefinitionFixture.cs b/src/test/WixToolsetTest.Data/TupleDefinitionFixture.cs new file mode 100644 index 00000000..53aa2196 --- /dev/null +++ b/src/test/WixToolsetTest.Data/TupleDefinitionFixture.cs | |||
@@ -0,0 +1,135 @@ | |||
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.Data | ||
4 | { | ||
5 | using WixToolset.Data; | ||
6 | using WixToolset.Data.Tuples; | ||
7 | using Xunit; | ||
8 | |||
9 | public class TupleDefinitionFixture | ||
10 | { | ||
11 | [Fact] | ||
12 | public void CanCreateFileTuple() | ||
13 | { | ||
14 | var tuple = TupleDefinitions.File.CreateTuple(); | ||
15 | Assert.IsType<FileTuple>(tuple); | ||
16 | Assert.Same(TupleDefinitions.File, tuple.Definition); | ||
17 | } | ||
18 | |||
19 | [Fact] | ||
20 | public void CanCreateFileTupleByName() | ||
21 | { | ||
22 | var tuple = TupleDefinitions.ByName("File").CreateTuple(); | ||
23 | Assert.IsType<FileTuple>(tuple); | ||
24 | Assert.Same(TupleDefinitions.File, tuple.Definition); | ||
25 | } | ||
26 | |||
27 | //[Fact] | ||
28 | //public void CanCreateFileTupleByType() | ||
29 | //{ | ||
30 | // var tuple = TupleDefinitions.CreateTuple<FileTuple>(); | ||
31 | // Assert.Same(TupleDefinitions.File, tuple.Definition); | ||
32 | //} | ||
33 | |||
34 | [Fact] | ||
35 | public void CanSetComponentFieldInFileTupleByCasting() | ||
36 | { | ||
37 | var fileTuple = (FileTuple)TupleDefinitions.File.CreateTuple(); | ||
38 | fileTuple.Component_ = "Foo"; | ||
39 | Assert.Equal("Foo", fileTuple.Component_); | ||
40 | } | ||
41 | |||
42 | [Fact] | ||
43 | public void CanCheckNameofField() | ||
44 | { | ||
45 | var fileTuple = new FileTuple(); | ||
46 | Assert.Equal("Component_", fileTuple.Definition.FieldDefinitions[1].Name); | ||
47 | Assert.Null(fileTuple.Fields[0]); | ||
48 | fileTuple.Component_ = "Foo"; | ||
49 | Assert.Equal("Component_", fileTuple.Fields[1].Name); | ||
50 | Assert.Same(fileTuple.Definition.FieldDefinitions[1].Name, fileTuple.Fields[1].Name); | ||
51 | } | ||
52 | |||
53 | [Fact] | ||
54 | public void CanSetComponentFieldInFileTupleByNew() | ||
55 | { | ||
56 | var fileTuple = new FileTuple(); | ||
57 | fileTuple.Component_ = "Foo"; | ||
58 | Assert.Equal("Foo", fileTuple.Component_); | ||
59 | } | ||
60 | |||
61 | [Fact] | ||
62 | public void CanGetContext() | ||
63 | { | ||
64 | using (new IntermediateFieldContext("bar")) | ||
65 | { | ||
66 | var fileTuple = new FileTuple(); | ||
67 | fileTuple.Component_ = "Foo"; | ||
68 | |||
69 | var field = fileTuple[FileTupleFields.Component_]; | ||
70 | Assert.Equal("Foo", field.AsString()); | ||
71 | Assert.Equal("bar", field.Context); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | [Fact] | ||
76 | public void CanSetInNestedContext() | ||
77 | { | ||
78 | var fileTuple = new FileTuple(); | ||
79 | |||
80 | using (new IntermediateFieldContext("bar")) | ||
81 | { | ||
82 | fileTuple.Component_ = "Foo"; | ||
83 | |||
84 | var field = fileTuple[FileTupleFields.Component_]; | ||
85 | Assert.Equal("Foo", field.AsString()); | ||
86 | Assert.Equal("bar", field.Context); | ||
87 | |||
88 | using (new IntermediateFieldContext("baz")) | ||
89 | { | ||
90 | fileTuple.Component_ = "Foo2"; | ||
91 | |||
92 | field = fileTuple[FileTupleFields.Component_]; | ||
93 | Assert.Equal("Foo2", field.AsString()); | ||
94 | Assert.Equal("baz", field.Context); | ||
95 | |||
96 | Assert.Equal("Foo", (string)field.PreviousValue); | ||
97 | Assert.Equal("bar", field.PreviousValue.Context); | ||
98 | } | ||
99 | |||
100 | fileTuple.Component_ = "Foo3"; | ||
101 | |||
102 | field = fileTuple[FileTupleFields.Component_]; | ||
103 | Assert.Equal("Foo3", field.AsString()); | ||
104 | Assert.Equal("bar", field.Context); | ||
105 | |||
106 | Assert.Equal("Foo2", (string)field.PreviousValue); | ||
107 | Assert.Equal("baz", field.PreviousValue.Context); | ||
108 | |||
109 | Assert.Equal("Foo", (string)field.PreviousValue.PreviousValue); | ||
110 | Assert.Equal("bar", field.PreviousValue.PreviousValue.Context); | ||
111 | } | ||
112 | |||
113 | fileTuple.Component_ = "Foo4"; | ||
114 | |||
115 | var fieldOutside = fileTuple[FileTupleFields.Component_]; | ||
116 | Assert.Equal("Foo4", fieldOutside.AsString()); | ||
117 | Assert.Null(fieldOutside.Context); | ||
118 | } | ||
119 | |||
120 | //[Fact] | ||
121 | //public void CanSetComponentFieldInFileTuple() | ||
122 | //{ | ||
123 | // var fileTuple = TupleDefinitions.File.CreateTuple<FileTuple>(); | ||
124 | // fileTuple.Component_ = "Foo"; | ||
125 | // Assert.Equal("Foo", fileTuple.Component_); | ||
126 | //} | ||
127 | |||
128 | //[Fact] | ||
129 | //public void CanThrowOnMismatchTupleType() | ||
130 | //{ | ||
131 | // var e = Assert.Throws<InvalidCastException>(() => TupleDefinitions.File.CreateTuple<ComponentTuple>()); | ||
132 | // Assert.Equal("Requested wrong type WixToolset.Data.Tuples.ComponentTuple, actual type WixToolset.Data.Tuples.FileTuple", e.Message); | ||
133 | //} | ||
134 | } | ||
135 | } | ||
diff --git a/src/test/WixToolsetTest.Data/WixToolsetTest.Data.csproj b/src/test/WixToolsetTest.Data/WixToolsetTest.Data.csproj new file mode 100644 index 00000000..fe0d99c5 --- /dev/null +++ b/src/test/WixToolsetTest.Data/WixToolsetTest.Data.csproj | |||
@@ -0,0 +1,19 @@ | |||
1 | <Project Sdk="Microsoft.NET.Sdk"> | ||
2 | |||
3 | <PropertyGroup> | ||
4 | <TargetFramework>netcoreapp2.0</TargetFramework> | ||
5 | |||
6 | <IsPackable>false</IsPackable> | ||
7 | </PropertyGroup> | ||
8 | |||
9 | <ItemGroup> | ||
10 | <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" /> | ||
11 | <PackageReference Include="xunit" Version="2.2.0" /> | ||
12 | <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> | ||
13 | </ItemGroup> | ||
14 | |||
15 | <ItemGroup> | ||
16 | <ProjectReference Include="..\..\WixToolset.Data\WixToolset.Data.csproj" /> | ||
17 | </ItemGroup> | ||
18 | |||
19 | </Project> | ||