Skip to content

Commit

Permalink
Add test for NotImplementedException
Browse files Browse the repository at this point in the history
  • Loading branch information
febinjoy committed Jan 2, 2024
1 parent d3568ac commit 8178d35
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
5 changes: 2 additions & 3 deletions LeetCodeSolutions/Temp/QEasySample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace LeetCodeSolutions.Questions.Easy
{
internal class QEasySample : IQuestion
public class QEasySample : IQuestion
{
public int QuestionNumber { get; private set; }
public string QuestionText { get; private set; }
Expand All @@ -23,5 +23,4 @@ public IResult Execute()
throw new NotImplementedException();
}
}
}

}
1 change: 1 addition & 0 deletions LeetCodeSolutionsTest/LeetCodeSolutionsTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
Expand Down
26 changes: 24 additions & 2 deletions LeetCodeSolutionsTest/QuestionServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using LeetCodeSolutions;
using LeetCodeSolutions.Exceptions;
using LeetCodeSolutions.Interfaces;
using LeetCodeSolutions.Questions.Easy;
using NSubstitute;
using NSubstitute.ExceptionExtensions;

namespace LeetCodeSolutionsTest
{
Expand All @@ -16,8 +20,26 @@ public void Setup()
[Test]
public void ExecuteQuestion_UnknownQuestionNumber_ThrowsQuestionNotFoundException()
{
// Arrange + Act + Assert
Assert.Throws<QuestionNotFoundException>(() => questionService.ExecuteQuestion(99999999));
// Arrange
int questionNumber = 99999999;

// Act + Assert
Assert.Throws<QuestionNotFoundException>(() => questionService.ExecuteQuestion(questionNumber));
}

[Test]
public void ExecuteQuestion_NotImplementedQuestion_ThrowsNotImplementedException()
{
// Arrange
int questionNumber = 0;
var mockQuestionFactory = Substitute.For<IQuestionFactory>();
var mockQuestion = Substitute.For<IQuestion>();

mockQuestionFactory.GetQuestionByNumber(questionNumber).Returns(new QEasySample());
mockQuestion.Execute().Throws(new NotImplementedException());

// Act + Assert
Assert.Throws<NotImplementedException>(() => questionService.ExecuteQuestion(questionNumber));
}
}
}

0 comments on commit 8178d35

Please sign in to comment.