Ver Fonte

Added tests

flabbet há 4 anos atrás
pai
commit
d2ebf9e0b6

+ 1 - 1
PixiEditor.UpdateInstaller/PixiEditor.UpdateInstaller.csproj

@@ -12,7 +12,7 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="Tools.InnoSetup" Version="6.0.5" />
+    <PackageReference Include="Tools.InnoSetup" Version="6.1.2" />
   </ItemGroup>
 
   <ItemGroup>

+ 2 - 2
PixiEditor/PixiEditor.csproj

@@ -45,14 +45,14 @@
     </None>
   </ItemGroup>
   <ItemGroup>
-    <PackageReference Include="Dirkster.AvalonDock.Themes.VS2013" Version="4.40.0" />
+    <PackageReference Include="Dirkster.AvalonDock.Themes.VS2013" Version="4.50.0" />
     <PackageReference Include="Expression.Blend.Sdk">
       <Version>1.0.2</Version>
     </PackageReference>
     <PackageReference Include="Extended.Wpf.Toolkit" Version="3.8.2" />
     <PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
     <PackageReference Include="PixiEditor.ColorPicker" Version="1.0.1" />
-    <PackageReference Include="System.Drawing.Common" Version="4.7.0" />
+    <PackageReference Include="System.Drawing.Common" Version="5.0.0" />
     <PackageReference Include="WriteableBitmapEx">
       <Version>1.6.7</Version>
     </PackageReference>

+ 2 - 2
PixiEditor/ViewModels/ImportFilePopupViewModel.cs

@@ -103,9 +103,9 @@ namespace PixiEditor.ViewModels
         }
 
         /// <summary>
-        ///     Command that handles Path choosing to save file
+        ///     Command that handles Path choosing to save file.
         /// </summary>
-        /// <param name="parameter"></param>
+        /// <param name="parameter">Binding parameter.</param>
         private void ChoosePath(object parameter)
         {
             OpenFileDialog path = new OpenFileDialog

+ 2 - 1
PixiEditorTests/ModelsTests/ControllersTests/ClipboardControllerTests.cs

@@ -1,4 +1,5 @@
 using System.IO;
+using System.Linq;
 using System.Windows;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
@@ -35,7 +36,7 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestThatClipboardControllerSavesImageToClipboard()
         {
             Layer testLayer = new Layer("test layer", 10, 10);
-            ClipboardController.CopyToClipboard(new[] { testLayer }, CoordinatesCalculator.RectangleToCoordinates(0, 0, 9, 9), 10, 10);
+            ClipboardController.CopyToClipboard(new[] { testLayer }, CoordinatesCalculator.RectangleToCoordinates(0, 0, 9, 9).ToArray(), 10, 10);
             Assert.True(ClipboardController.IsImageInClipboard());
         }
 

+ 0 - 0
PixiEditorTests/ModelsTests/IO/CorruptedJpg.jpg


+ 0 - 0
PixiEditorTests/ModelsTests/IO/CorruptedPNG.png


BIN
PixiEditorTests/ModelsTests/IO/CorruptedPixiFile.pixi


+ 18 - 0
PixiEditorTests/ModelsTests/IO/ImporterTests.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
+using PixiEditor.Exceptions;
 using PixiEditor.Models.IO;
 using Xunit;
 
@@ -9,11 +10,13 @@ namespace PixiEditorTests.ModelsTests.IO
     public class ImporterTests
     {
         private readonly string testImagePath;
+        private readonly string testCorruptedPixiImagePath;
 
         // I am not testing ImportDocument, because it's just a wrapper for BinarySerialization which is tested.
         public ImporterTests()
         {
             testImagePath = $"{Environment.CurrentDirectory}\\..\\..\\..\\ModelsTests\\IO\\TestImage.png";
+            testCorruptedPixiImagePath = $"{Environment.CurrentDirectory}\\..\\..\\..\\ModelsTests\\IO\\CorruptedPixiFile.pixi";
         }
 
         [Theory]
@@ -43,6 +46,21 @@ namespace PixiEditorTests.ModelsTests.IO
             Assert.Equal(color, image.GetPixel(2, 2)); // Middle center
         }
 
+        [Fact]
+        public void TestThatImporterThrowsCorruptedFileExceptionOnWrongPixiFileWithSupportedExtension()
+        {
+            Assert.Throws<CorruptedFileException>(() => { Importer.ImportDocument(testCorruptedPixiImagePath); });
+        }
+
+        [Theory]
+        [InlineData("CorruptedPNG.png")]
+        [InlineData("CorruptedJpg.jpg")]
+        public void TestThatImporterThrowsCorruptedFileExceptionOnWrongImageFileWithSupportedExtension(string fileName)
+        {
+            string imagePath = $"{Environment.CurrentDirectory}\\..\\..\\..\\ModelsTests\\IO\\{fileName}";
+            Assert.Throws<CorruptedFileException>(() => { Importer.ImportImage(imagePath); });
+        }
+
         [Fact]
         public void TestThatImportImageResizes()
         {

+ 2 - 1
PixiEditorTests/ModelsTests/PositionTests/CoordinatesCalculatorTests.cs

@@ -1,4 +1,5 @@
 using PixiEditor.Models.Position;
+using System.Linq;
 using Xunit;
 
 namespace PixiEditorTests.ModelsTests.PositionTests
@@ -10,7 +11,7 @@ namespace PixiEditorTests.ModelsTests.PositionTests
         [InlineData(0, 0, 10, 10, 121)]
         public void TestThatRectangleToCoordinatesReturnsSameAmount(int x1, int y1, int x2, int y2, int expectedResult)
         {
-            Assert.Equal(CoordinatesCalculator.RectangleToCoordinates(x1, y1, x2, y2).Length, expectedResult);
+            Assert.Equal(CoordinatesCalculator.RectangleToCoordinates(x1, y1, x2, y2).Count(), expectedResult);
         }
 
         [Fact]

+ 11 - 1
PixiEditorTests/PixiEditorTests.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>netcoreapp3.1</TargetFramework>
+    <TargetFramework>net5.0-windows</TargetFramework>
 
     <IsPackable>false</IsPackable>
 
@@ -13,6 +13,10 @@
     <DebugSymbols>true</DebugSymbols>
   </PropertyGroup>
 
+  <ItemGroup>
+    <None Remove="ModelsTests\IO\CorruptedFile.xaml" />
+  </ItemGroup>
+
   <ItemGroup>
     <PackageReference Include="Codecov" Version="1.12.3" />
     <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
@@ -30,6 +34,12 @@
     <PackageReference Include="Xunit.StaFact" Version="1.0.37" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Page Include="ModelsTests\IO\CorruptedFile.xaml">
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+  </ItemGroup>
+
   <ItemGroup>
     <ProjectReference Include="..\PixiEditor.UpdateModule\PixiEditor.UpdateModule.csproj" />
     <ProjectReference Include="..\PixiEditor\PixiEditor.csproj" />