-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Adds negative smoke tests for nullable fields and properties
If they are not declared in code.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...ContextAndDeclareFieldAsNullable/ClassFieldCannotBeDeclaredAsNullableNotDeclaredInCode.cs
This file contains 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,23 @@ | ||
// ReSharper disable All | ||
|
||
namespace CSharp80.NullableReferenceTypes.EnableNullableContextAndDeclareFieldAsNullable | ||
{ | ||
public class ClassFieldCannotBeDeclaredAsNullableNotDeclaredInCode | ||
{ | ||
public void FieldIsNullableForDifferentReasons() | ||
{ | ||
string dummy; | ||
|
||
if (string.Empty == null) return; | ||
if (null == string.Empty) return; | ||
if (string.Empty != null) return; | ||
if (null != string.Empty) return; | ||
if (string.Empty == null) return; | ||
if (null == string.Empty) return; | ||
|
||
string.Empty?.Length.ToString(); | ||
|
||
dummy = string.Empty ?? string.Empty; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...tAndDeclarePropertyAsNullable/ClassPropertyCannotBeDeclaredAsNullableNotDeclaredInCode.cs
This file contains 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,28 @@ | ||
// ReSharper disable All | ||
|
||
using System; | ||
using System.Net.Http; | ||
|
||
namespace CSharp80.NullableReferenceTypes.EnableNullableContextAndDeclarePropertyAsNullable | ||
{ | ||
public class ClassPropertyCannotBeDeclaredAsNullableNotDeclaredInCode | ||
{ | ||
public void PropertyIsNullableForDifferentReasons() | ||
{ | ||
HttpClient httpClient = new HttpClient(); | ||
|
||
httpClient.BaseAddress = null; | ||
|
||
if (httpClient.BaseAddress == null) return; | ||
if (null == httpClient.BaseAddress) return; | ||
if (httpClient.BaseAddress != null) return; | ||
if (null != httpClient.BaseAddress) return; | ||
if (httpClient.BaseAddress == null) return; | ||
if (null == httpClient.BaseAddress) return; | ||
|
||
httpClient.BaseAddress?.ToString(); | ||
|
||
var dummy = httpClient.BaseAddress ?? new Uri(""); | ||
} | ||
} | ||
} |