|
| 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 | +} |
0 commit comments