Skip to content

Commit

Permalink
Resolve ttu#19 - Added get root to IDataStore and changed location of…
Browse files Browse the repository at this point in the history
… tests
  • Loading branch information
colbytimm committed Feb 21, 2022
1 parent 9d04821 commit 75c3a53
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 38 deletions.
35 changes: 0 additions & 35 deletions JsonFlatFileDataStore.Test/DataStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,41 +419,6 @@ public async Task Insert_CorrectIdWithDynamic_With_InitialId()
UTHelpers.Down(pathToJson);
}

[Fact]
public void GetRoot_Dynamic()
{
var pathToJson = UTHelpers.Up();

var store = new DataStore(pathToJson);

// Get root
var root = store.GetRoot();

Assert.Equal(1, root.user[0].id);
Assert.Equal(2.1, root.myValue);
Assert.Equal("Carrillo", root.family[0].parents[0].name);

UTHelpers.Down(pathToJson);
}

[Fact]
public void GetRoot_Typed()
{
var pathToJson = UTHelpers.Up();

// Open database (create new if file doesn't exist)
var store = new DataStore(pathToJson);

// Get root
var root = store.GetRoot<Store>();

Assert.Equal(1, root.User.First().Id);
Assert.Equal(2.1, root.MyValue);
Assert.Equal("Carrillo", root.Family.First().Parents.First().Name);

UTHelpers.Down(pathToJson);
}

[Fact]
public async Task Readme_Example3()
{
Expand Down
35 changes: 35 additions & 0 deletions JsonFlatFileDataStore.Test/SingleItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,41 @@ public void GetItem_Nullable_NotFound()
UTHelpers.Down(newFilePath);
}

[Fact]
public void GetRoot_Dynamic()
{
var pathToJson = UTHelpers.Up();

var store = new DataStore(pathToJson);

// Get root
var root = store.GetRoot();

Assert.Equal(1, root.user[0].id);
Assert.Equal(2.1, root.myValue);
Assert.Equal("Carrillo", root.family[0].parents[0].name);

UTHelpers.Down(pathToJson);
}

[Fact]
public void GetRoot_Typed()
{
var pathToJson = UTHelpers.Up();

// Open database (create new if file doesn't exist)
var store = new DataStore(pathToJson);

// Get root
var root = store.GetRoot<Store>();

Assert.Equal(1, root.User.First().Id);
Assert.Equal(2.1, root.MyValue);
Assert.Equal("Carrillo", root.Family.First().Parents.First().Name);

UTHelpers.Down(pathToJson);
}

[Fact]
public void NotFound_Exception()
{
Expand Down
4 changes: 1 addition & 3 deletions JsonFlatFileDataStore/DataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,7 @@ public T GetRoot<T>()
throw new KeyNotFoundException();
}

var temp = _jsonData.ToObject<T>();

return temp;
return _jsonData.ToObject<T>();
}

private dynamic SingleDynamicItemReadConverter(JToken e)
Expand Down
13 changes: 13 additions & 0 deletions JsonFlatFileDataStore/IDataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ public interface IDataStore : IDisposable
/// <param name="key">Item key</param>
/// <returns>true if items found for deletion</returns>
Task<bool> DeleteItemAsync(string key);

/// <summary>
/// Get root item
/// </summary>
/// <returns>Dynamic item</returns>
dynamic GetRoot();

/// <summary>
/// Get root item
/// </summary>
/// <typeparam name="T">Item type</typeparam>
/// <returns>Typed item</returns>
T GetRoot<T>();
}

public enum ValueType
Expand Down

0 comments on commit 75c3a53

Please sign in to comment.