diff options
author | Joshua Clark <clarkis117@live.com> | 2018-03-17 06:07:19 +0300 |
---|---|---|
committer | Stephen Toub <stoub@microsoft.com> | 2018-03-17 06:07:19 +0300 |
commit | 007f6812bd1454675dbd3d15a9aca814afcd7553 (patch) | |
tree | b50d59c155104f75cd1ae50d01cd1eb8697ba676 /src/System.Drawing.Primitives | |
parent | 54eb3bfa6c07e45d85323fc5d2ce8f62733ec1b0 (diff) |
Added DCS Tests for System.Drawing Types (#27082)
* Added DCS Tests for System.Drawing Types
* Revert "Added DCS Tests for System.Drawing Types"
This reverts commit 20288796a73d2c90747297819344a53174144318.
* Move Utils.cs to CommonTest project
* add references to common helper method file and Utils.cs, add tests
* update references to Utils.cs
* fix indentation
Diffstat (limited to 'src/System.Drawing.Primitives')
-rw-r--r-- | src/System.Drawing.Primitives/tests/DataContractSerializerTests.cs | 146 | ||||
-rw-r--r-- | src/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj | 3 |
2 files changed, 149 insertions, 0 deletions
diff --git a/src/System.Drawing.Primitives/tests/DataContractSerializerTests.cs b/src/System.Drawing.Primitives/tests/DataContractSerializerTests.cs new file mode 100644 index 0000000000..86fe8d44a0 --- /dev/null +++ b/src/System.Drawing.Primitives/tests/DataContractSerializerTests.cs @@ -0,0 +1,146 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; +using System.Runtime.Serialization.Tests; +using System.Drawing; + +namespace System.Drawing.Primitives.Tests +{ + public class DataContractSerializerTests + { + [Fact] + public static void DCS_Point() + { + var objs = new Point[] + { + new Point(0,0), + new Point(1,2), + new Point(new Size(1,2)) + }; + var serializedStrings = new string[] + { + @"<Point xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><x>0</x><y>0</y></Point>", + @"<Point xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><x>1</x><y>2</y></Point>", + @"<Point xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><x>1</x><y>2</y></Point>" + }; + for (int i = 0; i < objs.Length; i++) + { + Assert.StrictEqual(DataContractSerializerHelper.SerializeAndDeserialize<Point>(objs[i], serializedStrings[i]), objs[i]); + } + } + + [Fact] + public static void DCS_PointF() + { + var objs = new PointF[] + { + new PointF(0, 0), + new PointF(1,2), + new PointF(1.5000f,-1.5000f) + }; + var serializedStrings = new string[] + { + @"<PointF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><x>0</x><y>0</y></PointF>", + @"<PointF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><x>1</x><y>2</y></PointF>", + @"<PointF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><x>1.5</x><y>-1.5</y></PointF>" + }; + for (int i = 0; i < objs.Length; i++) + { + Assert.StrictEqual(DataContractSerializerHelper.SerializeAndDeserialize<PointF>(objs[i], serializedStrings[i]), objs[i]); + } + } + + [Fact] + public static void DCS_Rectangle() + { + var objs = new Rectangle[] + { + new Rectangle(0, 0, 0, 0), + new Rectangle(1, 2, 1, 2), + new Rectangle(new Point(1,2), new Size(1,2)), + new Rectangle(1, -2, 1, -2) + }; + var serializedStrings = new string[] + { + @"<Rectangle xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>0</height><width>0</width><x>0</x><y>0</y></Rectangle>", + @"<Rectangle xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>2</height><width>1</width><x>1</x><y>2</y></Rectangle>", + @"<Rectangle xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>2</height><width>1</width><x>1</x><y>2</y></Rectangle>", + @"<Rectangle xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>-2</height><width>1</width><x>1</x><y>-2</y></Rectangle>" + }; + for (int i = 0; i < objs.Length; i++) + { + Assert.StrictEqual(DataContractSerializerHelper.SerializeAndDeserialize<Rectangle>(objs[i], serializedStrings[i]), objs[i]); + } + } + + [Fact] + public static void DCS_RectangleF() + { + var objs = new RectangleF[] + { + new RectangleF(0, 0, 0, 0), + new RectangleF(new PointF(1.5000f,2.5000f), new SizeF(1.5000f,2.5000f)), + new RectangleF(1.50001f, -2.5000f, 1.5000f, -2.5000f) + }; + var serializedStrings = new string[] + { + @"<RectangleF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>0</height><width>0</width><x>0</x><y>0</y></RectangleF>", + @"<RectangleF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>2.5</height><width>1.5</width><x>1.5</x><y>2.5</y></RectangleF>", + @"<RectangleF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>-2.5</height><width>1.5</width><x>1.50001</x><y>-2.5</y></RectangleF>" + }; + for (int i = 0; i < objs.Length; i++) + { + Assert.StrictEqual(DataContractSerializerHelper.SerializeAndDeserialize<RectangleF>(objs[i], serializedStrings[i]), objs[i]); + } + } + + [Fact] + public static void DCS_Size() + { + var objs = new Size[] + { + new Size(0,0), + new Size(new Point(1,2)), + new Size(1,2) + }; + var serializedStrings = new string[] + { + @"<Size xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>0</height><width>0</width></Size>", + @"<Size xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>2</height><width>1</width></Size>", + @"<Size xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>2</height><width>1</width></Size>" + }; + for (int i = 0; i < objs.Length; i++) + { + Assert.StrictEqual(DataContractSerializerHelper.SerializeAndDeserialize<Size>(objs[i], serializedStrings[i]), objs[i]); + } + } + + [Fact] + public static void DCS_SizeF() + { + var objs = new SizeF[] + { + new SizeF(0,0), + new SizeF(new PointF(1.5000f,-2.5000f)), + new SizeF(1.5000f,-2.5000f) + }; + var serializedStrings = new string[] + { + @"<SizeF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>0</height><width>0</width></SizeF>", + @"<SizeF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>-2.5</height><width>1.5</width></SizeF>", + @"<SizeF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>-2.5</height><width>1.5</width></SizeF>" + }; + for (int i = 0; i < objs.Length; i++) + { + Assert.StrictEqual(DataContractSerializerHelper.SerializeAndDeserialize<SizeF>(objs[i], serializedStrings[i]), objs[i]); + } + } + } +} diff --git a/src/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj b/src/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj index 3349020d86..a22538b184 100644 --- a/src/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj +++ b/src/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj @@ -11,6 +11,7 @@ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" /> <ItemGroup> + <Compile Include="DataContractSerializerTests.cs" /> <Compile Include="PointFTests.cs" /> <Compile Include="PointTests.cs" /> <Compile Include="RectangleFTests.cs" /> @@ -21,6 +22,8 @@ <Compile Include="$(CommonTestPath)\System\Diagnostics\DebuggerAttributes.cs"> <Link>Common\System\Diagnostics\DebuggerAttributes.cs</Link> </Compile> + <Compile Include="$(CommonTestPath)\System\Runtime\Serialization\DataContractSerializerHelper.cs" /> + <Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Utils.cs" /> </ItemGroup> <ItemGroup Condition="'$(TargetGroup)'=='netcoreapp'"> <Compile Include="SizeFTests.netcoreapp.cs" /> |