All files
[pithos-ms-client] / trunk / Pithos.Core.Test / MockStatusKeeper.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Diagnostics.Contracts;
4 using System.Linq;
5 using System.Text;
6 using Pithos.Interfaces;
7
8 namespace Pithos.Core.Test
9 {
10     public class MockStatusChecker : IStatusChecker, IStatusKeeper
11     {
12         public IPithosSettings Settings { get; set; }
13
14         private readonly string[] _states = { "Normal", "Modified", "Conflict", "Synch" };
15
16         Dictionary<string, FileOverlayStatus> _overlayCache = new Dictionary<string, FileOverlayStatus>();
17         Dictionary<string, FileStatus> _statusCache = new Dictionary<string, FileStatus>();
18         Dictionary<string, string> _checksums = new Dictionary<string, string>();
19
20         public FileOverlayStatus GetFileOverlayStatus(string path)
21         {
22             Contract.Requires(!String.IsNullOrWhiteSpace(path));
23             if (!_overlayCache.ContainsKey(path))
24                 return FileOverlayStatus.NA;
25
26             var pithosPath = Settings.PithosPath;
27             if (path.StartsWith(pithosPath, true, null))
28             {
29                 var status = _overlayCache[path];
30                 return status;
31             }
32             return FileOverlayStatus.NA;
33         }
34
35         public PithosStatus GetPithosStatus()
36         {
37             return PithosStatus.InSynch;
38         }
39
40         public void SetFileOverlayStatus(string path, FileOverlayStatus overlayStatus)
41         {
42             _overlayCache[path] = overlayStatus;
43         }
44
45         public void RemoveFileOverlayStatus(string path)
46         {
47             _overlayCache.Remove(path);
48         }
49
50         public void RenameFileOverlayStatus(string oldPath, string newPath)
51         {
52             var status = _overlayCache[oldPath];
53             _overlayCache[newPath] = status;
54             _overlayCache.Remove(oldPath);
55         }
56
57         public void UpdateFileChecksum(string path, string checksum)
58         {
59             _checksums[path] = checksum;
60         }
61
62         public void SetFileStatus(string path, FileStatus status)
63         {
64             _statusCache[path] = status;
65         }
66
67         public FileStatus GetFileStatus(string path)
68         {
69             if (!_statusCache.ContainsKey(path))
70                 return FileStatus.Missing;
71             return _statusCache[path];
72         }
73
74         public void ClearFileStatus(string path)
75         {
76             _statusCache.Remove(path);
77         }
78     }
79 }