forked from ttu/json-flatfile-datastore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add system.io.abstractions for an option to have a mockable filesyste…
…m in unit testing
- Loading branch information
youri
committed
Jun 1, 2023
1 parent
779a307
commit 83d4bc8
Showing
5 changed files
with
64 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO.Abstractions.TestingHelpers; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace JsonFlatFileDataStore.Test | ||
{ | ||
public class MockedFileSystemTest | ||
{ | ||
[Fact] | ||
public async Task WriteToFileTest() | ||
{ | ||
var filepath = @"c:\data.json"; | ||
|
||
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> | ||
{ | ||
{ filepath, new MockFileData("{}") }, | ||
}); | ||
|
||
var store = new DataStore(fileSystem, "c:\\data.json"); | ||
|
||
var collection = store.GetCollection<PrivateOwner>("PrivateOwner"); | ||
Assert.Equal(0, collection.Count); | ||
|
||
await collection.InsertOneAsync(new PrivateOwner { | ||
FirstName = "Jimmy", | ||
OwnerLongTestProperty = "UT" }); | ||
Assert.Equal(1, collection.Count); | ||
|
||
var json = fileSystem.File.ReadAllText(filepath); | ||
|
||
Assert.Contains("privateOwner", json); | ||
Assert.Contains("ownerLongTestProperty", json); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters