All checks were successful
ci/woodpecker/pr/merge_to_master Pipeline was successful
* In BroseCumulativeReport.Tests/AppTests.cs, consider adding more varied test cases for GetClosestSendingDate to cover edge cases and ensure the date is accurately calculated for all weekdays. * In ExcelGeneratorTests.cs, the SendEmail_ShouldSendEmailWithoutExceptions_WhenCalled test is only a placeholder without real assertions or mocks. It's recommended to refactor ExcelGenerator to inject an SMTP client and add mocks to test email sending properly, avoiding side effects. * In WzTests.cs, the assertion for WzNumber expects "WZ456" but the constructor input contains underscore "WZ_456". This is suspicious and should be clarified if the constructor removes underscores internally. If so, consider adding a comment or trimming whitespace explicitly. * Remove unnecessary comments such as "// TODO" without progress or address them to avoid clutter. * In all tests, consider using Theory + InlineData or MemberData attributes where applicable to simplify testing multiple inputs. These improvements will help ensure comprehensive and reliable testing aligned with professional standards.
69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using BroseCumulativeReport;
|
|
using BroseCumulativeReport.Model;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Moq;
|
|
using Xunit;
|
|
|
|
namespace BroseCumulativeReport.Tests
|
|
{
|
|
public class ExcelGeneratorTests
|
|
{
|
|
private readonly Mock<IConfiguration> _mockConfiguration = new();
|
|
|
|
public ExcelGeneratorTests()
|
|
{
|
|
// Setup mock IConfiguration behavior if needed
|
|
}
|
|
|
|
[Fact]
|
|
public void GenerateExcel_ShouldCreateFile_WhenProvidedValidInput()
|
|
{
|
|
// Arrange
|
|
var excelGenerator = new ExcelGenerator(_mockConfiguration.Object);
|
|
string tempFilePath = Path.GetTempFileName();
|
|
List<MainRow> mainRows = new List<MainRow>();
|
|
|
|
// Minimal MainRow data to avoid empty file scenario
|
|
mainRows.Add(new MainRow
|
|
{
|
|
CustomerName = "Customer",
|
|
CustomerOrderNumber = "Order1",
|
|
OrderNumber = "OrderNum",
|
|
OrderDate = DateTime.Today,
|
|
SalesChannelProductCode = "SCP",
|
|
ShipperProductCode = "SPC",
|
|
LastWzNumber = "WZ123",
|
|
WzQuantity = 1,
|
|
SendDatesWithQuantity = new List<(DateTime, int)> { (DateTime.Today, 1) },
|
|
ChildRows = new List<ChildRow>()
|
|
});
|
|
|
|
// Act
|
|
excelGenerator.GenerateExcel(tempFilePath, mainRows);
|
|
|
|
// Assert
|
|
Assert.True(File.Exists(tempFilePath));
|
|
|
|
// Cleanup
|
|
File.Delete(tempFilePath);
|
|
}
|
|
|
|
//[Fact]
|
|
// This test requires refactoring ExcelGenerator to allow injection of SMTP client
|
|
// to mock and verify sending logic without side effects.
|
|
//public void SendEmail_ShouldSendEmailWithoutExceptions_WhenCalled()
|
|
//{
|
|
// // Arrange
|
|
// var excelGenerator = new ExcelGenerator(_mockConfiguration.Object);
|
|
// string dummyFilePath = "dummyfile.xlsx";
|
|
|
|
// // Act & Assert
|
|
// var exception = Record.Exception(() => excelGenerator.SendEmail(dummyFilePath));
|
|
// Assert.Null(exception);
|
|
//}
|
|
}
|
|
}
|