Browse Source

If there's no data it shouldn't exist

Piotr Czajkowski 3 years ago
parent
commit
92573f16ff
2 changed files with 5 additions and 24 deletions
  1. 2 6
      PSDText/PSDText.cs
  2. 3 18
      PSDTextTests/PSDTextTests.cs

+ 2 - 6
PSDText/PSDText.cs

@@ -95,6 +95,8 @@ namespace PSDText
 
             AddXMLNamespaces();
             TextData = GetTextData();
+            if (!TextData.Any())
+                throw new Exception("Nothing was read from XML!");
         }
 
         /// <summary>
@@ -105,9 +107,6 @@ namespace PSDText
         /// false if there's nothing to write.</returns>
         public bool SaveAsXML(string path)
         {
-            if (!TextData.Any())
-                return false;
-
             var serializer = new XmlSerializer(typeof(List<TextData>));
             using (var sr = new StreamWriter(path))
             {
@@ -125,9 +124,6 @@ namespace PSDText
         /// false if there's nothing to write.</returns>
         public bool SaveAsJSON(string path)
         {
-            if (!TextData.Any())
-                return false;
-
             var serializer = new JsonSerializer();
             using (var sr = new StreamWriter(path))
             {

+ 3 - 18
PSDTextTests/PSDTextTests.cs

@@ -1,3 +1,4 @@
+using System;
 using System.IO;
 using Xunit;
 
@@ -28,14 +29,9 @@ namespace PSDTextTests
         }
 
         [Fact]
-        public void SaveAsXMLNoText()
+        public void NoText()
         {
-            var test = new PSDText.PSDText(NoTextPSD);
-            Assert.Empty(test.TextData);
-
-            var destination = "./testNoText.xml";
-            Assert.False(test.SaveAsXML(destination));
-            Assert.False(File.Exists(destination));
+            Assert.Throws<Exception>(() => new PSDText.PSDText(NoTextPSD));
         }
 
         [Fact]
@@ -49,16 +45,5 @@ namespace PSDTextTests
             Assert.True(File.Exists(destination));
             File.Delete(destination);
         }
-
-        [Fact]
-        public void SaveAsJSONNoText()
-        {
-            var test = new PSDText.PSDText(NoTextPSD);
-            Assert.Empty(test.TextData);
-
-            var destination = "./test.json";
-            Assert.False(test.SaveAsJSON(destination));
-            Assert.False(File.Exists(destination));
-        }
     }
 }