Files
2026-04-20 14:47:24 -05:00

99 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Collections.RepoApi.Services.AutoIms;
using LCU.Shared.Collections.RepoApiLib.Models;
using LCU.Shared.Collections.RepoApiLib.Repositories;
using Moq;
using Xunit;
namespace LCU.API.Collections.RepoApiTests.Processor
{
public class AutoImsNoteProcessorServiceTest
{
private readonly IAutoImsNoteProcessorService autoImsNoteProcessorService;
private readonly Mock<IAuctionAssignmentNoteRepository> mockAuctionAssignmentNoteRepository;
private readonly Mock<IUnitOfWork> mockUnitOfWork;
public AutoImsNoteProcessorServiceTest()
{
mockAuctionAssignmentNoteRepository = new Mock<IAuctionAssignmentNoteRepository>();
mockUnitOfWork = new Mock<IUnitOfWork>();
autoImsNoteProcessorService =
new AutoImsNoteProcessorService(mockAuctionAssignmentNoteRepository.Object, mockUnitOfWork.Object);
}
[Fact]
public void Basic_Construct_Test()
{
Assert.NotNull(autoImsNoteProcessorService);
}
[Fact]
public void Import_Notes_Test()
{
mockAuctionAssignmentNoteRepository.Setup(service =>
service.FindConflictingNotes(It.IsAny<DateTime>(), "test1", It.IsAny<string>()))
.Returns(Task.FromResult(CreateEmptyNotes())).Verifiable("Call find duplicate");
mockAuctionAssignmentNoteRepository.Setup(service =>
service.FindConflictingNotes(It.IsAny<DateTime>(), "test2", It.IsAny<string>()))
.Returns(Task.FromResult(CreateDummyNotes()));
mockAuctionAssignmentNoteRepository.Setup(service => service.AddAsync(It.IsAny<AuctionAssignmentNote>()))
.Verifiable("Call add note");
var notes = CreateDummyNotes();
var results = new List<AuctionAssignmentNote>();
foreach (var auctionAssignmentNote in notes)
{
var result = autoImsNoteProcessorService.ImportSingleNoteRow(auctionAssignmentNote);
if (result != null)
{
results.Add(result);
}
}
mockAuctionAssignmentNoteRepository.Verify(
foo => foo.FindConflictingNotes(It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()),
Times.Exactly(2));
mockAuctionAssignmentNoteRepository.Verify(foo => foo.AddAsync(It.IsAny<AuctionAssignmentNote>()),
Times.Exactly(1));
Assert.NotNull(results);
Assert.Equal(2, results.Count());
}
private IEnumerable<AuctionAssignmentNote> CreateEmptyNotes()
{
return new List<AuctionAssignmentNote>();
}
private IEnumerable<AuctionAssignmentNote> CreateDummyNotes()
{
return new[]
{
new AuctionAssignmentNote()
{
Text = "test1",
AuctionCustomerNo = "123456-789",
DateWritten = DateTime.Today,
Origin = "testing",
Writer = "tester",
Type = "XX",
AuctionAssignmentId = 12345
},
new AuctionAssignmentNote()
{
Text = "test2",
AuctionCustomerNo = "223456-789",
DateWritten = DateTime.Today,
Origin = "testing",
Writer = "tester",
Type = "XX",
AuctionAssignmentId = 12346
}
};
}
}
}