public ProductConfigDetails GetProductConfig()
{
ProductConfigDetails ProdConfigDetails;
if (appsettingsconfiguration.UseMockData)
{
taxConfigDetails = JsonFileReader.GetJsonFileData<TaxConfigDetails>("ProductConfiguration.json");
return ProdConfigDetails;
}
else
{
var lastModifieddteDateTime = System.IO.File.GetLastWriteTime("C:\\Data\\ProductConfiguration.json");
_memoryCache.TryGetValue("lastedit", out DateTime? modifiedDate);
if (lastModifieddteDateTime != modifiedDate)
{
var config = System.IO.File.ReadAllText("C:\\Data\\ProductConfiguration.json");
ProdConfigDetails = JsonConvert.DeserializeObject<ProductConfigDetails>(config);
_memoryCache.Set("lastedit", lastModified);
_memoryCache.Set("cachedConfig", ProdConfigDetails);
return ProdConfigDetails;
}
else
{
_memoryCache.TryGetValue("cachedConfig", out ProdConfigDetails);
return ProdConfigDetails;
}
}
}
What I have tried:
Job of this method: Fetch and return the JSON file details.
if option set to read mock data it is going to fetch from soln local mocked file.
else read the file from filesystem and then cache it.
if cached data is unchanged, fetch from cache.
For this method I need to write unit tests.
what are the possible tests I can write for this method?
1) GetProdConfigDetails_FromPhysicalPath()
2) GetProdConfigDetails_FromMockFile()
3) GetProdConfigDetails_FromInMemoryCache()
Please feel free to comment if any other test needs to be added.
How can I implement this test
GetProdConfigDetails_FromInMemoryCache()?