Skip to content

Commit 0f70357

Browse files
authored
docs: improve readme examples (#480)
As mentioned in #471 improve the initialization examples in the README and replace "productive code" with "production code".
1 parent 7474abc commit 0f70357

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

README.md

+40-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void StoreData_ShouldWriteValidFile()
6565

6666
## Getting Started
6767

68-
- Install `Testably.Abstractions` as nuget package in your productive projects and `Testably.Abstractions.Testing` as nuget package in your test projects.
68+
- Install `Testably.Abstractions` as nuget package in your production projects and `Testably.Abstractions.Testing` as nuget package in your test projects.
6969
```ps
7070
dotnet add package Testably.Abstractions
7171
dotnet add package Testably.Abstractions.Testing
@@ -82,11 +82,38 @@ public void StoreData_ShouldWriteValidFile()
8282
**You can now use the interfaces in your services!**
8383

8484
## Testing
85-
In order to simplify testing, the `Testably.Abstractions.Testing` project provides mocked instances for the abstraction interfaces:
85+
In order to simplify testing, the `Testably.Abstractions.Testing` project provides mocked instances for the abstraction interfaces, which are configured using fluent syntax:
8686

87-
These mocks are configured using fluent syntax:
87+
### Initialization
88+
89+
The following two code snippets initialize the mocked `fileSystem` with a structure like the following:
90+
- Directory "foo"
91+
- Directory "bar"
92+
- Empty file "bar.txt"
93+
- File "foo.txt" with "some file content" as content
94+
95+
```csharp
96+
var fileSystem = new MockFileSystem();
97+
fileSystem.Initialize().With(
98+
new DirectoryDescription("foo",
99+
new DirectoryDescription("bar"),
100+
new FileDescription("bar.txt")),
101+
new FileDescription("foo.txt", "some file content"));
102+
```
103+
104+
```csharp
105+
var fileSystem = new MockFileSystem();
106+
fileSystem.Initialize()
107+
.WithSubdirectory("foo").Initialized(d => d
108+
.WithSubdirectory("bar")
109+
.WithFile("bar.txt"))
110+
.WithFile("foo.txt").Which(f => f.HasStringContent("some file content"));
111+
```
112+
113+
### Drive management
88114
```csharp
89-
new MockFileSystem()
115+
var fileSystem = new MockFileSystem();
116+
fileSystem
90117
.WithDrive("D:", d => d
91118
.SetTotalSize(1024 * 1024))
92119
.InitializeIn("D:")
@@ -96,3 +123,12 @@ new MockFileSystem()
96123
f => f.HasStringContent("{\"count\":1}")));
97124
```
98125
Initializes the mocked file system with a second drive `D:` with 1MB total available space and creates on it an empty text file `foo.txt` and a directory `sub-dir` which contains randomly named json file with `{"count":1}` as file content.
126+
127+
On non-Windows systems, the main drive can still be configured, e.g.
128+
```csharp
129+
var fileSystem = new MockFileSystem();
130+
fileSystem.WithDrive(d => d.SetTotalSize(20));
131+
132+
// this will throw an IOException that there is not enough space on the disk.
133+
fileSystem.File.WriteAllText("foo", "some text longer than 20 bytes");
134+
```

0 commit comments

Comments
 (0)