From a39e88a0ea8ee1f52093d3ec360baaa5b028b311 Mon Sep 17 00:00:00 2001 From: Edward Cooke Date: Fri, 13 Sep 2024 11:05:40 -0600 Subject: [PATCH] Use build.props and fix all warnings --- Directory.Build.props | 6 + Directory.Packages.props | 1 + .../YamlDotNet.Benchmark.csproj | 38 +-- .../ExternalModel.cs | 23 +- ...amlDotNet.Core7AoTCompileTest.Model.csproj | 1 - .../YamlDotNet.Core7AoTCompileTest.csproj | 2 - YamlDotNet.Fsharp.Test/DeserializerTests.fs | 160 +++++----- YamlDotNet.Fsharp.Test/SerializerTests.fs | 277 ++++++++++-------- YamlDotNet.Fsharp.Test/StringExtensions.fs | 8 +- .../YamlDotNet.Fsharp.Test.fsproj | 10 +- .../DeserializeObjectGraph.fs | 1 + .../YamlDotNet.Samples.Fsharp.fsproj | 1 + YamlDotNet.Samples/UseTypeConverters.cs | 2 +- .../StaticGenerator/RootCollectionTests.cs | 8 +- YamlDotNet.Test/Core/ScannerTests.cs | 52 ++-- .../RepresentationModel/YamlStreamTests.cs | 6 +- .../KeyValueTypeDiscriminatorTests.cs | 41 +-- ...TypeDiscriminatingNodeDeserializerTests.cs | 18 +- .../UniqueKeyTypeDiscriminatorTests.cs | 12 +- .../Serialization/HiddenPropertyTests.cs | 2 +- .../Serialization/SerializationTests.cs | 8 +- .../Serialization/YamlCommentTests.cs | 23 +- YamlDotNet.Test/YamlDotNet.Test.csproj | 2 +- YamlDotNet/YamlDotNet.csproj | 4 - 24 files changed, 406 insertions(+), 300 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 6df06ad9..4901cc7b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -10,7 +10,13 @@ + 9999 + True 12.0 + + + true + diff --git a/Directory.Packages.props b/Directory.Packages.props index b6940f44..c23f4025 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -9,6 +9,7 @@ + diff --git a/YamlDotNet.Benchmark/YamlDotNet.Benchmark.csproj b/YamlDotNet.Benchmark/YamlDotNet.Benchmark.csproj index 1f21fa0a..a7f96711 100644 --- a/YamlDotNet.Benchmark/YamlDotNet.Benchmark.csproj +++ b/YamlDotNet.Benchmark/YamlDotNet.Benchmark.csproj @@ -1,27 +1,27 @@ - - Exe - net8.0;net472 - enable - enable - + + Exe + net8.0;net472 + enable + enable + - - - + + + - - - - + + + + - - - + + + - - - + + + diff --git a/YamlDotNet.Core7AoTCompileTest.Model/ExternalModel.cs b/YamlDotNet.Core7AoTCompileTest.Model/ExternalModel.cs index 241c9618..0f324e09 100644 --- a/YamlDotNet.Core7AoTCompileTest.Model/ExternalModel.cs +++ b/YamlDotNet.Core7AoTCompileTest.Model/ExternalModel.cs @@ -1,4 +1,25 @@ -namespace YamlDotNet.Core7AoTCompileTest.Model; +// This file is part of YamlDotNet - A .NET library for YAML. +// Copyright (c) Antoine Aubry and contributors +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is furnished to do +// so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace YamlDotNet.Core7AoTCompileTest.Model; public class ExternalModel { diff --git a/YamlDotNet.Core7AoTCompileTest.Model/YamlDotNet.Core7AoTCompileTest.Model.csproj b/YamlDotNet.Core7AoTCompileTest.Model/YamlDotNet.Core7AoTCompileTest.Model.csproj index 89b0c600..30402ac0 100644 --- a/YamlDotNet.Core7AoTCompileTest.Model/YamlDotNet.Core7AoTCompileTest.Model.csproj +++ b/YamlDotNet.Core7AoTCompileTest.Model/YamlDotNet.Core7AoTCompileTest.Model.csproj @@ -4,7 +4,6 @@ net8.0 enable enable - true diff --git a/YamlDotNet.Core7AoTCompileTest/YamlDotNet.Core7AoTCompileTest.csproj b/YamlDotNet.Core7AoTCompileTest/YamlDotNet.Core7AoTCompileTest.csproj index 0fe07dab..aaeb2c1d 100644 --- a/YamlDotNet.Core7AoTCompileTest/YamlDotNet.Core7AoTCompileTest.csproj +++ b/YamlDotNet.Core7AoTCompileTest/YamlDotNet.Core7AoTCompileTest.csproj @@ -6,7 +6,6 @@ true true enable - true @@ -17,7 +16,6 @@ bin\Debug\ DEBUG;TRACE prompt - 4 diff --git a/YamlDotNet.Fsharp.Test/DeserializerTests.fs b/YamlDotNet.Fsharp.Test/DeserializerTests.fs index 9e0bb282..422f5cfe 100644 --- a/YamlDotNet.Fsharp.Test/DeserializerTests.fs +++ b/YamlDotNet.Fsharp.Test/DeserializerTests.fs @@ -8,29 +8,33 @@ open YamlDotNet.Serialization.NamingConventions open System.ComponentModel [] -type Spec = { - EngineType: string - DriveType: string -} +type Spec = + { + EngineType: string + DriveType: string + } [] -type Car = { - Name: string - Year: int - Spec: Spec option - Nickname: string option -} +type Car = + { + Name: string + Year: int + Spec: Spec option + Nickname: string option + } [] -type Person = { - Name: string - MomentOfBirth: DateTime - Cars: Car array -} +type Person = + { + Name: string + MomentOfBirth: DateTime + Cars: Car array + } [] -let Deserialize_YamlWithScalarOptions() = - let yaml = """ +let Deserialize_YamlWithScalarOptions () = + let yaml = + """ name: Jack momentOfBirth: 1983-04-21T20:21:03.0041599Z cars: @@ -40,21 +44,24 @@ cars: - name: Honda year: 2021 """ - let sut = DeserializerBuilder() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build() + + let sut = + DeserializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build() let person = sut.Deserialize(yaml) Assert.Equal("Jack", person.Name) Assert.Equal(2, person.Cars.Length) Assert.Equal("Mercedes", person.Cars[0].Name) - Assert.Equal(Some "Jessy", person.Cars[0].Nickname)// |> should equal (Some "Jessy") + Assert.Equal(Some "Jessy", person.Cars[0].Nickname) // |> should equal (Some "Jessy") Assert.Equal("Honda", person.Cars[1].Name) Assert.Equal(None, person.Cars[1].Nickname) [] -let Deserialize_YamlWithObjectOptions() = - let yaml = """ +let Deserialize_YamlWithObjectOptions () = + let yaml = + """ name: Jack momentOfBirth: 1983-04-21T20:21:03.0041599Z cars: @@ -66,48 +73,56 @@ cars: - name: Honda year: 2021 """ - let sut = DeserializerBuilder() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build() + + let sut = + DeserializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build() let person = sut.Deserialize(yaml) Assert.Equal("Jack", person.Name) Assert.Equal(2, person.Cars.Length) - + Assert.Equal("Mercedes", person.Cars[0].Name) Assert.NotNull(person.Cars[0].Spec) Assert.True(person.Cars[0].Spec |> Option.isSome) Assert.Equal("V6", person.Cars[0].Spec.Value.EngineType) Assert.Equal("AWD", person.Cars[0].Spec.Value.DriveType) - + Assert.Equal("Honda", person.Cars[1].Name) Assert.Null(person.Cars[1].Spec) Assert.Equal(None, person.Cars[1].Spec) Assert.Equal(None, person.Cars[1].Nickname) - [] -type TestSeq = { - name: string - numbers: int seq -} +[] +type TestSeq = { name: string; numbers: int seq } [] -let Deserialize_YamlSeq() = - let jackTheDriver = { - name = "Jack" - numbers = seq { 12; 2; 2 } - } - - let yaml = """name: Jack +let Deserialize_YamlSeq () = + let jackTheDriver = + { + name = "Jack" + numbers = + seq { + 12 + 2 + 2 + } + } + + let yaml = + """name: Jack numbers: - 12 - 2 - 2 """ - let sut = DeserializerBuilder() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build() + + let sut = + DeserializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build() let person = sut.Deserialize(yaml) Assert.Equal(jackTheDriver.name, person.name) @@ -118,27 +133,28 @@ numbers: Assert.Equal(2, numbers[2]) [] -type TestList = { - name: string - numbers: int list -} +type TestList = { name: string; numbers: int list } [] -let Deserialize_YamlList() = - let jackTheDriver = { - name = "Jack" - numbers = [ 12; 2; 2 ] - } - - let yaml = """name: Jack +let Deserialize_YamlList () = + let jackTheDriver = + { + name = "Jack" + numbers = [ 12; 2; 2 ] + } + + let yaml = + """name: Jack numbers: - 12 - 2 - 2 """ - let sut = DeserializerBuilder() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build() + + let sut = + DeserializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build() let person = sut.Deserialize(yaml) Assert.Equal(jackTheDriver.name, person.name) @@ -148,29 +164,29 @@ numbers: Assert.Equal(2, numbers[1]) Assert.Equal(2, numbers[2]) - [] -type TestArray = { - name: string - numbers: int array -} +type TestArray = { name: string; numbers: int array } [] -let Deserialize_YamlArray() = - let jackTheDriver = { - name = "Jack" - numbers = [| 12; 2; 2 |] - } - - let yaml = """name: Jack +let Deserialize_YamlArray () = + let jackTheDriver = + { + name = "Jack" + numbers = [| 12; 2; 2 |] + } + + let yaml = + """name: Jack numbers: - 12 - 2 - 2 """ - let sut = DeserializerBuilder() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build() + + let sut = + DeserializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build() let person = sut.Deserialize(yaml) Assert.Equal(jackTheDriver.name, person.name) diff --git a/YamlDotNet.Fsharp.Test/SerializerTests.fs b/YamlDotNet.Fsharp.Test/SerializerTests.fs index a7bd209b..c8ad17c6 100644 --- a/YamlDotNet.Fsharp.Test/SerializerTests.fs +++ b/YamlDotNet.Fsharp.Test/SerializerTests.fs @@ -8,46 +8,56 @@ open YamlDotNet.Core open YamlDotNet.Fsharp.Test [] -type Spec = { - EngineType: string - DriveType: string -} +type Spec = + { + EngineType: string + DriveType: string + } [] -type Car = { - Name: string - Year: int - Spec: Spec option - Nickname: string option -} +type Car = + { + Name: string + Year: int + Spec: Spec option + Nickname: string option + } [] -type Person = { - Name: string - MomentOfBirth: DateTime - KidsSeat: int option - Cars: Car array -} +type Person = + { + Name: string + MomentOfBirth: DateTime + KidsSeat: int option + Cars: Car array + } [] -let Serialize_YamlWithScalarOptions() = - let jackTheDriver = { - Name = "Jack" - MomentOfBirth = DateTime(1983, 4, 21, 20, 21, 03, 4) - KidsSeat = Some 1 - Cars = [| - { Name = "Mercedes" - Year = 2018 - Nickname = Some "Jessy" - Spec = None }; - { Name = "Honda" - Year = 2021 - Nickname = None - Spec = None } - |] - } +let Serialize_YamlWithScalarOptions () = + let jackTheDriver = + { + Name = "Jack" + MomentOfBirth = DateTime(1983, 4, 21, 20, 21, 03, 4) + KidsSeat = Some 1 + Cars = + [| + { + Name = "Mercedes" + Year = 2018 + Nickname = Some "Jessy" + Spec = None + } + { + Name = "Honda" + Year = 2021 + Nickname = None + Spec = None + } + |] + } - let yaml = """name: Jack + let yaml = + """name: Jack momentOfBirth: 1983-04-21T20:21:03.0040000 kidsSeat: 1 cars: @@ -60,32 +70,41 @@ cars: spec: nickname: """ - let sut = SerializerBuilder() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build() + + let sut = + SerializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build() let person = sut.Serialize(jackTheDriver) Assert.Equal(yaml.Clean(), person.Clean()) [] -let Serialize_YamlWithScalarOptions_OmitNull() = - let jackTheDriver = { - Name = "Jack" - MomentOfBirth = DateTime(1983, 4, 21, 20, 21, 03, 4) - KidsSeat = Some 1 - Cars = [| - { Name = "Mercedes" - Year = 2018 - Nickname = Some "Jessy" - Spec = None }; - { Name = "Honda" - Year = 2021 - Nickname = None - Spec = None } - |] - } +let Serialize_YamlWithScalarOptions_OmitNull () = + let jackTheDriver = + { + Name = "Jack" + MomentOfBirth = DateTime(1983, 4, 21, 20, 21, 03, 4) + KidsSeat = Some 1 + Cars = + [| + { + Name = "Mercedes" + Year = 2018 + Nickname = Some "Jessy" + Spec = None + } + { + Name = "Honda" + Year = 2021 + Nickname = None + Spec = None + } + |] + } - let yaml = """name: Jack + let yaml = + """name: Jack momentOfBirth: 1983-04-21T20:21:03.0040000 kidsSeat: 1 cars: @@ -95,36 +114,42 @@ cars: - name: Honda year: 2021 """ - let sut = SerializerBuilder() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull) - .Build() + + let sut = + SerializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull) + .Build() let person = sut.Serialize(jackTheDriver) Assert.Equal(yaml.Clean(), person.Clean()) [] -let Serialize_YamlWithObjectOptions_OmitNull() = - let jackTheDriver = { - Name = "Jack" - MomentOfBirth = DateTime(1983, 4, 21, 20, 21, 03, 4) - KidsSeat = Some 1 - Cars = [| - { Name = "Mercedes" - Year = 2018 - Nickname = None - Spec = Some { - EngineType = "V6" - DriveType = "AWD" - } }; - { Name = "Honda" - Year = 2021 - Nickname = None - Spec = None } - |] - } +let Serialize_YamlWithObjectOptions_OmitNull () = + let jackTheDriver = + { + Name = "Jack" + MomentOfBirth = DateTime(1983, 4, 21, 20, 21, 03, 4) + KidsSeat = Some 1 + Cars = + [| + { + Name = "Mercedes" + Year = 2018 + Nickname = None + Spec = Some { EngineType = "V6"; DriveType = "AWD" } + } + { + Name = "Honda" + Year = 2021 + Nickname = None + Spec = None + } + |] + } - let yaml = """name: Jack + let yaml = + """name: Jack momentOfBirth: 1983-04-21T20:21:03.0040000 kidsSeat: 1 cars: @@ -136,91 +161,97 @@ cars: - name: Honda year: 2021 """ - let sut = SerializerBuilder() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull) - .Build() + + let sut = + SerializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull) + .Build() let person = sut.Serialize(jackTheDriver) Assert.Equal(yaml.Clean(), person.Clean()) [] -type TestSeq = { - name: string - numbers: int seq -} +[] +type TestSeq = { name: string; numbers: int seq } [] -let Serialize_YamlSeq() = - let jackTheDriver = { - name = "Jack" - numbers = [ 12; 2; 2 ] - } +let Serialize_YamlSeq () = + let jackTheDriver = + { + name = "Jack" + numbers = [ 12; 2; 2 ] + } - let yaml = """name: Jack + let yaml = + """name: Jack numbers: - 12 - 2 - 2 """ - let sut = SerializerBuilder() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull) - .Build() + + let sut = + SerializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull) + .Build() let person = sut.Serialize(jackTheDriver) Assert.Equal(yaml.Clean(), person.Clean()) [] -type TestList = { - name: string - numbers: int list -} +type TestList = { name: string; numbers: int list } [] -let Serialize_YamlList() = - let jackTheDriver = { - name = "Jack" - numbers = [ 12; 2; 2 ] - } +let Serialize_YamlList () = + let jackTheDriver = + { + name = "Jack" + numbers = [ 12; 2; 2 ] + } - let yaml = """name: Jack + let yaml = + """name: Jack numbers: - 12 - 2 - 2 """ - let sut = SerializerBuilder() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull) - .Build() + + let sut = + SerializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull) + .Build() let person = sut.Serialize(jackTheDriver) Assert.Equal(yaml.Clean(), person.Clean()) [] -type TestArray = { - name: string - numbers: int array -} +type TestArray = { name: string; numbers: int array } [] -let Serialize_YamlArray() = - let jackTheDriver = { - name = "Jack" - numbers = [| 12; 2; 2 |] - } +let Serialize_YamlArray () = + let jackTheDriver = + { + name = "Jack" + numbers = [| 12; 2; 2 |] + } - let yaml = """name: Jack + let yaml = + """name: Jack numbers: - 12 - 2 - 2 """ - let sut = SerializerBuilder() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull) - .Build() + + let sut = + SerializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull) + .Build() let person = sut.Serialize(jackTheDriver) Assert.Equal(yaml.Clean(), person.Clean()) diff --git a/YamlDotNet.Fsharp.Test/StringExtensions.fs b/YamlDotNet.Fsharp.Test/StringExtensions.fs index 5bf956d2..5094b2f3 100644 --- a/YamlDotNet.Fsharp.Test/StringExtensions.fs +++ b/YamlDotNet.Fsharp.Test/StringExtensions.fs @@ -7,9 +7,9 @@ type StringExtensions() = [] static member NormalizeNewLines(x: string) = x.Replace("\r\n", "\n").Replace("\n", System.Environment.NewLine) + [] - static member TrimNewLines(x: string) = - x.TrimEnd('\r').TrimEnd('\n') + static member TrimNewLines(x: string) = x.TrimEnd('\r').TrimEnd('\n') + [] - static member Clean(x: string) = - x.NormalizeNewLines().TrimNewLines() + static member Clean(x: string) = x.NormalizeNewLines().TrimNewLines() diff --git a/YamlDotNet.Fsharp.Test/YamlDotNet.Fsharp.Test.fsproj b/YamlDotNet.Fsharp.Test/YamlDotNet.Fsharp.Test.fsproj index f330335e..9c61a02e 100644 --- a/YamlDotNet.Fsharp.Test/YamlDotNet.Fsharp.Test.fsproj +++ b/YamlDotNet.Fsharp.Test/YamlDotNet.Fsharp.Test.fsproj @@ -1,4 +1,4 @@ - + net8.0;net6.0;net47 false @@ -6,7 +6,7 @@ true true - true + 5 @@ -15,9 +15,13 @@ + - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/YamlDotNet.Samples.Fsharp/DeserializeObjectGraph.fs b/YamlDotNet.Samples.Fsharp/DeserializeObjectGraph.fs index 6a2e0bb5..daa9626e 100644 --- a/YamlDotNet.Samples.Fsharp/DeserializeObjectGraph.fs +++ b/YamlDotNet.Samples.Fsharp/DeserializeObjectGraph.fs @@ -24,6 +24,7 @@ type Address = State: string } [] +[] type Order = { Receipt: string Date: DateTime diff --git a/YamlDotNet.Samples.Fsharp/YamlDotNet.Samples.Fsharp.fsproj b/YamlDotNet.Samples.Fsharp/YamlDotNet.Samples.Fsharp.fsproj index c0a9f26e..72f23d12 100644 --- a/YamlDotNet.Samples.Fsharp/YamlDotNet.Samples.Fsharp.fsproj +++ b/YamlDotNet.Samples.Fsharp/YamlDotNet.Samples.Fsharp.fsproj @@ -5,6 +5,7 @@ net8.0 false + 5 diff --git a/YamlDotNet.Samples/UseTypeConverters.cs b/YamlDotNet.Samples/UseTypeConverters.cs index f60f0d73..b141767c 100644 --- a/YamlDotNet.Samples/UseTypeConverters.cs +++ b/YamlDotNet.Samples/UseTypeConverters.cs @@ -33,7 +33,7 @@ namespace YamlDotNet.Samples { public class UseTypeConverters { - ITestOutputHelper output; + private readonly ITestOutputHelper output; public UseTypeConverters(ITestOutputHelper output) { diff --git a/YamlDotNet.Test/Analyzers/StaticGenerator/RootCollectionTests.cs b/YamlDotNet.Test/Analyzers/StaticGenerator/RootCollectionTests.cs index 70614e63..0ce08fb1 100644 --- a/YamlDotNet.Test/Analyzers/StaticGenerator/RootCollectionTests.cs +++ b/YamlDotNet.Test/Analyzers/StaticGenerator/RootCollectionTests.cs @@ -80,7 +80,7 @@ public void RootObjectWorks() b: world "; - var actual = (IDictionary) deserializer.Deserialize(yaml); + var actual = (IDictionary)deserializer.Deserialize(yaml); Assert.Equal("hello", actual["a"]); Assert.Equal("world", actual["b"]); } @@ -96,9 +96,9 @@ public void RootNestedObjectWorks() Test: world "; - var actual = (IDictionary) deserializer.Deserialize(yaml); - Assert.Equal("hello", ((IDictionary)actual["a"])["Test"]); - Assert.Equal("world", ((IDictionary)actual["b"])["Test"]); + var actual = (IDictionary)deserializer.Deserialize(yaml); + Assert.Equal("hello", ((IDictionary)actual["a"])["Test"]); + Assert.Equal("world", ((IDictionary)actual["b"])["Test"]); } } [YamlSerializable] diff --git a/YamlDotNet.Test/Core/ScannerTests.cs b/YamlDotNet.Test/Core/ScannerTests.cs index 5431879a..98fbf8a8 100644 --- a/YamlDotNet.Test/Core/ScannerTests.cs +++ b/YamlDotNet.Test/Core/ScannerTests.cs @@ -367,7 +367,7 @@ public void CommentsAreCorrectlyMarked() } } - Assert.True(false, "Did not find a comment"); + Assert.Fail("Did not find a comment"); } [Fact] @@ -463,7 +463,7 @@ public void Plain_Scalar_inside_flow_does_not_allow_braces() [Fact] public void Keys_can_start_with_colons_in_nested_block() { - AssertSequenceOfTokensFrom(Yaml.ScannerForText("root:\n :first: 1\n :second: 2"), + AssertSequenceOfTokensFrom(Yaml.ScannerForText("root:\n :first: 1\n :second: 2"), StreamStart, BlockMappingStart, Key, @@ -484,9 +484,9 @@ public void Keys_can_start_with_colons_in_nested_block() } [Fact] - public void Keys_can_start_with_colons_after_quoted_values() + public void Keys_can_start_with_colons_after_quoted_values() { - AssertSequenceOfTokensFrom(Yaml.ScannerForText(":first: '1'\n:second: 2"), + AssertSequenceOfTokensFrom(Yaml.ScannerForText(":first: '1'\n:second: 2"), StreamStart, BlockMappingStart, Key, @@ -502,9 +502,9 @@ public void Keys_can_start_with_colons_after_quoted_values() } [Fact] - public void Keys_can_start_with_colons_after_single_quoted_values_in_nested_block() + public void Keys_can_start_with_colons_after_single_quoted_values_in_nested_block() { - AssertSequenceOfTokensFrom(Yaml.ScannerForText("xyz:\n :hello: 'world'\n :goodbye: world"), + AssertSequenceOfTokensFrom(Yaml.ScannerForText("xyz:\n :hello: 'world'\n :goodbye: world"), StreamStart, BlockMappingStart, Key, @@ -525,26 +525,26 @@ public void Keys_can_start_with_colons_after_single_quoted_values_in_nested_bloc } [Fact] - public void Keys_can_start_with_colons_after_double_quoted_values_in_nested_block() - { - AssertSequenceOfTokensFrom(Yaml.ScannerForText("xyz:\n :hello: \"world\"\n :goodbye: world"), - StreamStart, - BlockMappingStart, - Key, - PlainScalar("xyz"), - Value, - BlockMappingStart, - Key, - PlainScalar(":hello"), - Value, - DoubleQuotedScalar("world"), - Key, - PlainScalar(":goodbye"), - Value, - PlainScalar("world"), - BlockEnd, - BlockEnd, - StreamEnd); + public void Keys_can_start_with_colons_after_double_quoted_values_in_nested_block() + { + AssertSequenceOfTokensFrom(Yaml.ScannerForText("xyz:\n :hello: \"world\"\n :goodbye: world"), + StreamStart, + BlockMappingStart, + Key, + PlainScalar("xyz"), + Value, + BlockMappingStart, + Key, + PlainScalar(":hello"), + Value, + DoubleQuotedScalar("world"), + Key, + PlainScalar(":goodbye"), + Value, + PlainScalar("world"), + BlockEnd, + BlockEnd, + StreamEnd); } [Fact] diff --git a/YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs b/YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs index 913f5aa8..840c75a2 100644 --- a/YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs +++ b/YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs @@ -41,7 +41,7 @@ public void LoadSimpleDocument() var stream = new YamlStream(); stream.Load(Yaml.ReaderFrom("02-scalar-in-imp-doc.yaml")); - Assert.Equal(1, stream.Documents.Count); + Assert.Single(stream.Documents); Assert.IsType(stream.Documents[0].RootNode); Assert.Equal("a scalar", ((YamlScalarNode)stream.Documents[0].RootNode).Value); Assert.Equal(YamlNodeType.Scalar, stream.Documents[0].RootNode.NodeType); @@ -79,7 +79,7 @@ public void BackwardAliasReferenceWorks() var stream = new YamlStream(); stream.Load(Yaml.ReaderFrom("backwards-alias.yaml")); - Assert.Equal(1, stream.Documents.Count); + Assert.Single(stream.Documents); Assert.IsType(stream.Documents[0].RootNode); var sequence = (YamlSequenceNode)stream.Documents[0].RootNode; @@ -97,7 +97,7 @@ public void ForwardAliasReferenceWorks() var stream = new YamlStream(); stream.Load(Yaml.ReaderFrom("forward-alias.yaml")); - Assert.Equal(1, stream.Documents.Count); + Assert.Single(stream.Documents); Assert.IsType(stream.Documents[0].RootNode); var sequence = (YamlSequenceNode)stream.Documents[0].RootNode; diff --git a/YamlDotNet.Test/Serialization/BufferedDeserialization/KeyValueTypeDiscriminatorTests.cs b/YamlDotNet.Test/Serialization/BufferedDeserialization/KeyValueTypeDiscriminatorTests.cs index cf7f14f6..262e084c 100644 --- a/YamlDotNet.Test/Serialization/BufferedDeserialization/KeyValueTypeDiscriminatorTests.cs +++ b/YamlDotNet.Test/Serialization/BufferedDeserialization/KeyValueTypeDiscriminatorTests.cs @@ -1,4 +1,4 @@ -// This file is part of YamlDotNet - A .NET library for YAML. +// This file is part of YamlDotNet - A .NET library for YAML. // Copyright (c) Antoine Aubry and contributors // // Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -37,7 +37,8 @@ public void KeyValueTypeDiscriminator_WithParentBaseType_Single() { var bufferedDeserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithTypeDiscriminatingNodeDeserializer(options => { + .WithTypeDiscriminatingNodeDeserializer(options => + { options.AddKeyValueTypeDiscriminator( "kind", new Dictionary() @@ -45,7 +46,7 @@ public void KeyValueTypeDiscriminator_WithParentBaseType_Single() { "Namespace", typeof(KubernetesNamespace) }, { "Service", typeof(KubernetesService) } }); - }, + }, maxDepth: 3, maxLength: 40) .Build(); @@ -59,7 +60,8 @@ public void KeyValueTypeDiscriminator_WithParentBaseType_List() { var bufferedDeserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithTypeDiscriminatingNodeDeserializer(options => { + .WithTypeDiscriminatingNodeDeserializer(options => + { options.AddKeyValueTypeDiscriminator( "kind", new Dictionary() @@ -67,7 +69,7 @@ public void KeyValueTypeDiscriminator_WithParentBaseType_List() { "Namespace", typeof(KubernetesNamespace) }, { "Service", typeof(KubernetesService) } }); - }, + }, maxDepth: 3, maxLength: 40) .Build(); @@ -76,13 +78,14 @@ public void KeyValueTypeDiscriminator_WithParentBaseType_List() resources[0].Should().BeOfType(); resources[1].Should().BeOfType(); } - + [Fact] public void KeyValueTypeDiscriminator_WithObjectBaseType_Single() { var bufferedDeserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithTypeDiscriminatingNodeDeserializer(options => { + .WithTypeDiscriminatingNodeDeserializer(options => + { options.AddKeyValueTypeDiscriminator( "kind", new Dictionary() @@ -90,7 +93,7 @@ public void KeyValueTypeDiscriminator_WithObjectBaseType_Single() { "Namespace", typeof(KubernetesNamespace) }, { "Service", typeof(KubernetesService) } }); - }, + }, maxDepth: 3, maxLength: 40) .Build(); @@ -104,7 +107,8 @@ public void KeyValueTypeDiscriminator_WithObjectBaseType_List() { var bufferedDeserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithTypeDiscriminatingNodeDeserializer(options => { + .WithTypeDiscriminatingNodeDeserializer(options => + { options.AddKeyValueTypeDiscriminator( "kind", new Dictionary() @@ -112,7 +116,7 @@ public void KeyValueTypeDiscriminator_WithObjectBaseType_List() { "Namespace", typeof(KubernetesNamespace) }, { "Service", typeof(KubernetesService) } }); - }, + }, maxDepth: 3, maxLength: 30) .Build(); @@ -127,7 +131,8 @@ public void KeyValueTypeDiscriminator_WithInterfaceBaseType_Single() { var bufferedDeserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithTypeDiscriminatingNodeDeserializer(options => { + .WithTypeDiscriminatingNodeDeserializer(options => + { options.AddKeyValueTypeDiscriminator( "kind", new Dictionary() @@ -135,7 +140,7 @@ public void KeyValueTypeDiscriminator_WithInterfaceBaseType_Single() { "Namespace", typeof(KubernetesNamespace) }, { "Service", typeof(KubernetesService) } }); - }, + }, maxDepth: 3, maxLength: 40) .Build(); @@ -149,7 +154,8 @@ public void KeyValueTypeDiscriminator_WithInterfaceBaseType_List() { var bufferedDeserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithTypeDiscriminatingNodeDeserializer(options => { + .WithTypeDiscriminatingNodeDeserializer(options => + { options.AddKeyValueTypeDiscriminator( "kind", new Dictionary() @@ -157,7 +163,7 @@ public void KeyValueTypeDiscriminator_WithInterfaceBaseType_List() { "Namespace", typeof(KubernetesNamespace) }, { "Service", typeof(KubernetesService) } }); - }, + }, maxDepth: 3, maxLength: 30) .Build(); @@ -172,7 +178,8 @@ public void KeyValueTypeDiscriminator_MultipleWithSameKey() { var bufferedDeserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithTypeDiscriminatingNodeDeserializer(options => { + .WithTypeDiscriminatingNodeDeserializer(options => + { options.AddKeyValueTypeDiscriminator( "kind", new Dictionary() @@ -185,11 +192,11 @@ public void KeyValueTypeDiscriminator_MultipleWithSameKey() { { "Service", typeof(KubernetesService) } }); - }, + }, maxDepth: 3, maxLength: 40) .Build(); - + var resources = bufferedDeserializer.Deserialize>(ListOfKubernetesYaml); resources[0].Should().BeOfType(); resources[1].Should().BeOfType(); diff --git a/YamlDotNet.Test/Serialization/BufferedDeserialization/TypeDiscriminatingNodeDeserializerTests.cs b/YamlDotNet.Test/Serialization/BufferedDeserialization/TypeDiscriminatingNodeDeserializerTests.cs index 34ec355f..6550a253 100644 --- a/YamlDotNet.Test/Serialization/BufferedDeserialization/TypeDiscriminatingNodeDeserializerTests.cs +++ b/YamlDotNet.Test/Serialization/BufferedDeserialization/TypeDiscriminatingNodeDeserializerTests.cs @@ -1,4 +1,4 @@ -// This file is part of YamlDotNet - A .NET library for YAML. +// This file is part of YamlDotNet - A .NET library for YAML. // Copyright (c) Antoine Aubry and contributors // // Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -37,9 +37,10 @@ public void TypeDiscriminatingNodeDeserializer_ThrowsWhen_MaxDepthExceeded() { var bufferedDeserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithTypeDiscriminatingNodeDeserializer(options => { - options.AddKeyValueTypeDiscriminator("kind", new Dictionary()); - }, + .WithTypeDiscriminatingNodeDeserializer(options => + { + options.AddKeyValueTypeDiscriminator("kind", new Dictionary()); + }, maxDepth: 2, maxLength: 40) .Build(); @@ -51,15 +52,16 @@ public void TypeDiscriminatingNodeDeserializer_ThrowsWhen_MaxDepthExceeded() .WithInnerException() .Where(e => e.InnerException.Message.Contains("Parser buffer exceeded max depth")); } - + [Fact] public void TypeDiscriminatingNodeDeserializer_ThrowsWhen_MaxLengthExceeded() { var bufferedDeserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithTypeDiscriminatingNodeDeserializer(options => { - options.AddKeyValueTypeDiscriminator("kind", new Dictionary()); - }, + .WithTypeDiscriminatingNodeDeserializer(options => + { + options.AddKeyValueTypeDiscriminator("kind", new Dictionary()); + }, maxDepth: 3, maxLength: 20) .Build(); diff --git a/YamlDotNet.Test/Serialization/BufferedDeserialization/UniqueKeyTypeDiscriminatorTests.cs b/YamlDotNet.Test/Serialization/BufferedDeserialization/UniqueKeyTypeDiscriminatorTests.cs index 6d26e10c..d9978a5d 100644 --- a/YamlDotNet.Test/Serialization/BufferedDeserialization/UniqueKeyTypeDiscriminatorTests.cs +++ b/YamlDotNet.Test/Serialization/BufferedDeserialization/UniqueKeyTypeDiscriminatorTests.cs @@ -1,4 +1,4 @@ -// This file is part of YamlDotNet - A .NET library for YAML. +// This file is part of YamlDotNet - A .NET library for YAML. // Copyright (c) Antoine Aubry and contributors // // Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -37,7 +37,8 @@ public void UniqueKeyTypeDiscriminator_WithInterfaceBaseType() { var bufferedDeserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithTypeDiscriminatingNodeDeserializer(options => { + .WithTypeDiscriminatingNodeDeserializer(options => + { options.AddUniqueKeyTypeDiscriminator( new Dictionary() { @@ -45,7 +46,7 @@ public void UniqueKeyTypeDiscriminator_WithInterfaceBaseType() { "avgDailyMeows", typeof(Cat) } } ); - }, + }, maxDepth: 3, maxLength: 10) .Build(); @@ -60,7 +61,8 @@ public void UniqueKeyTypeDiscriminator_WithObjectBaseType() { var bufferedDeserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithTypeDiscriminatingNodeDeserializer(options => { + .WithTypeDiscriminatingNodeDeserializer(options => + { options.AddUniqueKeyTypeDiscriminator( new Dictionary() { @@ -68,7 +70,7 @@ public void UniqueKeyTypeDiscriminator_WithObjectBaseType() { "avgDailyMeows", typeof(Cat) } } ); - }, + }, maxDepth: 3, maxLength: 10) .Build(); diff --git a/YamlDotNet.Test/Serialization/HiddenPropertyTests.cs b/YamlDotNet.Test/Serialization/HiddenPropertyTests.cs index 9753752c..b8e71369 100644 --- a/YamlDotNet.Test/Serialization/HiddenPropertyTests.cs +++ b/YamlDotNet.Test/Serialization/HiddenPropertyTests.cs @@ -36,7 +36,7 @@ public class HiddenPropertyBase public object Value => this.value; - [YamlIgnore] + [YamlIgnore] public object SetOnly { set => this.value = value; } [YamlIgnore] diff --git a/YamlDotNet.Test/Serialization/SerializationTests.cs b/YamlDotNet.Test/Serialization/SerializationTests.cs index 3b83d5a9..ae927e8f 100644 --- a/YamlDotNet.Test/Serialization/SerializationTests.cs +++ b/YamlDotNet.Test/Serialization/SerializationTests.cs @@ -2447,7 +2447,7 @@ public void SerializeStateMethodsGetCalledOnce() Assert.Equal(1, test.OnSerializedCallCount); Assert.Equal(1, test.OnSerializingCallCount); } - + [Fact] public void SerializeConcurrently() { @@ -2459,7 +2459,7 @@ public void SerializeConcurrently() // Failures don't occur consistently - running repeatedly increases the chances RunTest(); } - + Assert.Empty(exceptions); void RunTest() @@ -2469,7 +2469,7 @@ void RunTest() var control = new SemaphoreSlim(0, threadCount); var serializer = new SerializerBuilder().Build(); - + for (var i = 0; i < threadCount; i++) { threads.Add(new Thread(Serialize)); @@ -2480,7 +2480,7 @@ void RunTest() // Release them all simultaneously to try to maximise concurrency control.Release(threadCount); threads.ForEach(t => t.Join()); - + void Serialize() { control.Wait(); diff --git a/YamlDotNet.Test/Serialization/YamlCommentTests.cs b/YamlDotNet.Test/Serialization/YamlCommentTests.cs index 23689bd0..eedd1842 100644 --- a/YamlDotNet.Test/Serialization/YamlCommentTests.cs +++ b/YamlDotNet.Test/Serialization/YamlCommentTests.cs @@ -1,4 +1,25 @@ -using System; +// This file is part of YamlDotNet - A .NET library for YAML. +// Copyright (c) Antoine Aubry and contributors +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is furnished to do +// so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; using FluentAssertions; using Xunit; using Xunit.Abstractions; diff --git a/YamlDotNet.Test/YamlDotNet.Test.csproj b/YamlDotNet.Test/YamlDotNet.Test.csproj index e77ac799..50a46470 100644 --- a/YamlDotNet.Test/YamlDotNet.Test.csproj +++ b/YamlDotNet.Test/YamlDotNet.Test.csproj @@ -1,4 +1,4 @@ - + net8.0;net6.0;net47 false diff --git a/YamlDotNet/YamlDotNet.csproj b/YamlDotNet/YamlDotNet.csproj index 704715a1..e76a80f0 100644 --- a/YamlDotNet/YamlDotNet.csproj +++ b/YamlDotNet/YamlDotNet.csproj @@ -44,10 +44,6 @@ $(DefineConstants);RELEASE;TRACE;SIGNED - - true - -