Adding unit tests
This commit is contained in:
99
MarketDataUnitTests/MarketDataUnitTestClass.cs
Normal file
99
MarketDataUnitTests/MarketDataUnitTestClass.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.Generator.CMMomentum;
|
||||
using MarketData.Helper;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Utils;
|
||||
using MarketData;
|
||||
using MarketData.Configuration;
|
||||
using System.Diagnostics;
|
||||
|
||||
|
||||
namespace MarketDataUnitTests;
|
||||
|
||||
[TestClass]
|
||||
public class MarketDataUnitTestClass
|
||||
{
|
||||
private IConfigurationBuilder builder = default;
|
||||
private IConfiguration configuration = default;
|
||||
|
||||
public MarketDataUnitTestClass()
|
||||
{
|
||||
builder = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
||||
IConfigurationRoot configurationRoot = builder.Build();
|
||||
configuration = configurationRoot;
|
||||
GlobalConfig.Instance.Configuration = configuration;
|
||||
CreateLogging("unittest");
|
||||
|
||||
}
|
||||
|
||||
private static bool CreateLogging(String task)
|
||||
{
|
||||
if(String.IsNullOrEmpty(task))return false;
|
||||
task=task.ToLower();
|
||||
MDTrace.LogLevel = LogLevel.DEBUG;
|
||||
String logFolder = "/logs";
|
||||
DateTime currentDate=DateTime.Now;
|
||||
String strLogFile = "marketdata_" + task + ".log";
|
||||
String currentWorkingDirectory = Directory.GetCurrentDirectory();
|
||||
Console.WriteLine($"Current directory is {currentWorkingDirectory}");
|
||||
Utility.EnsureLogFolder(currentWorkingDirectory+logFolder);
|
||||
Utility.ExpireLogs(currentWorkingDirectory+logFolder,1);
|
||||
Trace.Listeners.Remove("Default");
|
||||
Console.WriteLine($"Adding Trace Listener :{currentWorkingDirectory+logFolder+"/"+strLogFile}");
|
||||
Trace.Listeners.Add(new TextWriterTraceListener(currentWorkingDirectory+logFolder+"/"+strLogFile));
|
||||
MDTrace.WriteLine($"Trace Listener added.");
|
||||
Utility.ShowLogs(currentWorkingDirectory + logFolder);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void CNNPredictionTest()
|
||||
{
|
||||
String cnnHostName = "10.0.0.240";
|
||||
CMCandidate cmCandidate = new CMCandidate();
|
||||
CMParams cmParams = new CMParams();
|
||||
|
||||
cmParams.UseCNN = true;
|
||||
cmParams.UseCNNHost = "http://" + cnnHostName + ":5000";
|
||||
cmParams.UseCNNDayCount = 270;
|
||||
cmParams.UseCNNRewardPercentDecimal = 0.25;
|
||||
|
||||
cmCandidate.Symbol = "MIDD";
|
||||
cmCandidate.TradeDate = DateTime.Parse("07-01-2024");
|
||||
|
||||
bool result = CMMomentumGenerator.PredictCandidate(cmCandidate, cmParams);
|
||||
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ETFHoldingsYahooRetrieval()
|
||||
{
|
||||
String[] etfSymbols = { "JFNNX", "ACWX", "ACES", "BBH" };
|
||||
List<ETFHoldings> results = new List<ETFHoldings>();
|
||||
|
||||
foreach (String etfSymbol in etfSymbols)
|
||||
{
|
||||
ETFHoldings etfHoldings = MarketDataHelper.GetETFHoldings(etfSymbol);
|
||||
if (null != etfHoldings && 0 != etfHoldings.Count)
|
||||
{
|
||||
results.Add(MarketDataHelper.GetETFHoldings(etfSymbol));
|
||||
}
|
||||
try { Thread.Sleep(500); } catch (Exception) {; }
|
||||
}
|
||||
Assert.IsTrue(results.Any(x => x != null), String.Format("{0} items failed.", etfSymbols.Length));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void LatestPriceRetrieval()
|
||||
{
|
||||
String symbol="AAPL";
|
||||
Price price=MarketDataHelper.GetLatestPrice(symbol);
|
||||
Assert.IsTrue(null!=price && price.IsValid);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user