-
Notifications
You must be signed in to change notification settings - Fork 316
Tests | Expand UDT serialization code coverage #3423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
benrr101
merged 20 commits into
dotnet:main
from
edwardneal:feat/udt-serialization/tests
Sep 18, 2025
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
95e811e
Expand code coverage for UDT serialization
edwardneal 21e5fd4
Address test failures on 32-bit OSes
edwardneal 01f711f
Make Microsoft.SqlServer.Server a PackageReference
edwardneal 4db8883
Reformat SerializedTypes.cs
edwardneal bd49514
Switch to implicit object creation
edwardneal 9f195c9
Add and correct comments
edwardneal 62edb70
Enable nullable for project
edwardneal f9136f9
Declare and assign variables together
edwardneal 6e80cc5
Moved MemoryStream to an instance variable
edwardneal 60e074c
Merge branch 'main' into feat/udt-serialization/tests
edwardneal fa46855
Post-merge build corrections
edwardneal 3f054c7
Merge branch 'main' into feat/udt-serialization/tests
edwardneal ab82654
Reapply IDE0090 recommendations, disable CS1591 on newly-added tests
edwardneal b6e11f8
Next code review (first response)
edwardneal 67cbb7b
Merge branch 'main' into feat/udt-serialization/tests
edwardneal ad7f07b
Disable CS1591 on new tests
edwardneal 90d83ab
Merge branch 'main' into feat/udt-serialization/tests
edwardneal 61109eb
Disable mandatory XML documentation
edwardneal 643d8dc
Change formatting of test data
edwardneal a868f5e
Remove trailing XML documentation override
edwardneal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/Microsoft.Data.SqlClient/tests/UnitTests/.editorconfig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# editorconfig.org | ||
|
||
# top-most EditorConfig file | ||
root = false | ||
|
||
[*.cs] | ||
|
||
csharp_style_var_when_type_is_apparent = false:refactor | ||
# IDE0090: Use 'new(...)' | ||
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...ent/tests/UnitTests/Microsoft/Data/SqlClient/UdtSerialization/InvalidSerializationTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// 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.IO; | ||
using Microsoft.Data.SqlClient.Server; | ||
using Microsoft.Data.SqlClient.UnitTests.UdtSerialization.SerializedTypes; | ||
using Microsoft.SqlServer.Server; | ||
using Xunit; | ||
|
||
namespace Microsoft.Data.SqlClient.UnitTests.UdtSerialization; | ||
|
||
/// <summary> | ||
/// Attempts to serialize types which do not meet the requirements for either user-defined or native serialization. | ||
/// </summary> | ||
public sealed class InvalidSerializationTest : IDisposable | ||
{ | ||
private readonly MemoryStream _stream; | ||
|
||
/// <summary> | ||
/// Initializes the MemoryStream used for all tests in this class. | ||
/// </summary> | ||
public InvalidSerializationTest() | ||
{ | ||
_stream = new MemoryStream(); | ||
} | ||
|
||
void IDisposable.Dispose() | ||
{ | ||
_stream.Dispose(); | ||
} | ||
|
||
/// <summary> | ||
/// Attempts to serialize a class that does not have the SqlUserDefinedType attribute. Verifies that this fails. | ||
/// </summary> | ||
[Fact] | ||
public void Serialize_MissingSqlUserDefinedTypeAttribute_Throws() | ||
{ | ||
Action serialize = () => SerializationHelperSql9.Serialize(_stream, new ClassMissingSqlUserDefinedTypeAttribute()); | ||
var exception = Assert.Throws<InvalidUdtException>(serialize); | ||
|
||
Assert.Equal($"'{typeof(ClassMissingSqlUserDefinedTypeAttribute).FullName}' is an invalid user defined type, reason: no UDT attribute.", exception.Message); | ||
} | ||
|
||
/// <summary> | ||
/// Attempts to serialize a class that has a SqlUserDefinedType attribute, but specifies a Format enumeration value of | ||
/// Unknown. Verifies that this fails. | ||
/// </summary> | ||
[Fact] | ||
public void Serialize_UnknownFormattedType_Throws() | ||
{ | ||
Action serialize = () => SerializationHelperSql9.Serialize(_stream, new UnknownFormattedClass()); | ||
var exception = Assert.Throws<ArgumentOutOfRangeException>("Format", serialize); | ||
|
||
#if NET | ||
Assert.Equal("The Format enumeration value, 0, is not supported by the format method. (Parameter 'Format')", exception.Message); | ||
#else | ||
Assert.Equal("The Format enumeration value, Unknown, is not supported by the format method.\r\nParameter name: Format", exception.Message); | ||
#endif | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.