Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public int GetSum(ArrayList arrayList)
return Sum;
}

public ArrayList MixedTypes { get; set; } = new() { 1, "two", DateTime.Now };

public int ReadFirstAsInt() => (int)MixedTypes[0]!;

public int ReadSecondAsInt() => (int)MixedTypes[1]!;

public void ListExample()
{
Sum = 0;
Expand Down
16 changes: 16 additions & 0 deletions collections-lists/ArrayListVsList/Tests/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ public void WhenValidObjectsAddedToList_ThenSumSuccessful()
Assert.Equal(expectedResult, _collection.Sum);
}

[Fact]
public void WhenMixedTypeArrayListReadWithMatchingCast_ThenValueReturned()
{
var expectedResult = 1;

var actualResult = _collection.ReadFirstAsInt();

Assert.Equal(expectedResult, actualResult);
}

[Fact]
public void WhenMixedTypeArrayListReadWithWrongCast_ThenInvalidCastExceptionThrown()
{
Assert.Throws<InvalidCastException>(() => _collection.ReadSecondAsInt());
}

[Fact]
public void WhenInvalidObjectsAddedToArrayList_ThenSumFail()
{
Expand Down
2 changes: 1 addition & 1 deletion collections-lists/ArrayListVsList/Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
Loading