diff --git a/Src/BlueDotBrigade.DatenLokator.TestTools/Daten.cs b/Src/BlueDotBrigade.DatenLokator.TestTools/Daten.cs index e365bbf..ad8c001 100644 --- a/Src/BlueDotBrigade.DatenLokator.TestTools/Daten.cs +++ b/Src/BlueDotBrigade.DatenLokator.TestTools/Daten.cs @@ -2,6 +2,7 @@ { using System; using System.Runtime.CompilerServices; + using System.Text.Json; using BlueDotBrigade.DatenLokator.TestTools.Configuration; public class Daten @@ -372,5 +373,67 @@ public System.IO.StreamReader AsStreamReader(From fromSource) return new System.IO.StreamReader(_coordinator.OsFile.OpenRead(sourceFilePath)); } + + /// + /// Retrieves the data that is appropriate for the test that is currently executing. + /// + /// + /// Returns the source file as an instance of . + /// + /// + /// Directory search order: + /// 1. the given directory + /// 2. a compressed file that is similar to the given directory + /// 3. the global directory for shared files + /// + public T AsJson() + { + var sourceFilePath = _coordinator.GetFilePath(_callingMethodName, _callingClassPath); + + ThrowIfFileMissing(sourceFilePath); + + var jsonContent = _coordinator.OsFile.ReadAllText(sourceFilePath); + return JsonSerializer.Deserialize(jsonContent); + } + + /// + /// Retrieves the data that is stored within the given . + /// + /// + /// Returns the source file as an instance of . + /// + /// + /// Directory search order: + /// 1. the given directory + /// 2. a compressed file that is similar to the given directory + /// 3. the global directory for shared files + /// + public T AsJson(string fileName) + { + var sourceFilePath = _coordinator.GetFilePath(fileName, _callingClassPath); + + ThrowIfFileMissing(sourceFilePath); + + var jsonContent = _coordinator.OsFile.ReadAllText(sourceFilePath); + return JsonSerializer.Deserialize(jsonContent); + } + + /// + /// Retrieves the data that was registered with . + /// + /// Determines which registered file to retrieve. + /// + /// Returns the source file as an instance of . + /// + /// + public T AsJson(From fromSource) + { + var sourceFilePath = GetGlobalDefaultPath(fromSource); + + ThrowIfFileMissing(sourceFilePath); + + var jsonContent = _coordinator.OsFile.ReadAllText(sourceFilePath); + return JsonSerializer.Deserialize(jsonContent); + } } } \ No newline at end of file