Commit a53bd9a
authored
feat: set Creation, LastAccess and LastWrite time for files (#875)
Implements #872
Adjust `CreationTime`, `LastAccessTime` and `LastWriteTime` when interacting with files in the `MockFileSystem`.
Provides a means to mock the used DateTime by calling e.g.
```csharp
var fixedTime = new DateTime(2022, 01, 01);
var fileSystem = new MockFileSystem().MockTime(() => fixedTime);
// All times will now be set to the fixedTime.
```
Implementes the following logic in MockFile:
*All these cases are covered by unit tests in MockFileAdjustTimesTest*
- When creating files
CreationTime, LastAccessTime and LastWriteTime are set to the current time
- When changing files (`WriteAllText`, `WriteAllBytes`, `AppendAllText`, `OpenWrite`, `Open`)
LastAccessTime and LastWriteTime are set to the current time
CreationTime is left unchanged
- When reading files (`ReadAllText`, `ReadAllLines`, `ReadAllBytes`, `OpenRead`)
LastAccessTime is set to the current time
CreationTime and LastWriteTime are left unchanged
- When setting attributes or ACLs (`SetAttributes`, `SetAccessControl`)
LastAccessTime is set to the current time
CreationTime and LastWriteTime are left unchanged
- When moving files (`Move`)
LastAccessTime is set to the current time
CreationTime and LastWriteTime are left unchanged
- When copying files (`Copy`)
CreationTime and LastAccessTime of the copied file in the destination directory is set to the current time
LastWriteTime and all times of the source file are left unchanged1 parent d15a5a2 commit a53bd9a
File tree
18 files changed
+703
-50
lines changed- src/System.IO.Abstractions.TestingHelpers
- tests/System.IO.Abstractions.TestingHelpers.Tests
18 files changed
+703
-50
lines changedLines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
11 | 19 | | |
12 | 20 | | |
13 | 21 | | |
| |||
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
127 | | - | |
| 128 | + | |
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
| |||
151 | 152 | | |
152 | 153 | | |
153 | 154 | | |
| 155 | + | |
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
| |||
188 | 190 | | |
189 | 191 | | |
190 | 192 | | |
191 | | - | |
| 193 | + | |
192 | 194 | | |
193 | 195 | | |
194 | 196 | | |
| |||
436 | 438 | | |
437 | 439 | | |
438 | 440 | | |
439 | | - | |
| 441 | + | |
440 | 442 | | |
441 | 443 | | |
442 | 444 | | |
| |||
480 | 482 | | |
481 | 483 | | |
482 | 484 | | |
483 | | - | |
| 485 | + | |
484 | 486 | | |
485 | | - | |
| 487 | + | |
486 | 488 | | |
487 | 489 | | |
488 | 490 | | |
| |||
539 | 541 | | |
540 | 542 | | |
541 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
542 | 550 | | |
543 | 551 | | |
544 | 552 | | |
| |||
578 | 586 | | |
579 | 587 | | |
580 | 588 | | |
581 | | - | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
582 | 592 | | |
583 | 593 | | |
584 | 594 | | |
| |||
590 | 600 | | |
591 | 601 | | |
592 | 602 | | |
593 | | - | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
594 | 606 | | |
595 | | - | |
596 | | - | |
| 607 | + | |
597 | 608 | | |
598 | 609 | | |
599 | 610 | | |
| |||
613 | 624 | | |
614 | 625 | | |
615 | 626 | | |
616 | | - | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
617 | 630 | | |
618 | | - | |
| 631 | + | |
619 | 632 | | |
620 | 633 | | |
621 | 634 | | |
| |||
713 | 726 | | |
714 | 727 | | |
715 | 728 | | |
| 729 | + | |
716 | 730 | | |
717 | 731 | | |
718 | 732 | | |
| |||
736 | 750 | | |
737 | 751 | | |
738 | 752 | | |
| 753 | + | |
739 | 754 | | |
740 | 755 | | |
741 | 756 | | |
| |||
824 | 839 | | |
825 | 840 | | |
826 | 841 | | |
827 | | - | |
| 842 | + | |
828 | 843 | | |
829 | 844 | | |
830 | 845 | | |
| |||
1094 | 1109 | | |
1095 | 1110 | | |
1096 | 1111 | | |
1097 | | - | |
| 1112 | + | |
1098 | 1113 | | |
1099 | 1114 | | |
1100 | 1115 | | |
| |||
1110 | 1125 | | |
1111 | 1126 | | |
1112 | 1127 | | |
| 1128 | + | |
1113 | 1129 | | |
1114 | 1130 | | |
1115 | 1131 | | |
| |||
Lines changed: 23 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| |||
78 | 81 | | |
79 | 82 | | |
80 | 83 | | |
| 84 | + | |
81 | 85 | | |
82 | 86 | | |
83 | 87 | | |
| |||
126 | 130 | | |
127 | 131 | | |
128 | 132 | | |
129 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
130 | 139 | | |
131 | 140 | | |
132 | 141 | | |
133 | 142 | | |
134 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
135 | 149 | | |
136 | 150 | | |
137 | 151 | | |
138 | 152 | | |
139 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
140 | 159 | | |
141 | 160 | | |
142 | 161 | | |
| |||
Lines changed: 19 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | | - | |
| 62 | + | |
64 | 63 | | |
65 | 64 | | |
66 | 65 | | |
67 | 66 | | |
68 | | - | |
| 67 | + | |
69 | 68 | | |
70 | 69 | | |
71 | 70 | | |
| |||
80 | 79 | | |
81 | 80 | | |
82 | 81 | | |
83 | | - | |
| 82 | + | |
84 | 83 | | |
85 | 84 | | |
86 | 85 | | |
| |||
117 | 116 | | |
118 | 117 | | |
119 | 118 | | |
120 | | - | |
| 119 | + | |
121 | 120 | | |
122 | 121 | | |
123 | 122 | | |
124 | 123 | | |
125 | | - | |
| 124 | + | |
126 | 125 | | |
127 | 126 | | |
128 | 127 | | |
| |||
137 | 136 | | |
138 | 137 | | |
139 | 138 | | |
140 | | - | |
| 139 | + | |
141 | 140 | | |
142 | 141 | | |
143 | 142 | | |
| |||
147 | 146 | | |
148 | 147 | | |
149 | 148 | | |
150 | | - | |
| 149 | + | |
151 | 150 | | |
152 | 151 | | |
153 | 152 | | |
154 | 153 | | |
155 | | - | |
| 154 | + | |
156 | 155 | | |
157 | 156 | | |
158 | 157 | | |
| |||
167 | 166 | | |
168 | 167 | | |
169 | 168 | | |
170 | | - | |
| 169 | + | |
171 | 170 | | |
172 | 171 | | |
173 | 172 | | |
| |||
381 | 380 | | |
382 | 381 | | |
383 | 382 | | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
384 | 393 | | |
385 | 394 | | |
386 | 395 | | |
| |||
0 commit comments