Ready to test Max RDS
This commit is contained in:
@ -1,10 +1,15 @@
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using OI.Metrology.Archive.Repositories;
|
||||
using OI.Metrology.Shared.Models;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using OI.Metrology.Tests.Models;
|
||||
using Serilog;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Tests;
|
||||
namespace OI.Metrology.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class UnitTestArchive
|
||||
@ -13,6 +18,7 @@ public class UnitTestArchive
|
||||
private readonly ILogger _Logger;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly string _WorkingDirectory;
|
||||
private readonly IMemoryCache? _MemoryCache;
|
||||
private readonly IConfigurationRoot _ConfigurationRoot;
|
||||
|
||||
public UnitTestArchive()
|
||||
@ -27,13 +33,17 @@ public class UnitTestArchive
|
||||
.AddEnvironmentVariables()
|
||||
.AddJsonFile("appsettings.Development.json");
|
||||
configurationRoot = configurationBuilder.Build();
|
||||
appSettings = OI.Metrology.Tests.Models.Binder.AppSettings.Get(configurationRoot);
|
||||
appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
||||
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
||||
Log.Logger = loggerConfiguration.CreateLogger();
|
||||
logger = Log.ForContext<UnitTestArchive>();
|
||||
logger.Information("Complete");
|
||||
ServiceCollection services = new();
|
||||
ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
_ = services.AddMemoryCache();
|
||||
_MemoryCache = serviceProvider.GetService<IMemoryCache>();
|
||||
_Logger = logger;
|
||||
_AppSettings = appSettings;
|
||||
_WorkingDirectory = workingDirectory;
|
||||
@ -56,7 +66,23 @@ public class UnitTestArchive
|
||||
Assert.IsFalse(_AppSettings is null);
|
||||
Assert.IsFalse(_WorkingDirectory is null);
|
||||
Assert.IsFalse(_ConfigurationRoot is null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestMethodArchiveJson()
|
||||
{
|
||||
string json;
|
||||
string jsonFile = Path.Combine(AppContext.BaseDirectory, "RdsMaxRepo.json");
|
||||
Assert.IsTrue(File.Exists(jsonFile));
|
||||
json = JsonSerializer.Serialize(_AppSettings);
|
||||
IDbConnectionFactory dbConnectionFactory = new SQLDbConnectionFactory(json);
|
||||
IRdsMaxRepo rdsMaxRepo = new RdsMaxRepo(dbConnectionFactory, _MemoryCache);
|
||||
json = File.ReadAllText(jsonFile);
|
||||
Shared.DataModels.RDS.Max[]? collection = JsonSerializer.Deserialize<Shared.DataModels.RDS.Max[]>(json);
|
||||
if (collection is null)
|
||||
throw new NullReferenceException(nameof(collection));
|
||||
List<string[]> data = rdsMaxRepo.Convert(collection);
|
||||
Assert.IsTrue(data.Any());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user