Skip to content

Commit d6ecd53

Browse files
committed
Adding Project files
1 parent 986444f commit d6ecd53

25 files changed

+620
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<None Remove="Assets\Original\2.jpg" />
12+
<None Remove="Assets\Original\3.jpg" />
13+
<None Remove="Assets\Original\4.jpg" />
14+
<None Remove="Assets\Original\5.jpg" />
15+
<None Remove="Assets\Original\compressed.jpg" />
16+
<None Remove="Assets\Original\SmallImages\batman.png" />
17+
<None Remove="Assets\Original\SmallImages\shield.png" />
18+
<None Remove="Assets\Original\SmallImages\spiderman.png" />
19+
<None Remove="Assets\Original\spiderman_original.jpg" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<Content Include="Assets\Original\LargeImages\2.jpg">
24+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25+
</Content>
26+
<Content Include="Assets\Original\LargeImages\3.jpg">
27+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
28+
</Content>
29+
<Content Include="Assets\Original\LargeImages\4.jpg">
30+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
31+
</Content>
32+
<Content Include="Assets\Original\LargeImages\5.jpg">
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
</Content>
35+
<Content Include="Assets\Original\SmallImages\batman.png">
36+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
37+
</Content>
38+
<Content Include="Assets\Original\SmallImages\compressed.jpg">
39+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
40+
</Content>
41+
<Content Include="Assets\Original\LargeImages\spiderman_original.jpg">
42+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
43+
</Content>
44+
<Content Include="Assets\Original\SmallImages\shield.png">
45+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
46+
</Content>
47+
<Content Include="Assets\Original\SmallImages\spiderman.png">
48+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
49+
</Content>
50+
</ItemGroup>
51+
52+
<ItemGroup>
53+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
54+
<PackageReference Include="Moq" Version="4.18.1" />
55+
<PackageReference Include="NUnit" Version="3.13.2" />
56+
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
57+
<PackageReference Include="coverlet.collector" Version="3.1.0" />
58+
</ItemGroup>
59+
60+
<ItemGroup>
61+
<ProjectReference Include="..\AWSFileUploaderWithImageCompression\AWSFileUploaderWithImageCompression.csproj" />
62+
</ItemGroup>
63+
64+
<ItemGroup>
65+
<Folder Include="Assets\Compressed\" />
66+
</ItemGroup>
67+
68+
</Project>
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
using Amazon;
2+
using AWSFileUploaderWithImageCompression.Classes;
3+
using NUnit.Framework;
4+
using System;
5+
using System.IO;
6+
using System.Threading.Tasks;
7+
using System.Text.Json;
8+
using System.Text.Json.Serialization;
9+
using Moq;
10+
using AWSFileUploaderWithImageCompression.Interfaces;
11+
using Amazon.S3.Model;
12+
13+
namespace AWSFileUploaderWithImageCompression.Test
14+
{
15+
public class ImageServiceTest
16+
{
17+
private IImageService imgService;
18+
19+
[OneTimeSetUp]
20+
public void Setup()
21+
{
22+
//Mocking s3Uploader
23+
var s3Uploader = new Mock<IS3ImageUploader>();
24+
s3Uploader.Setup(s => s.UploadAsync(It.IsAny<Stream>(), It.IsAny<string>(), It.IsAny<string>(), null)).Returns(Task.FromResult(new PutObjectResponse() { HttpStatusCode = System.Net.HttpStatusCode.OK }));
25+
26+
imgService = new ImageService(s3Uploader.Object);
27+
}
28+
29+
30+
/// <summary>
31+
/// This will test the resize and compression of large image files.
32+
/// </summary>
33+
[Test, TestCaseSource(typeof(TestSourceProvider), nameof(TestSourceProvider.GetLargeImages))]
34+
public async Task CompressLargeImagesTestAsync(FileInfo originalFile)
35+
{
36+
//Arrange
37+
var outputDirectory = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "Assets", "Compressed")).FullName;
38+
if (!Directory.Exists(outputDirectory))
39+
Directory.CreateDirectory(outputDirectory);
40+
var outputFileName = Path.Combine(outputDirectory, Guid.NewGuid().ToString() + originalFile.Extension);
41+
42+
43+
//Act
44+
var result = await imgService.ImageCompressor.CompressImage(originalFile.FullName, outputFileName);
45+
var serializedResult = JsonSerializer.Serialize(result, new JsonSerializerOptions { WriteIndented = true });
46+
47+
//Assert
48+
if (result.ImageCompressionSucccess || (result.AfterCompressionSizeInBytes < result.OriginalSizeInBytes))
49+
Assert.Pass($"Successfully compressed the image\n-------------------------------------\nFileName: {originalFile.Name}\n{serializedResult}");
50+
else
51+
Assert.Fail($"Compression Failed!\n-------------------------------------\nFileName: {originalFile.Name}\n{serializedResult}");
52+
53+
}
54+
55+
/// <summary>
56+
/// This will test that no compression should be performed if the images are already smaller in size.
57+
/// </summary>
58+
[Test, TestCaseSource(typeof(TestSourceProvider), nameof(TestSourceProvider.GetSmallImages))]
59+
public async Task DontCompressSmallImageAsync(FileInfo originalFile)
60+
{
61+
//Arrange
62+
var outputDirectory = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "Assets", "Compressed")).FullName;
63+
if (!Directory.Exists(outputDirectory))
64+
Directory.CreateDirectory(outputDirectory);
65+
var outputFileName = Path.Combine(outputDirectory, Guid.NewGuid().ToString() + originalFile.Extension);
66+
67+
68+
//Act
69+
var result = await imgService.ImageCompressor.CompressImage(originalFile.FullName, outputFileName);
70+
var serializedResult = JsonSerializer.Serialize(result, new JsonSerializerOptions { WriteIndented = true });
71+
72+
//Assert
73+
Assert.IsTrue(result.ImageCompressionSucccess == false);
74+
}
75+
76+
/// <summary>
77+
/// This will test the if the watermark to the image has been applied successfully.
78+
/// </summary>
79+
[Test]
80+
public async Task WaterMarkTest()
81+
{
82+
//Arrange
83+
var watermarkImage = File.OpenRead(Path.Combine(Environment.CurrentDirectory, "Assets", "Original", "SmallImages", "spiderman.png"));
84+
var outputDirectory = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "Assets", "Watermark")).FullName;
85+
if (!Directory.Exists(outputDirectory))
86+
Directory.CreateDirectory(outputDirectory);
87+
var sourceFile = File.OpenRead(Path.Combine(Environment.CurrentDirectory, "Assets", "Original", "LargeImages", "2.jpg"));
88+
var outputFile = $"{Path.Combine(outputDirectory)}{Guid.NewGuid().ToString()}.jpg";
89+
90+
imgService.ImageCompressor.UpdateImageServiceConfiguration(new Classes.Models.ImgCompressorConfiguration
91+
{
92+
WaterMarkTransperency = 5 //50% transparency
93+
});
94+
95+
//Act
96+
var success = await imgService.ImageCompressor.AddWaterMark(sourceFile, watermarkImage, outputFile);
97+
98+
//Assert
99+
Assert.IsTrue(success);
100+
}
101+
102+
103+
104+
/// <summary>
105+
/// This will test the Compress and Upload
106+
/// </summary>
107+
[TestCase("2.jpg")]
108+
[TestCase("3.jpg")]
109+
[TestCase("4.jpg")]
110+
public async Task CompressAndUploadTest(string fileName)
111+
{
112+
var sourceFile = File.OpenRead(Path.Combine(Environment.CurrentDirectory, "Assets", "Original", "LargeImages", fileName));
113+
var resp = await imgService.CompressAndUploadImageAsync(sourceFile);
114+
115+
Assert.IsNotNull(resp);
116+
Assert.IsTrue(resp.HttpStatusCode == System.Net.HttpStatusCode.OK);
117+
}
118+
119+
120+
[OneTimeTearDown]
121+
public void ClearImages()
122+
{
123+
if (Directory.Exists(Path.Combine(Environment.CurrentDirectory, "Assets", "Compressed")))
124+
Directory.Delete(Path.Combine(Environment.CurrentDirectory, "Assets", "Compressed"), true);
125+
if (Directory.Exists(Path.Combine(Environment.CurrentDirectory, "Assets", "Watermark")))
126+
Directory.Delete(Path.Combine(Environment.CurrentDirectory, "Assets", "Watermark"), true);
127+
}
128+
}
129+
130+
131+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"AWSFileUploaderWithImageCompression.Test": {
4+
"commandName": "Project",
5+
"environmentVariables": {
6+
"SECRET_KEY": "JjCfT0dFvb5LmPK/GyQsO/e3hU685nC9RKN09Bag",
7+
"ACCESS_KEY": "AKIAWP4ZAOWDMMHNRIOV",
8+
"BUCKET_NAME": "svappyassets"
9+
}
10+
}
11+
}
12+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace AWSFileUploaderWithImageCompression.Test
9+
{
10+
public static class TestSourceProvider
11+
{
12+
public static FileInfo[] GetLargeImages()
13+
{
14+
return new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "Assets", "Original", "LargeImages")).GetFiles();
15+
}
16+
17+
public static FileInfo[] GetSmallImages()
18+
{
19+
return new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "Assets", "Original", "SmallImages")).GetFiles();
20+
}
21+
}
22+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.32421.90
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSFileUploaderWithImageCompression", "AWSFileUploaderWithImageCompression\AWSFileUploaderWithImageCompression.csproj", "{84E4CA04-3628-44E6-9F00-2696E89E4D27}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWSFileUploaderWithImageCompression.Test", "AWSFileUploaderWithImageCompression.Test\AWSFileUploaderWithImageCompression.Test.csproj", "{B827FA59-AC7E-46C3-8180-472A4A9D32D3}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{84E4CA04-3628-44E6-9F00-2696E89E4D27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{84E4CA04-3628-44E6-9F00-2696E89E4D27}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{84E4CA04-3628-44E6-9F00-2696E89E4D27}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{84E4CA04-3628-44E6-9F00-2696E89E4D27}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{B827FA59-AC7E-46C3-8180-472A4A9D32D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{B827FA59-AC7E-46C3-8180-472A4A9D32D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{B827FA59-AC7E-46C3-8180-472A4A9D32D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{B827FA59-AC7E-46C3-8180-472A4A9D32D3}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {4EAC9825-2B94-4151-9FB5-655C6F35C218}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<ApplicationIcon>uploaderIcon.ico</ApplicationIcon>
8+
<Version>1.0.1</Version>
9+
<Authors>Muthukumar Thevar</Authors>
10+
<Description>A library for compressing, adding watermark and uploading the file into aws s3.</Description>
11+
<PackageIcon>uploaderIcon.png</PackageIcon>
12+
<PackageReadmeFile>README.md</PackageReadmeFile>
13+
<RepositoryUrl>https://github.com/mak-thevar/AWSFileUploaderWithImageCompression</RepositoryUrl>
14+
<PackageProjectUrl>https://github.com/mak-thevar/AWSFileUploaderWithImageCompression</PackageProjectUrl>
15+
<RepositoryType>git</RepositoryType>
16+
<PackageLicenseFile>E:\GitHUb\AWSFileUploaderWithImageCompression\LICENSE</PackageLicenseFile>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<Content Include="uploaderIcon.ico" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<None Include="..\README.md">
25+
<Pack>True</Pack>
26+
<PackagePath>\</PackagePath>
27+
</None>
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<PackageReference Include="AWSSDK.S3" Version="3.7.9.2" />
32+
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="11.1.1" />
33+
</ItemGroup>
34+
35+
<ItemGroup>
36+
<None Update="uploaderIcon.png">
37+
<Pack>True</Pack>
38+
<PackagePath>\</PackagePath>
39+
</None>
40+
</ItemGroup>
41+
42+
</Project>

0 commit comments

Comments
 (0)