diff --git a/ExamplesAndTests/DGGroupSortFilterExampleConcurrent/DGGroupSortFilterExampleConcurrent.csproj b/ExamplesAndTests/DGGroupSortFilterExampleConcurrent/DGGroupSortFilterExampleConcurrent.csproj index 5cac7e8..01ed181 100644 --- a/ExamplesAndTests/DGGroupSortFilterExampleConcurrent/DGGroupSortFilterExampleConcurrent.csproj +++ b/ExamplesAndTests/DGGroupSortFilterExampleConcurrent/DGGroupSortFilterExampleConcurrent.csproj @@ -8,7 +8,7 @@ - + diff --git a/ExamplesAndTests/DataGridGroupSortFilterUltimateExample/DataGridGroupSortFilterUltimateExample.csproj b/ExamplesAndTests/DataGridGroupSortFilterUltimateExample/DataGridGroupSortFilterUltimateExample.csproj index 948792d..35af2a4 100644 --- a/ExamplesAndTests/DataGridGroupSortFilterUltimateExample/DataGridGroupSortFilterUltimateExample.csproj +++ b/ExamplesAndTests/DataGridGroupSortFilterUltimateExample/DataGridGroupSortFilterUltimateExample.csproj @@ -13,7 +13,7 @@ - + diff --git a/ExamplesAndTests/EditableDataGridTest/EditableDataGridTest.csproj b/ExamplesAndTests/EditableDataGridTest/EditableDataGridTest.csproj index 5994e52..3bec096 100644 --- a/ExamplesAndTests/EditableDataGridTest/EditableDataGridTest.csproj +++ b/ExamplesAndTests/EditableDataGridTest/EditableDataGridTest.csproj @@ -7,7 +7,7 @@ - + diff --git a/ExamplesAndTests/Swordfish.NET.TestV3/Swordfish.NET.TestV3.csproj b/ExamplesAndTests/Swordfish.NET.TestV3/Swordfish.NET.TestV3.csproj index 9221579..6170af1 100644 --- a/ExamplesAndTests/Swordfish.NET.TestV3/Swordfish.NET.TestV3.csproj +++ b/ExamplesAndTests/Swordfish.NET.TestV3/Swordfish.NET.TestV3.csproj @@ -3,7 +3,7 @@ WinExe true - netcoreapp3.1;net451;net46 + net46 Creative Commons Swordfish Computing Pty Ltd Swordfish.NET.TestV3 diff --git a/ExamplesAndTests/Swordfish.NET.UnitTestV3/BasicTestsWithFluentAssertions.cs b/ExamplesAndTests/Swordfish.NET.UnitTestV3/BasicTestsWithFluentAssertions.cs deleted file mode 100644 index 44028a1..0000000 --- a/ExamplesAndTests/Swordfish.NET.UnitTestV3/BasicTestsWithFluentAssertions.cs +++ /dev/null @@ -1,87 +0,0 @@ -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Swordfish.NET.Collections; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Swordfish.NET.UnitTestV3 -{ - [TestClass] - public class BasicTestsWithFluentAssertions - { - - //A demonstration of unit tests using xunit - //Each test is done using just xUnit, then repeated using the FluentAssertions library - //These are not necessarily good units tests just a demonstration of how to do them - - [TestMethod] - public void ReadOnlyTest() - { //using just xUnit - var collection = new ConcurrentObservableCollection(); - Assert.IsFalse(collection.IsReadOnly); - } - - [TestMethod] - public void ReadOnlyTestFluent() - { //Using the fluent assertions library - var collection = new ConcurrentObservableCollection(); - collection.IsReadOnly.Should().BeFalse(); - } - - [TestMethod] - public void CountTest() - { - var collection = new ConcurrentObservableCollection(); - collection.AddRange(new int[] { 1, 2, 3 }); - //xUnit - Assert.IsTrue(collection.Count == 3, "should have count of three"); - } - [TestMethod] - public void CountTestFluent() - { - var collection = new ConcurrentObservableCollection(); - collection.AddRange(new int[] { 1, 2, 3 }); - //fluentAssertion - collection.Should().HaveCount(3, "because we put three items in it"); - } - - [TestMethod] - public void ContentTest() - { - var collection = new ConcurrentObservableCollection(); - collection.AddRange(new int[] { 1, 2, 3 }); - Assert.IsTrue(collection.Any(i => i == 1 || i == 2 || i == 3)); - } - - [TestMethod] - public void ContentTestFluent() - { - var collection = new ConcurrentObservableCollection(); - collection.AddRange(new int[] { 1, 2, 3 }); - collection.Should().Contain(1).And.Contain(2).And.Contain(3); - } - - - //Using xUnit 'Theory' for testing, can put in multiple input data and test on each - [DataTestMethod] - [DataRow(new int[] { 1, 2, 3 })] - [DataRow(new int[] { 0 })] - public void ContentTheoryTest(int[] array) - { - var collection = new ConcurrentObservableCollection(); - collection.AddRange(array); - Assert.IsTrue(collection.Any()); - } - [DataTestMethod] - [DataRow(new int[] { 1, 2, 3 })] - [DataRow(new int[] { 0 })] - public void ContentTheoryTestFluent(int[] array) - { - var collection = new ConcurrentObservableCollection(); - collection.AddRange(array); - collection.Should().NotBeNullOrEmpty(); - } - } -} diff --git a/ExamplesAndTests/Swordfish.NET.UnitTestV3/SerializationTests.cs b/ExamplesAndTests/Swordfish.NET.UnitTestV3/SerializationTests.cs index a52367f..71f835c 100644 --- a/ExamplesAndTests/Swordfish.NET.UnitTestV3/SerializationTests.cs +++ b/ExamplesAndTests/Swordfish.NET.UnitTestV3/SerializationTests.cs @@ -1,39 +1,57 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Swordfish.NET.Collections; +using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; +#if NETCOREAPP +using System.Text.Json; +#endif namespace Swordfish.NET.UnitTestV3 { [TestClass] public class SerializationTests { - [TestMethod] - public void ConcurrentObservableCollectionSerializationTest() +#if NETCOREAPP + private T RoundTripSerialization(T collection) where T : class + { + var bytes = JsonSerializer.SerializeToUtf8Bytes(collection, + new JsonSerializerOptions { WriteIndented = false }); + return JsonSerializer.Deserialize(new ReadOnlySpan(bytes)); + } +#else + private T RoundTripSerialization(T collection) where T : class { var serializer = new BinaryFormatter(); var stream = new MemoryStream(); + serializer.Serialize(stream, collection); + stream.Position = 0; + return serializer.Deserialize(stream) as T; + } +#endif + + [TestMethod] + public void ConcurrentObservableCollectionSerializationTest() + { var collection = new ConcurrentObservableCollection(); for (int i = 0; i < 10; i++) collection.Add("TestItem" + (i + 1).ToString()); - serializer.Serialize(stream, collection); - stream.Position = 0; - collection = serializer.Deserialize(stream) as ConcurrentObservableCollection; + + collection = RoundTripSerialization(collection); + for (int i = 0; i < 10; i++) Assert.AreEqual("TestItem" + (i + 1).ToString(), collection[i]); } - [TestMethod] + [TestMethod] public void ConcurrentObservableDictionarySerializationTest() { - var serializer = new BinaryFormatter(); - var stream = new MemoryStream(); var collection = new ConcurrentObservableDictionary(); for (int i = 0; i < 10; i++) collection.Add("TestItem" + (i + 1).ToString(), i); - serializer.Serialize(stream, collection); - stream.Position = 0; - collection = serializer.Deserialize(stream) as ConcurrentObservableDictionary; + + collection = RoundTripSerialization(collection); + for (int i = 0; i < 10; i++) Assert.AreEqual(i, collection["TestItem" + (i + 1).ToString()]); } @@ -41,14 +59,12 @@ public void ConcurrentObservableDictionarySerializationTest() [TestMethod] public void ConcurrentObservableSortedDictionarySerializationTest() { - var serializer = new BinaryFormatter(); - var stream = new MemoryStream(); var collection = new ConcurrentObservableSortedDictionary(); for (int i = 0; i < 10; i++) collection.Add("TestItem" + (i + 1).ToString(), i); - serializer.Serialize(stream, collection); - stream.Position = 0; - collection = serializer.Deserialize(stream) as ConcurrentObservableSortedDictionary; + + collection = RoundTripSerialization(collection); + for (int i = 0; i < 10; i++) Assert.AreEqual(i, collection["TestItem" + (i + 1).ToString()]); } @@ -56,14 +72,12 @@ public void ConcurrentObservableSortedDictionarySerializationTest() [TestMethod] public void ConcurrentObservableHashSetSerializationTest() { - var serializer = new BinaryFormatter(); - var stream = new MemoryStream(); var collection = new ConcurrentObservableHashSet(); for (int i = 0; i < 10; i++) collection.Add("TestItem" + (i + 1).ToString()); - serializer.Serialize(stream, collection); - stream.Position = 0; - collection = serializer.Deserialize(stream) as ConcurrentObservableHashSet; + + collection = RoundTripSerialization(collection); + Assert.AreEqual(10, collection.Count); for (int i = 0; i < 10; i++) Assert.IsTrue(collection.Contains("TestItem" + (i + 1).ToString())); diff --git a/ExamplesAndTests/Swordfish.NET.UnitTestV3/Swordfish.NET.UnitTestV3.csproj b/ExamplesAndTests/Swordfish.NET.UnitTestV3/Swordfish.NET.UnitTestV3.csproj index 7dc26f1..19e0c1a 100644 --- a/ExamplesAndTests/Swordfish.NET.UnitTestV3/Swordfish.NET.UnitTestV3.csproj +++ b/ExamplesAndTests/Swordfish.NET.UnitTestV3/Swordfish.NET.UnitTestV3.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1;net451;net46;net5.0-windows + net46;net6.0 Creative Commons Swordfish Computing Pty Ltd Swordfish.NET.TestV3 @@ -9,11 +9,10 @@ 1.0.0 - + - diff --git a/Swordfish.NET.CollectionsV3/Swordfish.NET.CollectionsV3.csproj b/Swordfish.NET.CollectionsV3/Swordfish.NET.CollectionsV3.csproj index 86b5b81..1a4359c 100644 --- a/Swordfish.NET.CollectionsV3/Swordfish.NET.CollectionsV3.csproj +++ b/Swordfish.NET.CollectionsV3/Swordfish.NET.CollectionsV3.csproj @@ -5,7 +5,7 @@ Properties Swordfish.NET.Collections Swordfish.NET.CollectionsV3 - netstandard2.0;net451;net46 + netstandard2.0;net46 Creative Commons Swordfish Computing Pty Ltd Swordfish.NET.CollectionsV3