Skip to content

Commit

Permalink
test: Adds negative smoke tests for nullable fields and properties
Browse files Browse the repository at this point in the history
If they are not declared in code.
  • Loading branch information
ironcev committed Jun 18, 2019
1 parent 6bd19a6 commit 210df6c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
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;
}
}
}
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("");
}
}
}

0 comments on commit 210df6c

Please sign in to comment.