Skip to content

Commit

Permalink
Test namespace changed and new ImagesNotFound test added to the pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
caraplana1 committed Aug 4, 2024
1 parent 16db108 commit 11fb3aa
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 24 deletions.
3 changes: 3 additions & 0 deletions ComicConverter/ComicBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public static void CreatePdf(string[] imagesPaths, string fileName)
|| f.EndsWith(".JPEG", StringComparison.OrdinalIgnoreCase)
|| f.EndsWith(".JPG", StringComparison.OrdinalIgnoreCase)).ToArray();

if (imagesPaths.Length is 0)
throw new IOException();

PdfDocument document = new();
document.Info.Title = fileName.Replace('\\', '/').Split('/').Last();

Expand Down
4 changes: 2 additions & 2 deletions Tests/ComicConverter.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Test;
using Xunit;
using System;
using System.IO;
using ComicConverter;
using ComicConverter.Enums;

namespace Test
namespace Tests
{
public class ComicConverter
{
Expand Down Expand Up @@ -70,7 +71,6 @@ public void OutInvalidFormat()
public void InInvalidFormat()
{
Comic comic;

Assert.Throws<FormatException>(() => comic = new(Samples.Testpath));
}
}
Expand Down
10 changes: 6 additions & 4 deletions Tests/ComicCreators/CbtFiles.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using Test;
using Xunit;
using System;
using System.IO;
using ComicConverter;

namespace Test.ComicCreators
namespace Tests.ComicCreators
{
public class CbtFiles
{
private const string CbtPath = "CreatedCbtFileTest";

[Fact]
public void CreateCbt()
{
Expand All @@ -23,9 +25,9 @@ public void CreateCbt()
[Fact]
public void ImagesNotFound()
{
string[] fakeFiles = ["fakefile1.jpg", "fakefile2.jpg", "fakefile3.jpg"];
string[] files = ["fakefile.jpg", "fakefile1.jpg", "fakefile2.jpg"];

Assert.Throws<IOException>(() => ComicBuilder.CreateCbt(fakeFiles, CbtPath));
Assert.Throws<IOException>(() => ComicBuilder.CreateCbt(files, CbtPath));
}
}
}
4 changes: 3 additions & 1 deletion Tests/ComicCreators/CbzFiles.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Test;
using Xunit;
using System;
using System.IO;
using ComicConverter;

namespace Test.ComicCreators
namespace Tests.ComicCreators
{
public class CbzFiles
{
Expand Down
11 changes: 10 additions & 1 deletion Tests/ComicCreators/PdfFiles.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Test;
using Xunit;
using System;
using System.IO;
using ComicConverter;

namespace Test.ComicCreators
namespace Tests.ComicCreators
{
public class PdfFiles
{
Expand All @@ -29,5 +30,13 @@ public void FilesAreNotImages()

Assert.ThrowsAny<Exception>(() => ComicBuilder.CreatePdf(images, Path));
}

[Fact]
public void ImagesNotFound()
{
string[] files = ["Fakename", "fakename2", "fakename3"];

Assert.Throws<IOException>(() => ComicBuilder.CreatePdf(files, Path));
}
}
}
6 changes: 3 additions & 3 deletions Tests/ImageCollectors/CbrFiles.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Test;
using Xunit;
using System.IO;
using ComicConverter;
using System.Collections.Generic;

namespace Test.ImageCollector
namespace Tests.ImageCollectors
{
public class CbrFiles
{
Expand All @@ -12,11 +13,10 @@ public class CbrFiles
public void Unrar()
{
string outputDir = "CbrTest1";
int extractedFiles;

ImageExporter.UnRar(Samples.Cbrpath, outputDir);

extractedFiles = Directory.GetFiles(outputDir).Length;
var extractedFiles = Directory.GetFiles(outputDir).Length;
Directory.Delete(outputDir, true);
Assert.Equal(3, extractedFiles);
}
Expand Down
5 changes: 3 additions & 2 deletions Tests/ImageCollectors/CbtFiles.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.IO;
using System;
using System.IO;
using System.Linq;
using ComicConverter;
using Test;
using Xunit;

namespace Test.ImageCollector
namespace Tests.ImageCollectors
{
public class CbtFiles
{
Expand Down
3 changes: 2 additions & 1 deletion Tests/ImageCollectors/CbzFiles.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Test;
using Xunit;
using System.IO;
using ComicConverter;
using System.Collections.Generic;

namespace Test.ImageCollector
namespace Tests.ImageCollectors
{
public class CbzFiles
{
Expand Down
26 changes: 16 additions & 10 deletions Tests/ImageCollectors/PdfFiles.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
using Test;
using Xunit;
using System;
using System.IO;
using ComicConverter;
using Xunit;

namespace Test.ImageCollector
namespace Tests.ImageCollectors
{
public class PdfFiles
{
[Fact]
public void ExtractImagesPdf()
public void ExtractImagesJpgPdf()
{
string pdfDir = "PdfExtractedImages";
string pdfPngDir = "PdfPNGExtractedImages";

ImageExporter.ExportPdfImages(Samples.Pdfpath, pdfDir);
ImageExporter.ExportPdfImages(Samples.Pdfpngpath, pdfPngDir);

var files = Directory.GetFiles(pdfDir).Length;
var filesPng = Directory.GetFiles(pdfPngDir).Length;

Directory.Delete(pdfDir, true);
Directory.Delete(pdfPngDir, true);

Assert.Equal(3, files);
Assert.Equal(3, filesPng);

}

[Fact]
public void ExtractImagesPngPdf()
{
string pdfPngDir = "PdfPNGExtractedImages";
ImageExporter.ExportPdfImages(Samples.Pdfpngpath, pdfPngDir);
var filesPng = Directory.GetFiles(pdfPngDir).Length;

Directory.Delete(pdfPngDir, true);

Assert.Equal(3, filesPng);
}

[Fact]
public void FileIsNotPdf()
{
Expand Down

0 comments on commit 11fb3aa

Please sign in to comment.