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([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([]);
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);
}
}
}