Jelajahi Sumber

Added NumbersWithFormula

Piotr Czajkowski 6 bulan lalu
induk
melakukan
aa7e0e0d97

+ 11 - 0
ExcelORM/ExcelORMTests/TestNumbersWithFormula.cs

@@ -0,0 +1,11 @@
+using ExcelORM.Models;
+
+namespace ExcelORMTests
+{
+    public record TestNumbersWithFormula
+    {
+        public double First { get; set; }
+        public double Second { get; set; }
+        public Formula? Sum { get; set; }
+    }
+}

+ 29 - 0
ExcelORM/ExcelORMTests/WriterTests.cs

@@ -191,4 +191,33 @@ public class WriterTests
         
         File.Delete(testFile);
     }
+
+    private static readonly TestNumbersWithFormula[] arrayNumbersWithFormulas =
+    {
+        new(){ First = 1, Second = 2, Sum = new Formula{FormulaA1 = "SUM(A2:B2)"} },
+        new(){ First = 2, Second = 3, Sum = new Formula{FormulaA1 = "SUM(A3:B3)"} },
+    };
+
+    [Fact]
+    public void NumbersWithFormula()
+    {
+        var testFile = Path.GetRandomFileName();
+        testFile = Path.ChangeExtension(testFile, "xlsx");
+
+        var writer = new ExcelWriter(testFile);
+        writer.Write(arrayNumbersWithFormulas);
+        writer.SaveAs(testFile);
+
+        var reader = new ExcelReader(testFile);
+        var readArray = reader.Read<TestNumbersWithFormula>().ToArray();
+        Assert.Equal(arrayNumbersWithFormulas.Length, readArray.Length);
+
+        foreach (var item in readArray)
+        {
+            Assert.NotNull(item.Sum);
+            Assert.Equal(item.First + item.Second, item.Sum.Value);
+        }
+
+        File.Delete(testFile);
+    }
 }