1c546c111a
- Fix CriteriaSheetGenerator.FormatTimestamp to handle all DateTimeKind values - Update TestWebApplicationFactory to use IAuthenticationService - Add logger parameter to ExcelParserServiceTests - Add SecureStoreManager to solution under /utils/ folder
111 lines
4.4 KiB
C#
111 lines
4.4 KiB
C#
using JdeScoping.Core.Interfaces;
|
|
using JdeScoping.Infrastructure.Auth;
|
|
using JdeScoping.Core.Models;
|
|
using JdeScoping.Core.Models.Inventory;
|
|
using JdeScoping.Core.Models.Organization;
|
|
using JdeScoping.Core.Models.Search;
|
|
using JdeScoping.Core.Models.WorkOrders;
|
|
using JdeScoping.Core.ViewModels;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NSubstitute;
|
|
|
|
namespace JdeScoping.Api.IntegrationTests;
|
|
|
|
/// <summary>
|
|
/// Test web application factory for integration tests
|
|
/// </summary>
|
|
public class TestWebApplicationFactory : WebApplicationFactory<Program>
|
|
{
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
{
|
|
builder.UseEnvironment("Testing");
|
|
|
|
// Add test configuration with dummy connection strings
|
|
builder.ConfigureAppConfiguration((context, config) =>
|
|
{
|
|
config.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["ConnectionStrings:SqlServer"] = "Server=localhost;Database=TestDb;Trusted_Connection=true;",
|
|
["ConnectionStrings:JDE"] = "Data Source=localhost;User Id=test;Password=test;",
|
|
["ConnectionStrings:CMS"] = "Data Source=localhost;User Id=test;Password=test;",
|
|
["DataAccess:ConnectionStringName"] = "SqlServer",
|
|
["DataSource:JDE:ConnectionStringName"] = "JDE",
|
|
["DataSource:CMS:ConnectionStringName"] = "CMS"
|
|
});
|
|
});
|
|
|
|
builder.ConfigureServices(services =>
|
|
{
|
|
// Remove the real repository and add a mock
|
|
var repositoryDescriptor = services.SingleOrDefault(
|
|
d => d.ServiceType == typeof(ILotFinderRepository));
|
|
if (repositoryDescriptor != null)
|
|
{
|
|
services.Remove(repositoryDescriptor);
|
|
}
|
|
|
|
// Add mock repository
|
|
var mockRepository = CreateMockRepository();
|
|
services.AddSingleton(mockRepository);
|
|
|
|
// Ensure fake auth is used for tests
|
|
var authServiceDescriptor = services.SingleOrDefault(
|
|
d => d.ServiceType == typeof(IAuthenticationService));
|
|
if (authServiceDescriptor != null)
|
|
{
|
|
services.Remove(authServiceDescriptor);
|
|
}
|
|
services.AddSingleton<IAuthenticationService, FakeAuthService>();
|
|
});
|
|
}
|
|
|
|
private static ILotFinderRepository CreateMockRepository()
|
|
{
|
|
var repository = Substitute.For<ILotFinderRepository>();
|
|
|
|
// Setup default returns for search operations
|
|
repository.GetUserSearchesAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
|
.Returns(new List<Search>());
|
|
|
|
repository.GetQueuedSearchesAsync(Arg.Any<CancellationToken>())
|
|
.Returns(new List<Search>());
|
|
|
|
repository.GetSearchAsync(Arg.Any<int>(), Arg.Any<CancellationToken>())
|
|
.Returns((Search?)null);
|
|
|
|
repository.GetSearchResultsAsync(Arg.Any<int>(), Arg.Any<CancellationToken>())
|
|
.Returns((byte[]?)null);
|
|
|
|
repository.SubmitSearchAsync(Arg.Any<Search>(), Arg.Any<CancellationToken>())
|
|
.Returns(1);
|
|
|
|
// Setup default returns for lookup operations
|
|
repository.SearchItemsAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
|
.Returns(new List<Item>());
|
|
|
|
repository.SearchProfitCentersAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
|
.Returns(new List<ProfitCenter>());
|
|
|
|
repository.SearchWorkCentersAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
|
.Returns(new List<WorkCenter>());
|
|
|
|
repository.SearchUsersAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
|
.Returns(new List<JdeUser>());
|
|
|
|
// Setup default returns for file upload lookups
|
|
repository.LookupWorkordersAsync(Arg.Any<List<long>>(), Arg.Any<CancellationToken>())
|
|
.Returns(new List<WorkOrder>());
|
|
|
|
repository.LookupItemsAsync(Arg.Any<List<string>>(), Arg.Any<CancellationToken>())
|
|
.Returns(new List<Item>());
|
|
|
|
repository.LookupLotsAsync(Arg.Any<List<LotViewModel>>(), Arg.Any<CancellationToken>())
|
|
.Returns(new List<Lot>());
|
|
|
|
return repository;
|
|
}
|
|
}
|