Merge pull request #1266 from esdrubal/datetimenewformat
[mono.git] / mcs / class / WindowsBase / Test / System.IO.Packaging / FakePackage.cs
1 // Permission is hereby granted, free of charge, to any person obtaining\r
2 // a copy of this software and associated documentation files (the\r
3 // "Software"), to deal in the Software without restriction, including\r
4 // without limitation the rights to use, copy, modify, merge, publish,\r
5 // distribute, sublicense, and/or sell copies of the Software, and to\r
6 // permit persons to whom the Software is furnished to do so, subject to\r
7 // the following conditions:\r
8 // \r
9 // The above copyright notice and this permission notice shall be\r
10 // included in all copies or substantial portions of the Software.\r
11 // \r
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
19 //\r
20 // Copyright (c) 2008 Novell, Inc. (http://www.novell.com)\r
21 //\r
22 // Authors:\r
23 //      Alan McGovern (amcgovern@novell.com)\r
24 //\r
25 \r
26 \r
27 using System;\r
28 using System.IO;\r
29 using System.IO.Packaging;\r
30 using System.Collections.Generic;\r
31 \r
32 namespace MonoTests.System.IO.Packaging {\r
33         \r
34     public class FakePackage : Package {\r
35         Dictionary<Uri, PackagePart> Parts { get; set; }\r
36         public List<Uri> CreatedParts { get; private set; }\r
37         public List<Uri> DeletedParts { get; private set; }\r
38         public List<Uri> GotParts { get; private set; }\r
39 \r
40         public FakePackage (FileAccess access, bool streaming)\r
41             : base (access, streaming)\r
42         {\r
43             CreatedParts = new List<Uri> ();\r
44             DeletedParts = new List<Uri> ();\r
45             GotParts = new List<Uri>();\r
46             Parts = new Dictionary<Uri, PackagePart> ();\r
47         }\r
48 \r
49         protected override PackagePart CreatePartCore (Uri partUri, string contentType, CompressionOption compressionOption)\r
50         {\r
51             FakePackagePart p = new FakePackagePart (this, partUri, contentType, compressionOption);\r
52             Parts.Add (p.Uri, p);\r
53             CreatedParts.Add (partUri);\r
54             return p;\r
55         }\r
56 \r
57         protected override void DeletePartCore (Uri partUri)\r
58         {\r
59             DeletedParts.Add (partUri);\r
60             Parts.Remove (partUri);\r
61         }\r
62 \r
63         protected override void FlushCore ()\r
64         {\r
65             // Flush...\r
66         }\r
67         \r
68         protected override PackagePart GetPartCore (Uri partUri)\r
69         {\r
70             if (!GotParts.Contains (partUri))\r
71                 GotParts.Add (partUri);\r
72             return Parts.ContainsKey(partUri) ?  Parts [partUri] : null;\r
73         }\r
74 \r
75         protected override PackagePart [] GetPartsCore ()\r
76         {\r
77             PackagePart [] p = new PackagePart [Parts.Count];\r
78             Parts.Values.CopyTo (p, 0);\r
79             return p;\r
80         }\r
81     }\r
82 }\r