92 lines
4.0 KiB
C#
92 lines
4.0 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
|
|
namespace Application.UnitTests.Repository
|
|
{
|
|
public class ProcessorHistoryRepositoryTest
|
|
{
|
|
private ApplicationDbContext _context;
|
|
private ProcessorHistoryRepository _repository;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
var mockDateTime = new DateTimeService();
|
|
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
|
|
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
|
|
{
|
|
Email = "[email protected]",
|
|
});
|
|
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
|
.EnableSensitiveDataLogging(true)
|
|
.Options;
|
|
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
|
|
_repository = new ProcessorHistoryRepository(_context);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Basic_Flow_test()
|
|
{
|
|
var res = await _repository.SaveProcessorRunHistory(new ProcessorHistoryRecord()
|
|
{
|
|
Process = Process.ImportCheckingAccountSalesFromDna,
|
|
LastSuccessfulRunTime = DateTime.Now,
|
|
LastProcessedRecordId = 5,
|
|
LastProcessedRecordTimestamp = DateTime.Now,
|
|
});
|
|
await _context.SaveChangesAsync();
|
|
Assert.NotNull(res);
|
|
Assert.AreEqual(res, Process.ImportCheckingAccountSalesFromDna);
|
|
|
|
res = await _repository.SaveProcessorRunHistory(new ProcessorHistoryRecord()
|
|
{
|
|
Process = Process.ImportGapMbpFromAlliedFile,
|
|
LastSuccessfulRunTime = DateTime.Parse("2021-04-05"),
|
|
LastProcessedRecordId = 3,
|
|
LastProcessedRecordTimestamp = DateTime.Parse("2021-04-05")
|
|
});
|
|
await _context.SaveChangesAsync();
|
|
Assert.NotNull(res);
|
|
Assert.AreEqual(Process.ImportGapMbpFromAlliedFile, res);
|
|
|
|
var list = await _repository.GetAllProcessorRunHistory();
|
|
Assert.NotNull(list);
|
|
Assert.AreEqual(2, list.Count);
|
|
|
|
//Saving existing Process causes update
|
|
res = await _repository.SaveProcessorRunHistory(new ProcessorHistoryRecord()
|
|
{
|
|
Process = Process.ImportGapMbpFromAlliedFile,
|
|
LastSuccessfulRunTime = DateTime.Parse("2021-05-08"),
|
|
LastProcessedRecordId = 200,
|
|
LastProcessedRecordTimestamp = DateTime.Parse("2021-05-07"),
|
|
});
|
|
await _context.SaveChangesAsync();
|
|
|
|
list = await _repository.GetAllProcessorRunHistory();
|
|
|
|
Assert.NotNull(list);
|
|
Assert.AreEqual(2, list.Count);
|
|
|
|
var updatedHistoryRecord = list.Find(x => x.Process == Process.ImportGapMbpFromAlliedFile);
|
|
Assert.AreEqual(200, updatedHistoryRecord.LastProcessedRecordId);
|
|
Assert.AreEqual(DateTime.Parse("2021-05-08"), updatedHistoryRecord.LastSuccessfulRunTime);
|
|
Assert.AreEqual(DateTime.Parse("2021-05-07"), updatedHistoryRecord.LastProcessedRecordTimestamp);
|
|
|
|
updatedHistoryRecord = await _repository.GetProcessorRunHistory(Process.ImportGapMbpFromAlliedFile);
|
|
Assert.AreEqual(200, updatedHistoryRecord.LastProcessedRecordId);
|
|
Assert.AreEqual(DateTime.Parse("2021-05-08"), updatedHistoryRecord.LastSuccessfulRunTime);
|
|
Assert.AreEqual(DateTime.Parse("2021-05-07"), updatedHistoryRecord.LastProcessedRecordTimestamp);
|
|
}
|
|
}
|
|
}
|