Skip to content

Commit f8c9f63

Browse files
author
Muhammad Rehan Saeed
committed
Add HasValue
1 parent d1d4faf commit f8c9f63

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

Source/Schema.NET/Values{T1,T2,T3,T4}.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ public Values(IEnumerable<object> items)
122122
/// </summary>
123123
public int Count => this.Value1.Count + this.Value2.Count + this.Value3.Count + this.Value4.Count;
124124

125+
/// <summary>
126+
/// Gets a value indicating whether this instance has a value.
127+
/// </summary>
128+
public bool HasValue => this.HasValue1 || this.HasValue2 || this.HasValue3 || this.HasValue4;
129+
125130
/// <summary>
126131
/// Gets whether the value of type <typeparamref name="T1" /> has a value.
127132
/// </summary>

Source/Schema.NET/Values{T1,T2,T3}.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ public Values(IEnumerable<object> items)
9696
/// </summary>
9797
public int Count => this.Value1.Count + this.Value2.Count + this.Value3.Count;
9898

99+
/// <summary>
100+
/// Gets a value indicating whether this instance has a value.
101+
/// </summary>
102+
public bool HasValue => this.HasValue1 || this.HasValue2 || this.HasValue3;
103+
99104
/// <summary>
100105
/// Gets whether the value of type <typeparamref name="T1" /> has a value.
101106
/// </summary>

Source/Schema.NET/Values{T1,T2}.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public Values(IEnumerable<object> items)
7474
/// </summary>
7575
public int Count => this.Value1.Count + this.Value2.Count;
7676

77+
/// <summary>
78+
/// Gets a value indicating whether this instance has a value.
79+
/// </summary>
80+
public bool HasValue => this.HasValue1 || this.HasValue2;
81+
7782
/// <summary>
7883
/// Gets whether the value of type <typeparamref name="T1" /> has a value.
7984
/// </summary>

Tests/Schema.NET.Test/Values2Test.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ public void Constructor_NullList_ThrowsArgumentNullException() =>
5858
public void Count_Items_ReturnsExpectedCount(int expectedCount, params object[] items) =>
5959
Assert.Equal(expectedCount, new Values<int, string>(items).Count);
6060

61+
[Fact]
62+
public void HasValue_DoesntHaveValue_ReturnsFalse() =>
63+
Assert.False(default(Values<int, string>).HasValue);
64+
65+
[Theory]
66+
[InlineData(1)]
67+
[InlineData("Foo")]
68+
public void HasValue_HasValue_ReturnsTrue(params object[] parameters) =>
69+
Assert.True(new Values<int, string>(parameters).HasValue);
70+
6171
[Fact]
6272
public void HasValue1_HasValue_ReturnsTrue() => Assert.True(new Values<int, string>(1).HasValue1);
6373

Tests/Schema.NET.Test/Values3Test.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ public void Constructor_NullList_ThrowsArgumentNullException() =>
7676
public void Count_Items_ReturnsExpectedCount(int expectedCount, params object[] items) =>
7777
Assert.Equal(expectedCount, new Values<int, string, DayOfWeek>(items).Count);
7878

79+
[Fact]
80+
public void HasValue_DoesntHaveValue_ReturnsFalse() =>
81+
Assert.False(default(Values<int, string, DayOfWeek>).HasValue);
82+
83+
[Theory]
84+
[InlineData(1)]
85+
[InlineData("Foo")]
86+
[InlineData(DayOfWeek.Friday)]
87+
public void HasValue_HasValue_ReturnsTrue(params object[] parameters) =>
88+
Assert.True(new Values<int, string, DayOfWeek>(parameters).HasValue);
89+
7990
[Fact]
8091
public void HasValue1_HasValue_ReturnsTrue() =>
8192
Assert.True(new Values<int, string, DayOfWeek>(1).HasValue1);

Tests/Schema.NET.Test/Values4Test.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ public void Constructor_NullList_ThrowsArgumentNullException() =>
9696
public void Count_Items_ReturnsExpectedCount(int expectedCount, params object[] items) =>
9797
Assert.Equal(expectedCount, new Values<int, string, DayOfWeek, Person>(items).Count);
9898

99+
[Fact]
100+
public void HasValue_DoesntHaveValue_ReturnsFalse() =>
101+
Assert.False(default(Values<int, string, DayOfWeek, Person>).HasValue);
102+
103+
[Theory]
104+
[InlineData(1)]
105+
[InlineData("Foo")]
106+
[InlineData(DayOfWeek.Friday)]
107+
public void HasValue_HasValue_ReturnsTrue(params object[] parameters) =>
108+
Assert.True(new Values<int, string, DayOfWeek, Person>(parameters).HasValue);
109+
99110
[Fact]
100111
public void HasValue1_HasValue_ReturnsTrue() =>
101112
Assert.True(new Values<int, string, DayOfWeek, Person>(1).HasValue1);

0 commit comments

Comments
 (0)