| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using Admin.NET.Plugin.AiDOP.DataPlatform.Executors;
- using Admin.NET.Plugin.AiDOP.DataPlatform.FileImport;
- using Admin.NET.Plugin.AiDOP.Entity.DataPlatform;
- using Xunit;
- namespace Admin.NET.Plugin.AiDOP.Tests.DataPlatform;
- public class MdpExcelValidationTests
- {
- [Fact]
- public void StripsClientTenant()
- {
- var raw = new Dictionary<string, object?> { ["Domain"] = "A", ["Customer"] = "C1", ["tenant_id"] = 999 };
- var maps = new List<MdpFieldMapping>
- {
- new() { SourceField = "Domain", TargetField = "Domain", IsRequired = 1, SortOrder = 1 },
- new() { SourceField = "Customer", TargetField = "Customer", IsRequired = 1, SortOrder = 2 },
- new() { SourceField = "tenant_id", TargetField = "tenant_id", IsRequired = 0, SortOrder = 3 }
- };
- var mapped = MdpExcelValidation.MapRow(raw, maps);
- Assert.False(mapped.ContainsKey("tenant_id"));
- Assert.Equal("A", mapped["Domain"]?.ToString());
- }
- [Fact]
- public void RequiredAndDuplicateHash()
- {
- var maps = new List<MdpFieldMapping>
- {
- new() { SourceField = "Domain", TargetField = "Domain", IsRequired = 1, SortOrder = 1 }
- };
- Assert.Throws<InvalidOperationException>(() => MdpExcelValidation.MapRow(new Dictionary<string, object?>(), maps));
- var a = MdpExcelValidation.RowHash(new Dictionary<string, object?> { ["Domain"] = "A" });
- var b = MdpExcelValidation.RowHash(new Dictionary<string, object?> { ["Domain"] = "A" });
- Assert.Equal(a, b);
- }
- [Fact]
- public void RejectsFormulaAndOversize()
- {
- Assert.Throws<InvalidOperationException>(() => MdpFileImportSecurity.EnsureCell("=1+1"));
- Assert.Throws<InvalidOperationException>(() => MdpFileImportSecurity.EnsureCell(new string('x', 2001)));
- }
- [Fact]
- public void FileSource_PullDispatcherRejected()
- {
- Assert.Throws<InvalidOperationException>(() =>
- {
- var source = new MdpSource { SourceType = "FILE_EXCEL" };
- if (string.Equals(source.SourceType, "FILE_EXCEL", StringComparison.OrdinalIgnoreCase))
- throw new InvalidOperationException("文件源不支持 Pull,请使用文件导入接口");
- });
- }
- [Fact]
- public void DbApiDispatcherSelectionUnchanged()
- {
- Assert.False(MdpExcelValidation.IsPullStage("TRANSFORM", "T"));
- Assert.True(MdpExcelValidation.IsPullStage("PULL", "P"));
- Assert.True(MdpExcelValidation.IsPullStage("EXTRACT", null));
- }
- [Fact]
- public void BizKeyIdempotent()
- {
- var mapped = new Dictionary<string, object?> { ["Domain"] = "D", ["Customer"] = "C" };
- Assert.Equal("D|C", MdpExcelValidation.BusinessKey("Domain,Customer", mapped));
- }
- }
- public class MdpExcelTemplateTests
- {
- [Fact]
- public void DefaultSheetName()
- {
- Assert.Equal("数据", MdpExcelTemplateService.ReadSheet(new MdpEntity()));
- Assert.Equal("客户", MdpExcelTemplateService.ReadSheet(new MdpEntity { FileConfigJson = "{\"sheetName\":\"客户\"}" }));
- }
- }
- public class MdpFileImportSecurityTests
- {
- [Fact]
- public void RejectsNonXlsx()
- {
- using var ms = new MemoryStream("notzip"u8.ToArray());
- Assert.Throws<InvalidOperationException>(() => MdpFileImportSecurity.EnsureXlsx("a.xls", ms.Length, ms));
- }
- }
- public class MdpExcelImportTests
- {
- [Fact]
- public void CommitStatuses()
- {
- Assert.Equal("READY", "READY");
- Assert.NotEqual("SUCCESS", "READY");
- }
- }
|