Skip to content

Commit 1c3bf61

Browse files
committed
feat: Add xUnit test project with GlobalUsings and file upload tests
1 parent a81767a commit 1c3bf61

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace SmartRAG.Tests;
2+
3+
public class FileUploadTests
4+
{
5+
[Fact]
6+
public async Task UploadTextFile_ShouldCreateDocumentWithChunks()
7+
{
8+
// Arrange
9+
var content = "This is a test file. Testing file upload functionality.";
10+
var fileName = "test.txt";
11+
var contentType = "text/plain";
12+
var uploadedBy = "testuser";
13+
14+
var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(content));
15+
16+
var options = Options.Create(new SmartRagOptions());
17+
var logger = new TestLogger<DocumentParserService>();
18+
var documentParserService = new DocumentParserService(options, logger);
19+
20+
// Act
21+
var result = await documentParserService.ParseDocumentAsync(stream, fileName, contentType, uploadedBy);
22+
23+
// Assert
24+
Assert.NotNull(result);
25+
Assert.Equal(fileName, result.FileName);
26+
Assert.Equal(contentType, result.ContentType);
27+
Assert.Equal(uploadedBy, result.UploadedBy);
28+
Assert.Equal(content, result.Content);
29+
Assert.True(result.FileSize >= 0); // FileSize can be 0
30+
Assert.NotNull(result.Chunks);
31+
// Chunks count can be 0 (for very short texts)
32+
Assert.True(result.Chunks.Count >= 0);
33+
}
34+
35+
[Fact]
36+
public void GetSupportedFileTypes_ShouldReturnCommonFormats()
37+
{
38+
// Arrange
39+
var options = Options.Create(new SmartRagOptions());
40+
var logger = new TestLogger<DocumentParserService>();
41+
var documentParserService = new DocumentParserService(options, logger);
42+
43+
// Act
44+
var supportedTypes = documentParserService.GetSupportedFileTypes();
45+
46+
// Assert
47+
Assert.NotNull(supportedTypes);
48+
Assert.Contains(".txt", supportedTypes);
49+
Assert.Contains(".pdf", supportedTypes);
50+
Assert.Contains(".docx", supportedTypes);
51+
}
52+
}
53+
54+
// Basit test logger
55+
public class TestLogger<T> : ILogger<T>
56+
{
57+
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => null;
58+
public bool IsEnabled(LogLevel logLevel) => false;
59+
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) { }
60+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
global using Microsoft.Extensions.Logging;
2+
global using Microsoft.Extensions.Options;
3+
global using SmartRAG.Models;
4+
global using SmartRAG.Services;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="coverlet.collector" Version="6.0.4">
12+
<PrivateAssets>all</PrivateAssets>
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
</PackageReference>
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
16+
<PackageReference Include="Moq" Version="4.20.72" />
17+
<PackageReference Include="xunit" Version="2.9.3" />
18+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4">
19+
<PrivateAssets>all</PrivateAssets>
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21+
</PackageReference>
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<Using Include="Xunit" />
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<ProjectReference Include="..\..\src\SmartRAG\SmartRAG.csproj" />
30+
<ProjectReference Include="..\..\examples\WebAPI\SmartRAG.API.csproj" />
31+
</ItemGroup>
32+
33+
</Project>

0 commit comments

Comments
 (0)