Loading StockAdvisory/FileManager/FileManager.cs +5 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,11 @@ public class FileManager : IFileManager { private string _storagePath; public string StoragePath { get { return _storagePath; } } private readonly string _sourceUrl; private readonly HttpClient _httpClient; Loading StockAdvisoryWebApi.Tests/StockWebApiTests.cs +27 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ public class StockWebApiTests { private WebApplicationFactory<Program> _factory; private FakeClock _clock; private FileManager _fileManager; private void SetupFiles() { Loading Loading @@ -63,7 +64,7 @@ public class StockWebApiTests // It really does not matter var downloadUrl = "https://ark-funds.com/"; var fileManager = new FileManager($"filesystem", options.CreateHttpClient(), downloadUrl, _clock); _fileManager = new FileManager($"filesystem", options.CreateHttpClient(), downloadUrl, _clock); _factory = new WebApplicationFactory<Program>() .WithWebHostBuilder(builder => Loading @@ -76,7 +77,7 @@ public class StockWebApiTests descriptor = services.Single(s => s.ServiceType == typeof(IClock)); Assert.True(services.Remove(descriptor)); services.AddSingleton<IFileManager>(fileManager); services.AddSingleton<IFileManager>(_fileManager); services.AddSingleton<IClock>(_clock); }); }); Loading Loading @@ -258,4 +259,28 @@ public class StockWebApiTests Directory.Delete("filesystem2", true); } [Test] public async Task Test_WhenChangingDirectory_Then_StoragePathChanges() { Directory.CreateDirectory("filesystem2"); var client = _factory.CreateClient(); var savedStoragePath = _fileManager.StoragePath; StockStorageLocation stockStorageLocation = new StockStorageLocation(); stockStorageLocation.Location = "filesystem2"; var jsonContent = JsonContent.Create(stockStorageLocation); var response = await client.PostAsync("/StockSettings", jsonContent); Assert.AreNotEqual(savedStoragePath, _fileManager.StoragePath); // set back to "filesystem" stockStorageLocation.Location = "filesystem"; jsonContent = JsonContent.Create(stockStorageLocation); response = await client.PostAsync("/StockSettings", jsonContent); Assert.AreEqual(savedStoragePath, _fileManager.StoragePath); Directory.Delete("filesystem2", true); } } Loading
StockAdvisory/FileManager/FileManager.cs +5 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,11 @@ public class FileManager : IFileManager { private string _storagePath; public string StoragePath { get { return _storagePath; } } private readonly string _sourceUrl; private readonly HttpClient _httpClient; Loading
StockAdvisoryWebApi.Tests/StockWebApiTests.cs +27 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ public class StockWebApiTests { private WebApplicationFactory<Program> _factory; private FakeClock _clock; private FileManager _fileManager; private void SetupFiles() { Loading Loading @@ -63,7 +64,7 @@ public class StockWebApiTests // It really does not matter var downloadUrl = "https://ark-funds.com/"; var fileManager = new FileManager($"filesystem", options.CreateHttpClient(), downloadUrl, _clock); _fileManager = new FileManager($"filesystem", options.CreateHttpClient(), downloadUrl, _clock); _factory = new WebApplicationFactory<Program>() .WithWebHostBuilder(builder => Loading @@ -76,7 +77,7 @@ public class StockWebApiTests descriptor = services.Single(s => s.ServiceType == typeof(IClock)); Assert.True(services.Remove(descriptor)); services.AddSingleton<IFileManager>(fileManager); services.AddSingleton<IFileManager>(_fileManager); services.AddSingleton<IClock>(_clock); }); }); Loading Loading @@ -258,4 +259,28 @@ public class StockWebApiTests Directory.Delete("filesystem2", true); } [Test] public async Task Test_WhenChangingDirectory_Then_StoragePathChanges() { Directory.CreateDirectory("filesystem2"); var client = _factory.CreateClient(); var savedStoragePath = _fileManager.StoragePath; StockStorageLocation stockStorageLocation = new StockStorageLocation(); stockStorageLocation.Location = "filesystem2"; var jsonContent = JsonContent.Create(stockStorageLocation); var response = await client.PostAsync("/StockSettings", jsonContent); Assert.AreNotEqual(savedStoragePath, _fileManager.StoragePath); // set back to "filesystem" stockStorageLocation.Location = "filesystem"; jsonContent = JsonContent.Create(stockStorageLocation); response = await client.PostAsync("/StockSettings", jsonContent); Assert.AreEqual(savedStoragePath, _fileManager.StoragePath); Directory.Delete("filesystem2", true); } }