- Added ComplianceNFs.Infrastructure.Tests project to the solution. - Implemented unit tests for AccessDbRepository, ArchivingService, AttachmentRepository, InvoiceIngestionService, MailListener, MonitorViewModel, and Worker. - Enhanced existing tests with additional assertions and mock setups. - Updated TODOs and roadmap documentation to reflect changes in service implementations and testing coverage. - Modified ComplianceNFs.sln to include new test project and adjust solution properties.
63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using ComplianceNFs.Monitor;
|
|
using ComplianceNFs.Core.Entities;
|
|
using ComplianceNFs.Core.Application;
|
|
using Moq;
|
|
using Xunit;
|
|
|
|
namespace ComplianceNFs.Infrastructure.Tests
|
|
{
|
|
public class MonitorViewModelTests
|
|
{
|
|
[Fact]
|
|
public void Constructor_SubscribesToStatusStreamAndPopulatesRecentInvoices()
|
|
{
|
|
// Arrange
|
|
var mockStream = new Mock<IInvoiceStatusStream>();
|
|
var testInvoice = new EnergyInvoice
|
|
{
|
|
MailId = "mailid",
|
|
ConversationId = "convid",
|
|
SupplierEmail = "test@supplier.com",
|
|
ReceivedDate = DateTime.Now,
|
|
InvoiceId = 1,
|
|
Filename = "file.xml",
|
|
Status = InvoiceStatus.Validated
|
|
};
|
|
mockStream.Setup(s => s.GetRecent(It.IsAny<int>())).Returns(new[] { testInvoice });
|
|
var viewModel = new MonitorViewModel(mockStream.Object);
|
|
|
|
// Assert
|
|
Assert.Single(viewModel.RecentInvoices);
|
|
Assert.Equal("mailid", viewModel.RecentInvoices[0].MailId);
|
|
}
|
|
|
|
[Fact]
|
|
public void StatusUpdated_Event_AddsInvoiceToRecentInvoices()
|
|
{
|
|
// Arrange
|
|
var mockStream = new Mock<IInvoiceStatusStream>();
|
|
mockStream.Setup(s => s.GetRecent(It.IsAny<int>())).Returns(Array.Empty<EnergyInvoice>());
|
|
var viewModel = new MonitorViewModel(mockStream.Object);
|
|
var newInvoice = new EnergyInvoice
|
|
{
|
|
MailId = "newmailid",
|
|
ConversationId = "convid",
|
|
SupplierEmail = "test@supplier.com",
|
|
ReceivedDate = DateTime.Now,
|
|
InvoiceId = 2,
|
|
Filename = "file2.xml",
|
|
Status = InvoiceStatus.Validated
|
|
};
|
|
|
|
// Act
|
|
mockStream.Raise(s => s.StatusUpdated += null, newInvoice);
|
|
|
|
// Assert
|
|
Assert.Single(viewModel.RecentInvoices);
|
|
Assert.Equal("newmailid", viewModel.RecentInvoices[0].MailId);
|
|
}
|
|
}
|
|
}
|