|
6 | 6 | using System.Data.SqlTypes;
|
7 | 7 | using Xunit;
|
8 | 8 |
|
9 |
| -namespace Microsoft.Data.SqlClient.UnitTests |
| 9 | +namespace Microsoft.Data.SqlClient.UnitTests; |
| 10 | + |
| 11 | +/// <summary> |
| 12 | +/// Tests that null and non-null values assigned to the SqlBuffer round-trip correctly to their CLR and their |
| 13 | +/// their SqlTypes representations. |
| 14 | +/// </summary> |
| 15 | +/// <remarks> |
| 16 | +/// Several methods in this class are internal. This is because their parameters are of SqlBuffer.StorageType, |
| 17 | +/// which is non-public. |
| 18 | +/// </remarks> |
| 19 | +public sealed class SqlBufferTest |
10 | 20 | {
|
| 21 | + private readonly SqlBuffer _target = new(); |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// Verifies that if a SqlBuffer is directly assigned the value of SqlGuid.Null, accessing its Guid property |
| 25 | + /// throws a SqlNullValueException. |
| 26 | + /// </summary> |
| 27 | + [Fact] |
| 28 | + public void GuidShouldThrowWhenSqlGuidNullIsSet() |
| 29 | + { |
| 30 | + _target.SqlGuid = SqlGuid.Null; |
| 31 | + |
| 32 | + Assert.Throws<SqlNullValueException>(() => _target.Guid); |
| 33 | + } |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Verifies that if a SqlBuffer is set to null of type Guid or SqlGuid, accessing its Guid property throws |
| 37 | + /// a SqlNullValueException. |
| 38 | + /// </summary> |
| 39 | + [Theory] |
| 40 | + [InlineData(SqlBuffer.StorageType.Guid)] |
| 41 | + [InlineData(SqlBuffer.StorageType.SqlGuid)] |
| 42 | + internal void GuidShouldThrowWhenSetToNullOfTypeIsCalled(SqlBuffer.StorageType storageType) |
| 43 | + { |
| 44 | + _target.SetToNullOfType(storageType); |
| 45 | + |
| 46 | + Assert.Throws<SqlNullValueException>(() => _target.Guid); |
| 47 | + } |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Verifies that the Guid property round-trips correctly. |
| 51 | + /// </summary> |
| 52 | + [Fact] |
| 53 | + public void GuidShouldReturnWhenGuidIsSet() |
| 54 | + { |
| 55 | + var expected = Guid.NewGuid(); |
| 56 | + _target.Guid = expected; |
| 57 | + |
| 58 | + Assert.Equal(expected, _target.Guid); |
| 59 | + } |
| 60 | + |
| 61 | + /// <summary> |
| 62 | + /// Verifies that the SqlGuid property round-trips to the Guid property correctly. |
| 63 | + /// </summary> |
| 64 | + [Fact] |
| 65 | + public void GuidShouldReturnExpectedWhenSqlGuidIsSet() |
| 66 | + { |
| 67 | + var expected = Guid.NewGuid(); |
| 68 | + _target.SqlGuid = expected; |
| 69 | + |
| 70 | + Assert.Equal(expected, _target.Guid); |
| 71 | + } |
| 72 | + |
11 | 73 | /// <summary>
|
12 |
| - /// Tests that null and non-null values assigned to the SqlBuffer round-trip correctly to their CLR and their |
13 |
| - /// their SqlTypes representations. |
| 74 | + /// Verifies that if a SqlBuffer is set to null of type Guid or SqlGuid, accessing its SqlGuid property returns |
| 75 | + /// SqlGuid.Null. |
14 | 76 | /// </summary>
|
15 |
| - /// <remarks> |
16 |
| - /// Several methods in this class are internal. This is because their parameters are of SqlBuffer.StorageType, |
17 |
| - /// which is non-public. |
18 |
| - /// </remarks> |
19 |
| - public sealed class SqlBufferTest |
| 77 | + [Theory] |
| 78 | + [InlineData(SqlBuffer.StorageType.Guid)] |
| 79 | + [InlineData(SqlBuffer.StorageType.SqlGuid)] |
| 80 | + internal void SqlGuidShouldReturnSqlNullWhenSetToNullOfTypeIsCalled(SqlBuffer.StorageType storageType) |
20 | 81 | {
|
21 |
| - private readonly SqlBuffer _target = new(); |
22 |
| - |
23 |
| - /// <summary> |
24 |
| - /// Verifies that if a SqlBuffer is directly assigned the value of SqlGuid.Null, accessing its Guid property |
25 |
| - /// throws a SqlNullValueException. |
26 |
| - /// </summary> |
27 |
| - [Fact] |
28 |
| - public void GuidShouldThrowWhenSqlGuidNullIsSet() |
29 |
| - { |
30 |
| - _target.SqlGuid = SqlGuid.Null; |
31 |
| - |
32 |
| - Assert.Throws<SqlNullValueException>(() => _target.Guid); |
33 |
| - } |
34 |
| - |
35 |
| - /// <summary> |
36 |
| - /// Verifies that if a SqlBuffer is set to null of type Guid or SqlGuid, accessing its Guid property throws |
37 |
| - /// a SqlNullValueException. |
38 |
| - /// </summary> |
39 |
| - [Theory] |
40 |
| - [InlineData(SqlBuffer.StorageType.Guid)] |
41 |
| - [InlineData(SqlBuffer.StorageType.SqlGuid)] |
42 |
| - internal void GuidShouldThrowWhenSetToNullOfTypeIsCalled(SqlBuffer.StorageType storageType) |
43 |
| - { |
44 |
| - _target.SetToNullOfType(storageType); |
45 |
| - |
46 |
| - Assert.Throws<SqlNullValueException>(() => _target.Guid); |
47 |
| - } |
48 |
| - |
49 |
| - /// <summary> |
50 |
| - /// Verifies that the Guid property round-trips correctly. |
51 |
| - /// </summary> |
52 |
| - [Fact] |
53 |
| - public void GuidShouldReturnWhenGuidIsSet() |
54 |
| - { |
55 |
| - var expected = Guid.NewGuid(); |
56 |
| - _target.Guid = expected; |
57 |
| - |
58 |
| - Assert.Equal(expected, _target.Guid); |
59 |
| - } |
60 |
| - |
61 |
| - /// <summary> |
62 |
| - /// Verifies that the SqlGuid property round-trips to the Guid property correctly. |
63 |
| - /// </summary> |
64 |
| - [Fact] |
65 |
| - public void GuidShouldReturnExpectedWhenSqlGuidIsSet() |
66 |
| - { |
67 |
| - var expected = Guid.NewGuid(); |
68 |
| - _target.SqlGuid = expected; |
69 |
| - |
70 |
| - Assert.Equal(expected, _target.Guid); |
71 |
| - } |
72 |
| - |
73 |
| - /// <summary> |
74 |
| - /// Verifies that if a SqlBuffer is set to null of type Guid or SqlGuid, accessing its SqlGuid property returns |
75 |
| - /// SqlGuid.Null. |
76 |
| - /// </summary> |
77 |
| - [Theory] |
78 |
| - [InlineData(SqlBuffer.StorageType.Guid)] |
79 |
| - [InlineData(SqlBuffer.StorageType.SqlGuid)] |
80 |
| - internal void SqlGuidShouldReturnSqlNullWhenSetToNullOfTypeIsCalled(SqlBuffer.StorageType storageType) |
81 |
| - { |
82 |
| - _target.SetToNullOfType(storageType); |
83 |
| - |
84 |
| - Assert.Equal(SqlGuid.Null, _target.SqlGuid); |
85 |
| - } |
86 |
| - |
87 |
| - /// <summary> |
88 |
| - /// Verifies that if a SqlBuffer is directly assigned the value of SqlGuid.Null, accessing its SqlGuid property |
89 |
| - /// returns SqlGuid.Null. |
90 |
| - /// </summary> |
91 |
| - [Fact] |
92 |
| - public void SqlGuidShouldReturnSqlGuidNullWhenSqlGuidNullIsSet() |
93 |
| - { |
94 |
| - _target.SqlGuid = SqlGuid.Null; |
95 |
| - |
96 |
| - Assert.Equal(SqlGuid.Null, _target.SqlGuid); |
97 |
| - } |
98 |
| - |
99 |
| - /// <summary> |
100 |
| - /// Verifies that the Guid property round-trips to the SqlGuid property correctly. |
101 |
| - /// </summary> |
102 |
| - [Fact] |
103 |
| - public void SqlGuidShouldReturnExpectedWhenGuidIsSet() |
104 |
| - { |
105 |
| - var guid = Guid.NewGuid(); |
106 |
| - SqlGuid expected = guid; |
107 |
| - _target.Guid = guid; |
108 |
| - |
109 |
| - Assert.Equal(expected, _target.SqlGuid); |
110 |
| - } |
111 |
| - |
112 |
| - /// <summary> |
113 |
| - /// Verifies that the SqlGuid property round-trips correctly. |
114 |
| - /// </summary> |
115 |
| - [Fact] |
116 |
| - public void SqlGuidShouldReturnExpectedWhenSqlGuidIsSet() |
117 |
| - { |
118 |
| - SqlGuid expected = Guid.NewGuid(); |
119 |
| - _target.SqlGuid = expected; |
120 |
| - |
121 |
| - Assert.Equal(expected, _target.SqlGuid); |
122 |
| - } |
123 |
| - |
124 |
| - /// <summary> |
125 |
| - /// Verifies that the Guid property round-trips to the SqlValue property correctly. |
126 |
| - /// </summary> |
127 |
| - [Fact] |
128 |
| - public void SqlValueShouldReturnExpectedWhenGuidIsSet() |
129 |
| - { |
130 |
| - var guid = Guid.NewGuid(); |
131 |
| - SqlGuid expected = guid; |
132 |
| - _target.Guid = guid; |
133 |
| - |
134 |
| - Assert.Equal(expected, _target.SqlValue); |
135 |
| - } |
136 |
| - |
137 |
| - /// <summary> |
138 |
| - /// Verifies that the SqlGuid property round-trips to the SqlValue property correctly. |
139 |
| - /// </summary> |
140 |
| - [Fact] |
141 |
| - public void SqlValueShouldReturnExpectedWhenSqlGuidIsSet() |
142 |
| - { |
143 |
| - SqlGuid expected = Guid.NewGuid(); |
144 |
| - _target.SqlGuid = expected; |
145 |
| - |
146 |
| - Assert.Equal(expected, _target.SqlValue); |
147 |
| - } |
| 82 | + _target.SetToNullOfType(storageType); |
| 83 | + |
| 84 | + Assert.Equal(SqlGuid.Null, _target.SqlGuid); |
| 85 | + } |
| 86 | + |
| 87 | + /// <summary> |
| 88 | + /// Verifies that if a SqlBuffer is directly assigned the value of SqlGuid.Null, accessing its SqlGuid property |
| 89 | + /// returns SqlGuid.Null. |
| 90 | + /// </summary> |
| 91 | + [Fact] |
| 92 | + public void SqlGuidShouldReturnSqlGuidNullWhenSqlGuidNullIsSet() |
| 93 | + { |
| 94 | + _target.SqlGuid = SqlGuid.Null; |
| 95 | + |
| 96 | + Assert.Equal(SqlGuid.Null, _target.SqlGuid); |
| 97 | + } |
| 98 | + |
| 99 | + /// <summary> |
| 100 | + /// Verifies that the Guid property round-trips to the SqlGuid property correctly. |
| 101 | + /// </summary> |
| 102 | + [Fact] |
| 103 | + public void SqlGuidShouldReturnExpectedWhenGuidIsSet() |
| 104 | + { |
| 105 | + var guid = Guid.NewGuid(); |
| 106 | + SqlGuid expected = guid; |
| 107 | + _target.Guid = guid; |
| 108 | + |
| 109 | + Assert.Equal(expected, _target.SqlGuid); |
| 110 | + } |
| 111 | + |
| 112 | + /// <summary> |
| 113 | + /// Verifies that the SqlGuid property round-trips correctly. |
| 114 | + /// </summary> |
| 115 | + [Fact] |
| 116 | + public void SqlGuidShouldReturnExpectedWhenSqlGuidIsSet() |
| 117 | + { |
| 118 | + SqlGuid expected = Guid.NewGuid(); |
| 119 | + _target.SqlGuid = expected; |
| 120 | + |
| 121 | + Assert.Equal(expected, _target.SqlGuid); |
| 122 | + } |
| 123 | + |
| 124 | + /// <summary> |
| 125 | + /// Verifies that the Guid property round-trips to the SqlValue property correctly. |
| 126 | + /// </summary> |
| 127 | + [Fact] |
| 128 | + public void SqlValueShouldReturnExpectedWhenGuidIsSet() |
| 129 | + { |
| 130 | + var guid = Guid.NewGuid(); |
| 131 | + SqlGuid expected = guid; |
| 132 | + _target.Guid = guid; |
| 133 | + |
| 134 | + Assert.Equal(expected, _target.SqlValue); |
| 135 | + } |
| 136 | + |
| 137 | + /// <summary> |
| 138 | + /// Verifies that the SqlGuid property round-trips to the SqlValue property correctly. |
| 139 | + /// </summary> |
| 140 | + [Fact] |
| 141 | + public void SqlValueShouldReturnExpectedWhenSqlGuidIsSet() |
| 142 | + { |
| 143 | + SqlGuid expected = Guid.NewGuid(); |
| 144 | + _target.SqlGuid = expected; |
| 145 | + |
| 146 | + Assert.Equal(expected, _target.SqlValue); |
148 | 147 | }
|
149 | 148 | }
|
0 commit comments