diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/WixToolset.Data/WixOutput.cs | 13 | ||||
-rw-r--r-- | src/test/WixToolsetTest.Data/SerializeFixture.cs | 83 |
2 files changed, 86 insertions, 10 deletions
diff --git a/src/WixToolset.Data/WixOutput.cs b/src/WixToolset.Data/WixOutput.cs index 27e7827a..bb546821 100644 --- a/src/WixToolset.Data/WixOutput.cs +++ b/src/WixToolset.Data/WixOutput.cs | |||
@@ -183,6 +183,8 @@ namespace WixToolset.Data | |||
183 | /// <returns>Stream to the data of the file.</returns> | 183 | /// <returns>Stream to the data of the file.</returns> |
184 | public Stream CreateDataStream(string name) | 184 | public Stream CreateDataStream(string name) |
185 | { | 185 | { |
186 | this.DeleteExistingEntry(name); | ||
187 | |||
186 | var entry = this.archive.CreateEntry(name); | 188 | var entry = this.archive.CreateEntry(name); |
187 | 189 | ||
188 | return entry.Open(); | 190 | return entry.Open(); |
@@ -195,6 +197,8 @@ namespace WixToolset.Data | |||
195 | /// <param name="path">Path to file on disk to include in the output.</param> | 197 | /// <param name="path">Path to file on disk to include in the output.</param> |
196 | public void ImportDataStream(string name, string path) | 198 | public void ImportDataStream(string name, string path) |
197 | { | 199 | { |
200 | this.DeleteExistingEntry(name); | ||
201 | |||
198 | this.archive.CreateEntryFromFile(path, name, System.IO.Compression.CompressionLevel.Optimal); | 202 | this.archive.CreateEntryFromFile(path, name, System.IO.Compression.CompressionLevel.Optimal); |
199 | } | 203 | } |
200 | 204 | ||
@@ -256,5 +260,14 @@ namespace WixToolset.Data | |||
256 | 260 | ||
257 | this.disposed = true; | 261 | this.disposed = true; |
258 | } | 262 | } |
263 | |||
264 | private void DeleteExistingEntry(string name) | ||
265 | { | ||
266 | var entry = this.archive.GetEntry(name); | ||
267 | if (entry != null) | ||
268 | { | ||
269 | entry.Delete(); | ||
270 | } | ||
271 | } | ||
259 | } | 272 | } |
260 | } | 273 | } |
diff --git a/src/test/WixToolsetTest.Data/SerializeFixture.cs b/src/test/WixToolsetTest.Data/SerializeFixture.cs index c07124ef..6e224438 100644 --- a/src/test/WixToolsetTest.Data/SerializeFixture.cs +++ b/src/test/WixToolsetTest.Data/SerializeFixture.cs | |||
@@ -32,20 +32,83 @@ namespace WixToolsetTest.Data | |||
32 | intermediate.UpdateLevel(IntermediateLevels.Resolved); | 32 | intermediate.UpdateLevel(IntermediateLevels.Resolved); |
33 | 33 | ||
34 | var path = Path.GetTempFileName(); | 34 | var path = Path.GetTempFileName(); |
35 | intermediate.Save(path); | 35 | try |
36 | { | ||
37 | intermediate.Save(path); | ||
38 | |||
39 | var loaded = Intermediate.Load(path); | ||
40 | |||
41 | Assert.True(loaded.HasLevel(IntermediateLevels.Compiled)); | ||
42 | Assert.True(loaded.HasLevel(IntermediateLevels.Linked)); | ||
43 | Assert.True(loaded.HasLevel(IntermediateLevels.Resolved)); | ||
44 | |||
45 | var tuple = (ComponentTuple)loaded.Sections.Single().Tuples.Single(); | ||
46 | |||
47 | Assert.Equal("TestComponent", tuple.Id.Id); | ||
48 | Assert.Equal(AccessModifier.Public, tuple.Id.Access); | ||
49 | Assert.Equal("TestFolder", tuple.DirectoryRef); | ||
50 | Assert.Equal(ComponentLocation.Either, tuple.Location); | ||
51 | } | ||
52 | finally | ||
53 | { | ||
54 | File.Delete(path); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | [Fact] | ||
59 | public void CanUpdateIntermediate() | ||
60 | { | ||
61 | var sln = new SourceLineNumber("test.wxs", 1); | ||
62 | var section = new IntermediateSection("test", SectionType.Product, 65001); | ||
63 | |||
64 | section.Tuples.Add(new ComponentTuple(sln, new Identifier(AccessModifier.Public, "TestComponent")) | ||
65 | { | ||
66 | ComponentId = new Guid(1, 0, 0, new byte[8]).ToString("B"), | ||
67 | DirectoryRef = "TestFolder", | ||
68 | Location = ComponentLocation.Either, | ||
69 | }); | ||
70 | |||
71 | var intermediate = new Intermediate("TestIntermediate", IntermediateLevels.Compiled, new[] { section }, null); | ||
72 | |||
73 | var path = Path.GetTempFileName(); | ||
74 | try | ||
75 | { | ||
76 | intermediate.Save(path); | ||
36 | 77 | ||
37 | var loaded = Intermediate.Load(path); | 78 | var uri = new Uri(Path.GetFullPath(path)); |
79 | var stream = File.Open(path, FileMode.Open, FileAccess.ReadWrite); | ||
38 | 80 | ||
39 | Assert.True(loaded.HasLevel(IntermediateLevels.Compiled)); | 81 | using (var wixout = WixOutput.Read(uri, stream)) |
40 | Assert.True(loaded.HasLevel(IntermediateLevels.Linked)); | 82 | { |
41 | Assert.True(loaded.HasLevel(IntermediateLevels.Resolved)); | 83 | var loaded = Intermediate.Load(wixout); |
84 | var tuple = (ComponentTuple)loaded.Sections.Single().Tuples.Single(); | ||
85 | |||
86 | Assert.Equal("TestComponent", tuple.Id.Id); | ||
87 | Assert.Equal(AccessModifier.Public, tuple.Id.Access); | ||
88 | |||
89 | wixout.Reopen(writable: true); | ||
90 | |||
91 | section.Tuples.Add(new ComponentTuple(sln, new Identifier(AccessModifier.Public, "NewComponent")) | ||
92 | { | ||
93 | ComponentId = new Guid(1, 0, 0, new byte[8]).ToString("B"), | ||
94 | }); | ||
95 | |||
96 | intermediate.Save(wixout); | ||
97 | loaded = Intermediate.Load(wixout); | ||
98 | |||
99 | var newTuple = loaded.Sections.Single().Tuples.Where(t => t.Id.Id == "NewComponent"); | ||
100 | Assert.Single(newTuple); | ||
101 | } | ||
42 | 102 | ||
43 | var tuple = (ComponentTuple)loaded.Sections.Single().Tuples.Single(); | 103 | var loadedAfterDispose = Intermediate.Load(path); |
104 | var newTupleStillThere = loadedAfterDispose.Sections.Single().Tuples.Where(t => t.Id.Id == "NewComponent"); | ||
105 | Assert.Single(newTupleStillThere); | ||
44 | 106 | ||
45 | Assert.Equal("TestComponent", tuple.Id.Id); | 107 | } |
46 | Assert.Equal(AccessModifier.Public, tuple.Id.Access); | 108 | finally |
47 | Assert.Equal("TestFolder", tuple.DirectoryRef); | 109 | { |
48 | Assert.Equal(ComponentLocation.Either, tuple.Location); | 110 | File.Delete(path); |
111 | } | ||
49 | } | 112 | } |
50 | 113 | ||
51 | [Fact] | 114 | [Fact] |