Skip to content

Commit 0f6184b

Browse files
committed
Add [NotNull] attribute on the Should() method for Nullable<> assertions
1 parent 135302b commit 0f6184b

File tree

7 files changed

+100
-93
lines changed

7 files changed

+100
-93
lines changed

Src/FluentAssertions/AssertionExtensions.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public static BooleanAssertions Should(this bool actualValue)
300300
/// current nullable <see cref="bool"/>.
301301
/// </summary>
302302
[Pure]
303-
public static NullableBooleanAssertions Should(this bool? actualValue)
303+
public static NullableBooleanAssertions Should([NotNull] this bool? actualValue)
304304
{
305305
return new NullableBooleanAssertions(actualValue);
306306
}
@@ -330,7 +330,7 @@ public static GuidAssertions Should(this Guid actualValue)
330330
/// current nullable <see cref="Guid"/>.
331331
/// </summary>
332332
[Pure]
333-
public static NullableGuidAssertions Should(this Guid? actualValue)
333+
public static NullableGuidAssertions Should([NotNull] this Guid? actualValue)
334334
{
335335
return new NullableGuidAssertions(actualValue);
336336
}
@@ -454,7 +454,7 @@ public static DateTimeOffsetAssertions Should(this DateTimeOffset actualValue)
454454
/// current nullable <see cref="DateTime"/>.
455455
/// </summary>
456456
[Pure]
457-
public static NullableDateTimeAssertions Should(this DateTime? actualValue)
457+
public static NullableDateTimeAssertions Should([NotNull] this DateTime? actualValue)
458458
{
459459
return new NullableDateTimeAssertions(actualValue);
460460
}
@@ -464,7 +464,7 @@ public static NullableDateTimeAssertions Should(this DateTime? actualValue)
464464
/// current nullable <see cref="DateTimeOffset"/>.
465465
/// </summary>
466466
[Pure]
467-
public static NullableDateTimeOffsetAssertions Should(this DateTimeOffset? actualValue)
467+
public static NullableDateTimeOffsetAssertions Should([NotNull] this DateTimeOffset? actualValue)
468468
{
469469
return new NullableDateTimeOffsetAssertions(actualValue);
470470
}
@@ -485,7 +485,7 @@ public static DateOnlyAssertions Should(this DateOnly actualValue)
485485
/// current nullable <see cref="DateOnly"/>.
486486
/// </summary>
487487
[Pure]
488-
public static NullableDateOnlyAssertions Should(this DateOnly? actualValue)
488+
public static NullableDateOnlyAssertions Should([NotNull] this DateOnly? actualValue)
489489
{
490490
return new NullableDateOnlyAssertions(actualValue);
491491
}
@@ -505,7 +505,7 @@ public static TimeOnlyAssertions Should(this TimeOnly actualValue)
505505
/// current nullable <see cref="TimeOnly"/>.
506506
/// </summary>
507507
[Pure]
508-
public static NullableTimeOnlyAssertions Should(this TimeOnly? actualValue)
508+
public static NullableTimeOnlyAssertions Should([NotNull] this TimeOnly? actualValue)
509509
{
510510
return new NullableTimeOnlyAssertions(actualValue);
511511
}
@@ -537,7 +537,7 @@ public static NumericAssertions<int> Should(this int actualValue)
537537
/// current nullable <see cref="int"/>.
538538
/// </summary>
539539
[Pure]
540-
public static NullableNumericAssertions<int> Should(this int? actualValue)
540+
public static NullableNumericAssertions<int> Should([NotNull] this int? actualValue)
541541
{
542542
return new NullableInt32Assertions(actualValue);
543543
}
@@ -557,7 +557,7 @@ public static NumericAssertions<uint> Should(this uint actualValue)
557557
/// current nullable <see cref="uint"/>.
558558
/// </summary>
559559
[Pure]
560-
public static NullableNumericAssertions<uint> Should(this uint? actualValue)
560+
public static NullableNumericAssertions<uint> Should([NotNull] this uint? actualValue)
561561
{
562562
return new NullableUInt32Assertions(actualValue);
563563
}
@@ -577,7 +577,7 @@ public static NumericAssertions<decimal> Should(this decimal actualValue)
577577
/// current nullable <see cref="decimal"/>.
578578
/// </summary>
579579
[Pure]
580-
public static NullableNumericAssertions<decimal> Should(this decimal? actualValue)
580+
public static NullableNumericAssertions<decimal> Should([NotNull] this decimal? actualValue)
581581
{
582582
return new NullableDecimalAssertions(actualValue);
583583
}
@@ -597,7 +597,7 @@ public static NumericAssertions<byte> Should(this byte actualValue)
597597
/// current nullable <see cref="byte"/>.
598598
/// </summary>
599599
[Pure]
600-
public static NullableNumericAssertions<byte> Should(this byte? actualValue)
600+
public static NullableNumericAssertions<byte> Should([NotNull] this byte? actualValue)
601601
{
602602
return new NullableByteAssertions(actualValue);
603603
}
@@ -617,7 +617,7 @@ public static NumericAssertions<sbyte> Should(this sbyte actualValue)
617617
/// current nullable <see cref="sbyte"/>.
618618
/// </summary>
619619
[Pure]
620-
public static NullableNumericAssertions<sbyte> Should(this sbyte? actualValue)
620+
public static NullableNumericAssertions<sbyte> Should([NotNull] this sbyte? actualValue)
621621
{
622622
return new NullableSByteAssertions(actualValue);
623623
}
@@ -637,7 +637,7 @@ public static NumericAssertions<short> Should(this short actualValue)
637637
/// current nullable <see cref="short"/>.
638638
/// </summary>
639639
[Pure]
640-
public static NullableNumericAssertions<short> Should(this short? actualValue)
640+
public static NullableNumericAssertions<short> Should([NotNull] this short? actualValue)
641641
{
642642
return new NullableInt16Assertions(actualValue);
643643
}
@@ -657,7 +657,7 @@ public static NumericAssertions<ushort> Should(this ushort actualValue)
657657
/// current nullable <see cref="ushort"/>.
658658
/// </summary>
659659
[Pure]
660-
public static NullableNumericAssertions<ushort> Should(this ushort? actualValue)
660+
public static NullableNumericAssertions<ushort> Should([NotNull] this ushort? actualValue)
661661
{
662662
return new NullableUInt16Assertions(actualValue);
663663
}
@@ -677,7 +677,7 @@ public static NumericAssertions<long> Should(this long actualValue)
677677
/// current nullable <see cref="long"/>.
678678
/// </summary>
679679
[Pure]
680-
public static NullableNumericAssertions<long> Should(this long? actualValue)
680+
public static NullableNumericAssertions<long> Should([NotNull] this long? actualValue)
681681
{
682682
return new NullableInt64Assertions(actualValue);
683683
}
@@ -697,7 +697,7 @@ public static NumericAssertions<ulong> Should(this ulong actualValue)
697697
/// current nullable <see cref="ulong"/>.
698698
/// </summary>
699699
[Pure]
700-
public static NullableNumericAssertions<ulong> Should(this ulong? actualValue)
700+
public static NullableNumericAssertions<ulong> Should([NotNull] this ulong? actualValue)
701701
{
702702
return new NullableUInt64Assertions(actualValue);
703703
}
@@ -717,7 +717,7 @@ public static NumericAssertions<float> Should(this float actualValue)
717717
/// current nullable <see cref="float"/>.
718718
/// </summary>
719719
[Pure]
720-
public static NullableNumericAssertions<float> Should(this float? actualValue)
720+
public static NullableNumericAssertions<float> Should([NotNull] this float? actualValue)
721721
{
722722
return new NullableSingleAssertions(actualValue);
723723
}
@@ -737,7 +737,7 @@ public static NumericAssertions<double> Should(this double actualValue)
737737
/// current nullable <see cref="double"/>.
738738
/// </summary>
739739
[Pure]
740-
public static NullableNumericAssertions<double> Should(this double? actualValue)
740+
public static NullableNumericAssertions<double> Should([NotNull] this double? actualValue)
741741
{
742742
return new NullableDoubleAssertions(actualValue);
743743
}
@@ -767,7 +767,7 @@ public static SimpleTimeSpanAssertions Should(this TimeSpan actualValue)
767767
/// current nullable <see cref="TimeSpan"/>.
768768
/// </summary>
769769
[Pure]
770-
public static NullableSimpleTimeSpanAssertions Should(this TimeSpan? actualValue)
770+
public static NullableSimpleTimeSpanAssertions Should([NotNull] this TimeSpan? actualValue)
771771
{
772772
return new NullableSimpleTimeSpanAssertions(actualValue);
773773
}

Src/FluentAssertions/EnumAssertionsExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Diagnostics;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Diagnostics.Contracts;
45
using FluentAssertions.Primitives;
56

@@ -27,7 +28,7 @@ public static EnumAssertions<TEnum> Should<TEnum>(this TEnum @enum)
2728
/// current <typeparamref name="TEnum"/>.
2829
/// </summary>
2930
[Pure]
30-
public static NullableEnumAssertions<TEnum> Should<TEnum>(this TEnum? @enum)
31+
public static NullableEnumAssertions<TEnum> Should<TEnum>([NotNull] this TEnum? @enum)
3132
where TEnum : struct, Enum
3233
{
3334
return new NullableEnumAssertions<TEnum>(@enum);

Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ namespace FluentAssertions
6464
public static FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataRow> Should([System.Diagnostics.CodeAnalysis.NotNull] this System.Data.DataRowCollection actualValue) { }
6565
public static FluentAssertions.Collections.GenericCollectionAssertions<System.Data.DataTable> Should([System.Diagnostics.CodeAnalysis.NotNull] this System.Data.DataTableCollection actualValue) { }
6666
public static FluentAssertions.Primitives.DateTimeAssertions Should(this System.DateTime actualValue) { }
67-
public static FluentAssertions.Primitives.NullableDateTimeAssertions Should(this System.DateTime? actualValue) { }
67+
public static FluentAssertions.Primitives.NullableDateTimeAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.DateTime? actualValue) { }
6868
public static FluentAssertions.Primitives.DateTimeOffsetAssertions Should(this System.DateTimeOffset actualValue) { }
69-
public static FluentAssertions.Primitives.NullableDateTimeOffsetAssertions Should(this System.DateTimeOffset? actualValue) { }
69+
public static FluentAssertions.Primitives.NullableDateTimeOffsetAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.DateTimeOffset? actualValue) { }
7070
public static FluentAssertions.Specialized.NonGenericAsyncFunctionAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.Func<System.Threading.Tasks.Task> action) { }
7171
public static FluentAssertions.Primitives.GuidAssertions Should(this System.Guid actualValue) { }
72-
public static FluentAssertions.Primitives.NullableGuidAssertions Should(this System.Guid? actualValue) { }
72+
public static FluentAssertions.Primitives.NullableGuidAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.Guid? actualValue) { }
7373
public static FluentAssertions.Streams.BufferedStreamAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.IO.BufferedStream actualValue) { }
7474
public static FluentAssertions.Streams.StreamAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.IO.Stream actualValue) { }
7575
public static FluentAssertions.Primitives.HttpResponseMessageAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.Net.Http.HttpResponseMessage actualValue) { }
@@ -78,37 +78,37 @@ namespace FluentAssertions
7878
public static FluentAssertions.Types.MethodInfoAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.Reflection.MethodInfo methodInfo) { }
7979
public static FluentAssertions.Types.PropertyInfoAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.Reflection.PropertyInfo propertyInfo) { }
8080
public static FluentAssertions.Primitives.SimpleTimeSpanAssertions Should(this System.TimeSpan actualValue) { }
81-
public static FluentAssertions.Primitives.NullableSimpleTimeSpanAssertions Should(this System.TimeSpan? actualValue) { }
81+
public static FluentAssertions.Primitives.NullableSimpleTimeSpanAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.TimeSpan? actualValue) { }
8282
public static FluentAssertions.Types.TypeAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.Type subject) { }
8383
public static FluentAssertions.Xml.XAttributeAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.Xml.Linq.XAttribute actualValue) { }
8484
public static FluentAssertions.Xml.XDocumentAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.Xml.Linq.XDocument actualValue) { }
8585
public static FluentAssertions.Xml.XElementAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this System.Xml.Linq.XElement actualValue) { }
8686
public static FluentAssertions.Primitives.BooleanAssertions Should(this bool actualValue) { }
87-
public static FluentAssertions.Primitives.NullableBooleanAssertions Should(this bool? actualValue) { }
87+
public static FluentAssertions.Primitives.NullableBooleanAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this bool? actualValue) { }
8888
public static FluentAssertions.Numeric.NumericAssertions<byte> Should(this byte actualValue) { }
89-
public static FluentAssertions.Numeric.NullableNumericAssertions<byte> Should(this byte? actualValue) { }
89+
public static FluentAssertions.Numeric.NullableNumericAssertions<byte> Should([System.Diagnostics.CodeAnalysis.NotNull] this byte? actualValue) { }
9090
public static FluentAssertions.Numeric.NumericAssertions<decimal> Should(this decimal actualValue) { }
91-
public static FluentAssertions.Numeric.NullableNumericAssertions<decimal> Should(this decimal? actualValue) { }
91+
public static FluentAssertions.Numeric.NullableNumericAssertions<decimal> Should([System.Diagnostics.CodeAnalysis.NotNull] this decimal? actualValue) { }
9292
public static FluentAssertions.Numeric.NumericAssertions<double> Should(this double actualValue) { }
93-
public static FluentAssertions.Numeric.NullableNumericAssertions<double> Should(this double? actualValue) { }
93+
public static FluentAssertions.Numeric.NullableNumericAssertions<double> Should([System.Diagnostics.CodeAnalysis.NotNull] this double? actualValue) { }
9494
public static FluentAssertions.Numeric.NumericAssertions<float> Should(this float actualValue) { }
95-
public static FluentAssertions.Numeric.NullableNumericAssertions<float> Should(this float? actualValue) { }
95+
public static FluentAssertions.Numeric.NullableNumericAssertions<float> Should([System.Diagnostics.CodeAnalysis.NotNull] this float? actualValue) { }
9696
public static FluentAssertions.Numeric.NumericAssertions<int> Should(this int actualValue) { }
97-
public static FluentAssertions.Numeric.NullableNumericAssertions<int> Should(this int? actualValue) { }
97+
public static FluentAssertions.Numeric.NullableNumericAssertions<int> Should([System.Diagnostics.CodeAnalysis.NotNull] this int? actualValue) { }
9898
public static FluentAssertions.Numeric.NumericAssertions<long> Should(this long actualValue) { }
99-
public static FluentAssertions.Numeric.NullableNumericAssertions<long> Should(this long? actualValue) { }
99+
public static FluentAssertions.Numeric.NullableNumericAssertions<long> Should([System.Diagnostics.CodeAnalysis.NotNull] this long? actualValue) { }
100100
public static FluentAssertions.Primitives.ObjectAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this object actualValue) { }
101101
public static FluentAssertions.Numeric.NumericAssertions<sbyte> Should(this sbyte actualValue) { }
102-
public static FluentAssertions.Numeric.NullableNumericAssertions<sbyte> Should(this sbyte? actualValue) { }
102+
public static FluentAssertions.Numeric.NullableNumericAssertions<sbyte> Should([System.Diagnostics.CodeAnalysis.NotNull] this sbyte? actualValue) { }
103103
public static FluentAssertions.Numeric.NumericAssertions<short> Should(this short actualValue) { }
104-
public static FluentAssertions.Numeric.NullableNumericAssertions<short> Should(this short? actualValue) { }
104+
public static FluentAssertions.Numeric.NullableNumericAssertions<short> Should([System.Diagnostics.CodeAnalysis.NotNull] this short? actualValue) { }
105105
public static FluentAssertions.Primitives.StringAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this string actualValue) { }
106106
public static FluentAssertions.Numeric.NumericAssertions<uint> Should(this uint actualValue) { }
107-
public static FluentAssertions.Numeric.NullableNumericAssertions<uint> Should(this uint? actualValue) { }
107+
public static FluentAssertions.Numeric.NullableNumericAssertions<uint> Should([System.Diagnostics.CodeAnalysis.NotNull] this uint? actualValue) { }
108108
public static FluentAssertions.Numeric.NumericAssertions<ulong> Should(this ulong actualValue) { }
109-
public static FluentAssertions.Numeric.NullableNumericAssertions<ulong> Should(this ulong? actualValue) { }
109+
public static FluentAssertions.Numeric.NullableNumericAssertions<ulong> Should([System.Diagnostics.CodeAnalysis.NotNull] this ulong? actualValue) { }
110110
public static FluentAssertions.Numeric.NumericAssertions<ushort> Should(this ushort actualValue) { }
111-
public static FluentAssertions.Numeric.NullableNumericAssertions<ushort> Should(this ushort? actualValue) { }
111+
public static FluentAssertions.Numeric.NullableNumericAssertions<ushort> Should([System.Diagnostics.CodeAnalysis.NotNull] this ushort? actualValue) { }
112112
[System.Obsolete(("You are asserting the \'AndConstraint\' itself. Remove the \'Should()\' method direct" +
113113
"ly following \'And\'"), true)]
114114
public static void Should<TAssertions>(this FluentAssertions.Primitives.BooleanAssertions<TAssertions> _)
@@ -239,7 +239,7 @@ namespace FluentAssertions
239239
{
240240
public static FluentAssertions.Primitives.EnumAssertions<TEnum> Should<TEnum>(this TEnum @enum)
241241
where TEnum : struct, System.Enum { }
242-
public static FluentAssertions.Primitives.NullableEnumAssertions<TEnum> Should<TEnum>(this TEnum? @enum)
242+
public static FluentAssertions.Primitives.NullableEnumAssertions<TEnum> Should<TEnum>([System.Diagnostics.CodeAnalysis.NotNull] this TEnum? @enum)
243243
where TEnum : struct, System.Enum { }
244244
}
245245
public class EquivalencyPlan : System.Collections.Generic.IEnumerable<FluentAssertions.Equivalency.IEquivalencyStep>, System.Collections.IEnumerable

0 commit comments

Comments
 (0)