242 lines
6.5 KiB
C#
242 lines
6.5 KiB
C#
// using System;
|
|
// using System.IO;
|
|
// using System.Threading.Tasks;
|
|
// using CamBooth.App.Core.AppSettings;
|
|
// using CamBooth.App.Core.Logging;
|
|
// using CamBooth.App.Features.LycheeUpload;
|
|
//
|
|
// namespace CamBooth.Tests.Features.LycheeUpload;
|
|
//
|
|
// /// <summary>
|
|
// /// Example Unit Tests for LycheeUploadService
|
|
// /// Note: Requires a running Lychee instance for integration tests
|
|
// /// </summary>
|
|
// public class LycheeUploadServiceTests
|
|
// {
|
|
// private readonly Logger _logger;
|
|
// private readonly AppSettingsService _appSettings;
|
|
// private LycheeUploadService _service;
|
|
//
|
|
// public LycheeUploadServiceTests()
|
|
// {
|
|
// _logger = new Logger(null);
|
|
// _appSettings = new AppSettingsService(_logger);
|
|
// _service = new LycheeUploadService(_appSettings, _logger);
|
|
// }
|
|
//
|
|
// // Unit Test: Authentication
|
|
// public async Task TestAuthentication()
|
|
// {
|
|
// Console.WriteLine("Testing Lychee Authentication...");
|
|
//
|
|
// var result = await _service.AuthenticateAsync();
|
|
//
|
|
// if (result)
|
|
// {
|
|
// Console.WriteLine("✅ Authentication successful");
|
|
// Console.WriteLine($" IsAuthenticated: {_service.IsAuthenticated}");
|
|
// }
|
|
// else
|
|
// {
|
|
// Console.WriteLine("❌ Authentication failed");
|
|
// }
|
|
// }
|
|
//
|
|
// // Unit Test: Single Image Upload
|
|
// public async Task TestSingleImageUpload()
|
|
// {
|
|
// Console.WriteLine("\nTesting Single Image Upload...");
|
|
//
|
|
// // Authenticate first
|
|
// await _service.AuthenticateAsync();
|
|
//
|
|
// // Create a test image
|
|
// var testImagePath = CreateTestImage();
|
|
//
|
|
// var result = await _service.UploadImageAsync(testImagePath);
|
|
//
|
|
// if (result)
|
|
// {
|
|
// Console.WriteLine("✅ Image upload successful");
|
|
// }
|
|
// else
|
|
// {
|
|
// Console.WriteLine("❌ Image upload failed");
|
|
// }
|
|
//
|
|
// // Cleanup
|
|
// if (File.Exists(testImagePath))
|
|
// {
|
|
// File.Delete(testImagePath);
|
|
// }
|
|
// }
|
|
//
|
|
// // Unit Test: Batch Upload
|
|
// public async Task TestBatchUpload()
|
|
// {
|
|
// Console.WriteLine("\nTesting Batch Image Upload...");
|
|
//
|
|
// // Authenticate first
|
|
// await _service.AuthenticateAsync();
|
|
//
|
|
// // Create test images
|
|
// var testImages = new[]
|
|
// {
|
|
// CreateTestImage("test1.jpg"),
|
|
// CreateTestImage("test2.jpg"),
|
|
// CreateTestImage("test3.jpg")
|
|
// };
|
|
//
|
|
// var successCount = await _service.UploadImagesAsync(testImages);
|
|
//
|
|
// Console.WriteLine($" Uploaded: {successCount}/{testImages.Length} images");
|
|
//
|
|
// if (successCount == testImages.Length)
|
|
// {
|
|
// Console.WriteLine("✅ Batch upload successful");
|
|
// }
|
|
// else
|
|
// {
|
|
// Console.WriteLine($"⚠️ Partial success: {successCount}/{testImages.Length}");
|
|
// }
|
|
//
|
|
// // Cleanup
|
|
// foreach (var image in testImages)
|
|
// {
|
|
// if (File.Exists(image))
|
|
// {
|
|
// File.Delete(image);
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// // Unit Test: Album Creation
|
|
// public async Task TestAlbumCreation()
|
|
// {
|
|
// Console.WriteLine("\nTesting Album Creation...");
|
|
//
|
|
// // Authenticate first
|
|
// await _service.AuthenticateAsync();
|
|
//
|
|
// var albumName = $"Test Album {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
|
|
// var albumId = await _service.CreateAlbumAsync(albumName);
|
|
//
|
|
// if (albumId != null)
|
|
// {
|
|
// Console.WriteLine($"✅ Album created successfully");
|
|
// Console.WriteLine($" Album ID: {albumId}");
|
|
// }
|
|
// else
|
|
// {
|
|
// Console.WriteLine("❌ Album creation failed");
|
|
// }
|
|
// }
|
|
//
|
|
// // Unit Test: Upload to Specific Album
|
|
// public async Task TestUploadToAlbum()
|
|
// {
|
|
// Console.WriteLine("\nTesting Upload to Specific Album...");
|
|
//
|
|
// // Authenticate first
|
|
// await _service.AuthenticateAsync();
|
|
//
|
|
// // Create test album
|
|
// var albumName = $"Test Album {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
|
|
// var albumId = await _service.CreateAlbumAsync(albumName);
|
|
//
|
|
// if (albumId == null)
|
|
// {
|
|
// Console.WriteLine("❌ Failed to create test album");
|
|
// return;
|
|
// }
|
|
//
|
|
// // Upload image to album
|
|
// var testImagePath = CreateTestImage();
|
|
// var result = await _service.UploadImageAsync(testImagePath, albumId);
|
|
//
|
|
// if (result)
|
|
// {
|
|
// Console.WriteLine($"✅ Image uploaded to album successfully");
|
|
// Console.WriteLine($" Album ID: {albumId}");
|
|
// }
|
|
// else
|
|
// {
|
|
// Console.WriteLine("❌ Upload to album failed");
|
|
// }
|
|
//
|
|
// // Cleanup
|
|
// if (File.Exists(testImagePath))
|
|
// {
|
|
// File.Delete(testImagePath);
|
|
// }
|
|
// }
|
|
//
|
|
// // Unit Test: Logout
|
|
// public async Task TestLogout()
|
|
// {
|
|
// Console.WriteLine("\nTesting Logout...");
|
|
//
|
|
// // Authenticate first
|
|
// await _service.AuthenticateAsync();
|
|
// Console.WriteLine($" Before logout - IsAuthenticated: {_service.IsAuthenticated}");
|
|
//
|
|
// // Logout
|
|
// await _service.LogoutAsync();
|
|
// Console.WriteLine($" After logout - IsAuthenticated: {_service.IsAuthenticated}");
|
|
//
|
|
// if (!_service.IsAuthenticated)
|
|
// {
|
|
// Console.WriteLine("✅ Logout successful");
|
|
// }
|
|
// else
|
|
// {
|
|
// Console.WriteLine("❌ Logout failed");
|
|
// }
|
|
// }
|
|
//
|
|
// // Helper: Create a test image
|
|
// private string CreateTestImage(string fileName = "test_image.jpg")
|
|
// {
|
|
// var tempPath = Path.Combine(Path.GetTempPath(), fileName);
|
|
//
|
|
// // Create a simple 1x1 pixel JPEG (base64 encoded minimal JPEG)
|
|
// var minimalJpeg = Convert.FromBase64String(
|
|
// "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAv/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAAAAX/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCwAA8A/9k="
|
|
// );
|
|
//
|
|
// File.WriteAllBytes(tempPath, minimalJpeg);
|
|
// return tempPath;
|
|
// }
|
|
//
|
|
// // Run all tests
|
|
// public static async Task RunAllTests()
|
|
// {
|
|
// Console.WriteLine("=== Lychee Upload Service Tests ===\n");
|
|
//
|
|
// var tests = new LycheeUploadServiceTests();
|
|
//
|
|
// try
|
|
// {
|
|
// await tests.TestAuthentication();
|
|
// await tests.TestSingleImageUpload();
|
|
// await tests.TestBatchUpload();
|
|
// await tests.TestAlbumCreation();
|
|
// await tests.TestUploadToAlbum();
|
|
// await tests.TestLogout();
|
|
//
|
|
// Console.WriteLine("\n=== All tests completed ===");
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Console.WriteLine($"\n❌ Test error: {ex.Message}");
|
|
// }
|
|
// finally
|
|
// {
|
|
// tests._service.Dispose();
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// // Example usage in Program.cs or test runner:
|
|
// // await LycheeUploadServiceTests.RunAllTests();
|