Adding MaidBotApi
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
using LCU.Api.Internal.MaidBotLib.Models;
|
||||
using LCU.Api.Internal.MaidBotLib.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace LCU.Api.Internal.MaidBotTests.RepositoryTests
|
||||
{
|
||||
public class DbContextTestSet
|
||||
{
|
||||
public IReadOnlyCollection<LoggingMatrix> LoggingMatrixSet { get; set; }
|
||||
}
|
||||
|
||||
public abstract class DbContextFromJsonTest
|
||||
{
|
||||
public DbContextTestSet GetTestAccounts(string filePath)
|
||||
{
|
||||
var testSet = new DbContextTestSet();
|
||||
|
||||
// Get the absolute path to the JSON file
|
||||
var path = Path.IsPathRooted(filePath)
|
||||
? filePath
|
||||
: Path.GetRelativePath(Directory.GetCurrentDirectory(), filePath);
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
throw new ArgumentException($"Could not find file at path: {path}");
|
||||
}
|
||||
|
||||
var fileData = File.ReadAllText(filePath);
|
||||
var allData = JObject.Parse(fileData);
|
||||
|
||||
var runInfo = allData["LoggingMatrixs"];
|
||||
testSet.LoggingMatrixSet = runInfo?.ToObject<List<LoggingMatrix>>();
|
||||
|
||||
return testSet;
|
||||
}
|
||||
|
||||
public AppDbContext GetBlankContext()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
return new AppDbContext(options);
|
||||
}
|
||||
|
||||
public AppDbContext GetContextWithData(string jsonFileName)
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
var context = new AppDbContext(options);
|
||||
|
||||
var testData = GetTestAccounts(jsonFileName);
|
||||
AddTo(context.LoggingMatrixs, testData.LoggingMatrixSet);
|
||||
|
||||
context.SaveChanges();
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
private static void AddTo<T>(DbSet<T> collection, IEnumerable<T> range) where T : class
|
||||
{
|
||||
if (range != null) collection.AddRange(range);
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
using LCU.Api.Internal.MaidBotLib.Models;
|
||||
using LCU.Api.Internal.MaidBotLib.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.Api.Internal.MaidBotTests.RepositoryTests
|
||||
{
|
||||
public class LoggingMatrixRepositoryTest : DbContextFromJsonTest
|
||||
{
|
||||
private readonly LoggingMatrixRepository _loggingMatrixRepository;
|
||||
private const string JsonTestDataFilePath = "RepositoryTests\\LoggingMatrixTestData.json";
|
||||
|
||||
public LoggingMatrixRepositoryTest()
|
||||
{
|
||||
var dbContext = GetContextWithData(JsonTestDataFilePath);
|
||||
_loggingMatrixRepository = new LoggingMatrixRepository(dbContext);
|
||||
}
|
||||
|
||||
//TODO: These UnitTest have been commented out since there is version mismatch and at this time
|
||||
// we are not going to undergo the work that is required to upgrade. The work to upgrade
|
||||
// the .net version will need to be done in a separate Story:
|
||||
// 89988 Maidbot API > Library Modernization
|
||||
// https://landmarkcu.visualstudio.com/LMCU/_boards/board/t/Development/Stories?workitem=89988.
|
||||
// This decision was made during this PR:
|
||||
// https://landmarkcu.visualstudio.com/Platform/_git/LCU.API.Internal.MaidBotApi/pullrequest/17634
|
||||
//[Fact]
|
||||
//public void ListAsync_Test()
|
||||
//{
|
||||
// var loggingMatrixes = _loggingMatrixRepository.ListAsync().Result;
|
||||
// Assert.NotNull(loggingMatrixes);
|
||||
// Assert.Equal(6, loggingMatrixes.Count());
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public async void FindById_Test()
|
||||
//{
|
||||
// var loggingMatrix = await _loggingMatrixRepository.FindByIdAsync(1);
|
||||
// Assert.NotNull(loggingMatrix);
|
||||
// Assert.Equal(1, loggingMatrix.LoggingMatrixId);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public void RetrieveByApplicationLevelAndGroup_Test()
|
||||
//{
|
||||
// var application = "Test App 1";
|
||||
// var group = "Test Group 1";
|
||||
// var level = "Test Level 1";
|
||||
// var loggingMatrixes = _loggingMatrixRepository.RetrieveByApplicationLevelAndGroup(application, level, group ).Result;
|
||||
// Assert.NotNull(loggingMatrixes);
|
||||
// Assert.Equal(2, loggingMatrixes.Count());
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public void RetrieveByApplciationAndLevel_Test()
|
||||
//{
|
||||
// var application = "Test App 1";
|
||||
// var level = "Test Level 1";
|
||||
// var loggingMatrixes = _loggingMatrixRepository.RetrieveByApplciationAndLevel(application, level).Result;
|
||||
// Assert.NotNull(loggingMatrixes);
|
||||
// Assert.Equal(3, loggingMatrixes.Count());
|
||||
//}
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"LoggingMatrixs": [
|
||||
{
|
||||
"LoggingmatrixId": 1,
|
||||
"Application": "Test App 1",
|
||||
"Level": "Test Level 1",
|
||||
"Group": "Test Group 1",
|
||||
"Email": "[email protected]",
|
||||
"Disabled": false
|
||||
},
|
||||
{
|
||||
"LoggingmatrixId": 2,
|
||||
"Application": "Test App 2",
|
||||
"Level": "Test Level 2",
|
||||
"Group": "Test Group 2",
|
||||
"Email": "[email protected]",
|
||||
"Disabled": false
|
||||
},
|
||||
{
|
||||
"LoggingmatrixId": 3,
|
||||
"Application": "Test App 3",
|
||||
"Level": "Test Level 3",
|
||||
"Group": "Test Group 3",
|
||||
"Email": "[email protected]",
|
||||
"Disabled": true
|
||||
},
|
||||
{
|
||||
"LoggingmatrixId": 4,
|
||||
"Application": "Test App 1",
|
||||
"Level": "Test Level 1",
|
||||
"Group": "Test Group 1",
|
||||
"Email": "[email protected]",
|
||||
"Disabled": false
|
||||
},
|
||||
{
|
||||
"LoggingmatrixId": 5,
|
||||
"Application": "Test App 1",
|
||||
"Level": "Test Level 1",
|
||||
"Group": "Test Group 1",
|
||||
"Email": "[email protected]",
|
||||
"Disabled": true
|
||||
},
|
||||
{
|
||||
"LoggingmatrixId": 6,
|
||||
"Application": "Test App 1",
|
||||
"Level": "Test Level 1",
|
||||
"Group": "Test Group 6",
|
||||
"Email": "[email protected]",
|
||||
"Disabled": false
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user