Skip to content

Commit

Permalink
New tests that use .png and .webp images
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Matthews committed May 3, 2022
1 parent 3c740d6 commit 9ea9861
Showing 1 changed file with 42 additions and 21 deletions.
63 changes: 42 additions & 21 deletions NsfwSpy.Test/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ namespace NsfwSpyNS.Test
{
public class UnitTests
{
[Fact]
public void ClassifyImageByteArray_ValidByteArray()
[Theory]
[InlineData("flower.jpg")]
[InlineData("flower.png")]
[InlineData("flower.webp")]
public void ClassifyImageByteArray_ValidByteArray(string filename)
{
var filePath = Path.Combine(AppContext.BaseDirectory, @"Assets/flower.jpg");
var filePath = Path.Combine(AppContext.BaseDirectory, $@"Assets/{filename}");
var imageBytes = File.ReadAllBytes(filePath);

var nsfwSpy = new NsfwSpy();
Expand All @@ -28,21 +31,27 @@ public void ClassifyImageByteArray_InvalidByteArray()
Assert.Throws<ClassificationFailedException>(() => nsfwSpy.ClassifyImage(new byte[0]));
}

[Fact]
public void ClassifyImageUri_ValidUri()
[Theory]
[InlineData("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.jpg")]
[InlineData("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.png")]
[InlineData("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.webp")]
public void ClassifyImageUri_ValidUri(string url)
{
var uri = new Uri("https://pbs.twimg.com/profile_images/883859744498176000/pjEHfbdn_400x400.jpg");
var uri = new Uri(url);

var nsfwSpy = new NsfwSpy();
var result = nsfwSpy.ClassifyImage(uri);

Assert.Equal("Neutral", result.PredictedLabel);
}

[Fact]
public void ClassifyImageUri_CustomWebClient()
[Theory]
[InlineData("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.jpg")]
[InlineData("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.png")]
[InlineData("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.webp")]
public void ClassifyImageUri_CustomWebClient(string url)
{
var uri = new Uri("https://pbs.twimg.com/profile_images/883859744498176000/pjEHfbdn_400x400.jpg");
var uri = new Uri(url);
var webClient = new WebClient();
webClient.Headers["User-Agent"] = "test";

Expand All @@ -52,10 +61,13 @@ public void ClassifyImageUri_CustomWebClient()
Assert.Equal("Neutral", result.PredictedLabel);
}

[Fact]
public void ClassifyImageFilePath_ValidFilePath()
[Theory]
[InlineData("flower.jpg")]
[InlineData("flower.png")]
[InlineData("flower.webp")]
public void ClassifyImageFilePath_ValidFilePath(string filename)
{
var filePath = Path.Combine(AppContext.BaseDirectory, @"Assets/flower.jpg");
var filePath = Path.Combine(AppContext.BaseDirectory, $@"Assets/{filename}");

var nsfwSpy = new NsfwSpy();
var result = nsfwSpy.ClassifyImage(filePath);
Expand All @@ -72,21 +84,27 @@ public void ClassifyImageFilePath_InvalidFilePath()
Assert.Throws<FileNotFoundException>(() => nsfwSpy.ClassifyImage(filePath));
}

[Fact]
public async Task ClassifyImageUriAsync_ValidUri()
[Theory]
[InlineData("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.jpg")]
[InlineData("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.png")]
[InlineData("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.webp")]
public async Task ClassifyImageUriAsync_ValidUri(string url)
{
var uri = new Uri("https://pbs.twimg.com/profile_images/883859744498176000/pjEHfbdn_400x400.jpg");
var uri = new Uri(url);

var nsfwSpy = new NsfwSpy();
var result = await nsfwSpy.ClassifyImageAsync(uri);

Assert.Equal("Neutral", result.PredictedLabel);
}

[Fact]
public async Task ClassifyImageUriAsync_CustomWebClient()
[Theory]
[InlineData("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.jpg")]
[InlineData("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.png")]
[InlineData("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.webp")]
public async Task ClassifyImageUriAsync_CustomWebClient(string url)
{
var uri = new Uri("https://pbs.twimg.com/profile_images/883859744498176000/pjEHfbdn_400x400.jpg");
var uri = new Uri(url);
var webClient = new WebClient();
webClient.Headers["User-Agent"] = "test";

Expand All @@ -96,10 +114,13 @@ public async Task ClassifyImageUriAsync_CustomWebClient()
Assert.Equal("Neutral", result.PredictedLabel);
}

[Fact]
public async Task ClassifyImageFilePathAsync_ValidFilePath()
[Theory]
[InlineData("flower.jpg")]
[InlineData("flower.png")]
[InlineData("flower.webp")]
public async Task ClassifyImageFilePathAsync_ValidFilePath(string filename)
{
var filePath = Path.Combine(AppContext.BaseDirectory, @"Assets/flower.jpg");
var filePath = Path.Combine(AppContext.BaseDirectory, $@"Assets/{filename}");

var nsfwSpy = new NsfwSpy();
var result = await nsfwSpy.ClassifyImageAsync(filePath);
Expand Down

0 comments on commit 9ea9861

Please sign in to comment.