1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using Xunit;
6 
7 namespace System.Xml.Tests
8 {
9     public class DecimalAttributeTests
10     {
11         [Fact]
ReadContentAsDecimalAttribute1()12         public static void ReadContentAsDecimalAttribute1()
13         {
14             var reader = Utils.CreateFragmentReader("<Root a='  0099.99  '/>");
15             reader.PositionOnElement("Root");
16             reader.MoveToAttribute("a");
17             Assert.Equal(99.99m, reader.ReadContentAs(typeof(Decimal), null));
18         }
19 
20         [Fact]
ReadContentAsDecimalAttribute10()21         public static void ReadContentAsDecimalAttribute10()
22         {
23             var reader = Utils.CreateFragmentReader("<Root a='-000123456  '/>");
24             reader.PositionOnElement("Root");
25             reader.MoveToAttribute("a");
26             Assert.Equal(-123456m, reader.ReadContentAsDecimal());
27         }
28 
29         [Fact]
ReadContentAsDecimalAttribute11()30         public static void ReadContentAsDecimalAttribute11()
31         {
32             var reader = Utils.CreateFragmentReader("<Root a='99999.44456'/>");
33             reader.PositionOnElement("Root");
34             reader.MoveToAttribute("a");
35             Assert.Equal(99999.44456m, reader.ReadContentAsDecimal());
36         }
37 
38         [Fact]
ReadContentAsDecimalAttribute12()39         public static void ReadContentAsDecimalAttribute12()
40         {
41             var reader = Utils.CreateFragmentReader("<Root a=' 0 '/>");
42             reader.PositionOnElement("Root");
43             reader.MoveToAttribute("a");
44             Assert.Equal(0m, reader.ReadContentAs(typeof(Decimal), null));
45         }
46 
47         [Fact]
ReadContentAsDecimalAttribute2()48         public static void ReadContentAsDecimalAttribute2()
49         {
50             var reader = Utils.CreateFragmentReader("<Root a=' -56.44 '/>");
51             reader.PositionOnElement("Root");
52             reader.MoveToAttribute("a");
53             Assert.Equal(-56.44m, reader.ReadContentAs(typeof(Decimal), null));
54         }
55 
56         [Fact]
ReadContentAsDecimalAttribute3()57         public static void ReadContentAsDecimalAttribute3()
58         {
59             var reader = Utils.CreateFragmentReader("<Root a='  -56.455'/>");
60             reader.PositionOnElement("Root");
61             reader.MoveToAttribute("a");
62             Assert.Equal(-56.455m, reader.ReadContentAs(typeof(Decimal), null));
63         }
64 
65         [Fact]
ReadContentAsDecimalAttribute4()66         public static void ReadContentAsDecimalAttribute4()
67         {
68             var reader = Utils.CreateFragmentReader("<Root a='-000123456  '/>");
69             reader.PositionOnElement("Root");
70             reader.MoveToAttribute("a");
71             Assert.Equal(-123456m, reader.ReadContentAs(typeof(Decimal), null));
72         }
73 
74         [Fact]
ReadContentAsDecimalAttribute5()75         public static void ReadContentAsDecimalAttribute5()
76         {
77             var reader = Utils.CreateFragmentReader("<Root a='99999.44456'/>");
78             reader.PositionOnElement("Root");
79             reader.MoveToAttribute("a");
80             Assert.Equal(99999.44456m, reader.ReadContentAs(typeof(Decimal), null));
81         }
82 
83         [Fact]
ReadContentAsDecimalAttribute6()84         public static void ReadContentAsDecimalAttribute6()
85         {
86             var reader = Utils.CreateFragmentReader("<Root a=' 0 '/>");
87             reader.PositionOnElement("Root");
88             reader.MoveToAttribute("a");
89             Assert.Equal(0m, reader.ReadContentAsDecimal());
90         }
91 
92         [Fact]
ReadContentAsDecimalAttribute7()93         public static void ReadContentAsDecimalAttribute7()
94         {
95             var reader = Utils.CreateFragmentReader("<Root a='  0099.99  '/>");
96             reader.PositionOnElement("Root");
97             reader.MoveToAttribute("a");
98             Assert.Equal(99.99m, reader.ReadContentAsDecimal());
99         }
100 
101         [Fact]
ReadContentAsDecimalAttribute8()102         public static void ReadContentAsDecimalAttribute8()
103         {
104             var reader = Utils.CreateFragmentReader("<Root a=' -56.44 '/>");
105             reader.PositionOnElement("Root");
106             reader.MoveToAttribute("a");
107             Assert.Equal(-56.44m, reader.ReadContentAsDecimal());
108         }
109 
110         [Fact]
ReadContentAsDecimalAttribute9()111         public static void ReadContentAsDecimalAttribute9()
112         {
113             var reader = Utils.CreateFragmentReader("<Root a='  -56.455'/>");
114             reader.PositionOnElement("Root");
115             reader.MoveToAttribute("a");
116             Assert.Equal(-56.455m, reader.ReadContentAsDecimal());
117         }
118     }
119 }
120