71 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| //using DomainResults.Common;
 | |
| 
 | |
| //using Microsoft.Extensions.Logging;
 | |
| //using Core.Enumerations;
 | |
| //using ObjectStorageProvider;
 | |
| 
 | |
| 
 | |
| //namespace CoreTests.FakeServices {
 | |
| //  public class ObjectStorageFakeService : IObjectStorageFileService {
 | |
| 
 | |
| //    private readonly ILogger<ObjectStorageFakeService> _logger;
 | |
| //    private Dictionary<string, Dictionary<string, byte[]>> _collection;
 | |
| 
 | |
| //    /// <summary>
 | |
| //    /// Dictionary<bucketName, Dictionary<objectName, content)>
 | |
| //    /// </summary>
 | |
| //    /// <param name="logger"></param>
 | |
| //    /// <param name="collection">Dictionary<objectName, (bucketName, content)></param>
 | |
| //    public ObjectStorageFakeService(
 | |
| //      ILogger<ObjectStorageFakeService> logger,
 | |
| //      Dictionary<string, Dictionary<string, byte[]>> collection
 | |
| //    ) {
 | |
| //      _logger = logger;
 | |
| //      _collection = collection;
 | |
| //    }
 | |
| 
 | |
| //    public (byte[]?, IDomainResult) FileDownload(string bucketName, string objectName) =>
 | |
| //      FileDownloadAsync(bucketName, objectName).Result;
 | |
| 
 | |
| //    public Task<(byte[]?, IDomainResult)> FileDownloadAsync(string bucketName, string objectName) =>
 | |
| //      Task.Run(() => {
 | |
| //        Dictionary<string, byte[]>? bucket;
 | |
| //        _collection.TryGetValue(bucketName, out bucket);
 | |
| 
 | |
| //        if (bucket == null)
 | |
| //          return IDomainResult.Failed<byte[]?>();
 | |
| 
 | |
| //        byte[]? content;
 | |
| //        bucket.TryGetValue(objectName, out content);
 | |
| 
 | |
| //        if (content == null)
 | |
| //          return IDomainResult.Failed<byte[]?>();
 | |
| 
 | |
| //        return IDomainResult.Success(content);
 | |
| //      });
 | |
| 
 | |
| //    public (string?, IDomainResult) FileUpload(string bucketName, byte[] bytes, string contentType, string location = "us-east-1", bool force = false) {
 | |
| //      throw new NotImplementedException();
 | |
| //    }
 | |
| 
 | |
| //    public (string?, IDomainResult) FileUpload(string bucketName, byte[] bytes, FileExtension fileExtension, string location = "us-east-1", bool force = false) =>
 | |
| //      FileUploadAsync(bucketName, bytes, fileExtension, location, force).Result;
 | |
| 
 | |
| //    public Task<(string?, IDomainResult)> FileUploadAsync(string bucketName, byte[] bytes, string contentType, string location = "us-east-1", bool force = false) {
 | |
| //      throw new NotImplementedException();
 | |
| //    }
 | |
| 
 | |
| //    public Task<(string?, IDomainResult)> FileUploadAsync(string bucketName, byte[] bytes, FileExtension fileExtension, string location = "us-east-1", bool force = false) =>
 | |
| //      Task.Run(() => {
 | |
| //        var objName = $"{Guid.NewGuid()}{fileExtension.Id}";
 | |
| 
 | |
| //        if (!_collection.ContainsKey(bucketName))
 | |
| //          _collection.Add(bucketName, new Dictionary<string, byte[]>());
 | |
| 
 | |
| //        _collection[bucketName].Add(objName, bytes);
 | |
| 
 | |
| //        return IDomainResult.Success<string?>(objName);
 | |
| //      });
 | |
| //  }
 | |
| //}
 |