Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support with NUnit for testing #181

Merged
merged 2 commits into from
Apr 17, 2023
Merged
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
@@ -1,17 +1,16 @@
namespace DentallApp.UnitTests.DataAccess.Repositories;

[TestClass]
public class RepositoryExtensionsTests
{
private IRepository<UserRole> _repository;

[TestInitialize]
[SetUp]
public void TestInitialize()
{
_repository = Mock.Create<IRepository<UserRole>>();
}

[TestMethod]
[Test]
public void AddOrUpdateOrDelete_WhenNumberOfElementsAreEqual_ShouldMergeSequenceOfElements()
{
// Arrange
Expand Down Expand Up @@ -45,7 +44,7 @@ public void AddOrUpdateOrDelete_WhenNumberOfElementsAreEqual_ShouldMergeSequence
rolesId[1].Should().Be(RolesId.Admin);
}

[TestMethod]
[Test]
public void AddOrUpdateOrDelete_WhenIdentifiersDoNotContainsTheSecondaryForeignKey_ShouldDeleteCurrentEntity()
{
// Arrange
Expand Down Expand Up @@ -83,7 +82,7 @@ public void AddOrUpdateOrDelete_WhenIdentifiersDoNotContainsTheSecondaryForeignK
}


[TestMethod]
[Test]
public void AddOrUpdateOrDelete_WhenSourceDoNotContainsTheIdentifier_ShouldInsertCurrentEntity()
{
// Arrange
Expand Down
5 changes: 3 additions & 2 deletions tests/DentallApp.UnitTests/DentallApp.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
<PackageReference Include="JustMock" Version="2022.3.912.3" />
<PackageReference Include="Microsoft.Bot.Builder.Testing" Version="4.18.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
namespace DentallApp.UnitTests.Features.AppointmentCancellation;

[TestClass]
public class AppointmentCancellationServiceTests
{
private IAppointmentCancellationRepository _appointmentRepository;
private IDateTimeProvider _dateTimeProvider;
private AppointmentCancellationService _appointmentService;

[TestInitialize]
[SetUp]
public void TestInitialize()
{
_appointmentRepository = Mock.Create<IAppointmentCancellationRepository>();
Expand All @@ -17,7 +16,7 @@ public void TestInitialize()
_dateTimeProvider);
}

[TestMethod]
[Test]
public async Task CancelAppointmentsAsync_WhenAllAppointmentsCanBeCancelled_ShouldReturnsAnResponseWithoutAppointmentsId()
{
// Arrange
Expand Down Expand Up @@ -48,7 +47,7 @@ public async Task CancelAppointmentsAsync_WhenAllAppointmentsCanBeCancelled_Shou
response.Data.Should().BeNull();
}

[TestMethod]
[Test]
public async Task CancelAppointmentsAsync_WhenSomeAppointmentsCannotBeCancelled_ShouldReturnsAnResponseWithAppointmentsId()
{
// Arrange
Expand Down Expand Up @@ -86,7 +85,7 @@ public async Task CancelAppointmentsAsync_WhenSomeAppointmentsCannotBeCancelled_
.BeEquivalentTo(new[] { 4, 5 });
}

[TestMethod]
[Test]
public async Task CancelAppointmentsAsync_WhenAppointmentsCannotBeCancelled_ShouldReturnsAnResponseWithAppointmentsId()
{
// Arrange
Expand Down Expand Up @@ -124,7 +123,7 @@ public async Task CancelAppointmentsAsync_WhenAppointmentsCannotBeCancelled_Shou
.BeEquivalentTo(new[] { 1, 2, 3, 4, 5 });
}

[TestMethod]
[Test]
public async Task CancelBasicUserAppointmentAsync_WhenAppointmentCannotBeCancelled_ShouldReturnsFailureResponse()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace DentallApp.UnitTests.Features.AvailabilityHours;

[TestClass]
public class AvailabilityServiceTests
{
private IAppointmentRepository _appointmentRepository;
Expand All @@ -10,7 +9,7 @@ public class AvailabilityServiceTests
private AvailabilityService _availabilityService;
private IDateTimeProvider _dateTimeProvider;

[TestInitialize]
[SetUp]
public void TestInitialize()
{
_appointmentRepository = Mock.Create<IAppointmentRepository>();
Expand All @@ -25,7 +24,7 @@ public void TestInitialize()
_dateTimeProvider);
}

[TestMethod]
[Test]
public async Task GetAvailableHoursAsync_WhenAppointmentDateIsPublicHoliday_ShouldReturnsAnErrorMessage()
{
// Arrange
Expand All @@ -42,7 +41,7 @@ public async Task GetAvailableHoursAsync_WhenAppointmentDateIsPublicHoliday_Shou
response.Message.Should().Be(AppointmentDateIsPublicHolidayMessage);
}

[TestMethod]
[Test]
public async Task GetAvailableHoursAsync_WhenDentistIsNotAvailableOnGivenDay_ShouldReturnsAnErrorMessage()
{
// Arrange
Expand All @@ -60,7 +59,7 @@ public async Task GetAvailableHoursAsync_WhenDentistIsNotAvailableOnGivenDay_Sho
response.Message.Should().Be(expectedMessage);
}

[TestMethod]
[Test]
public async Task GetAvailableHoursAsync_WhenEmployeeScheduleIsInactive_ShouldReturnsAnErrorMessage()
{
// Arrange
Expand All @@ -78,7 +77,7 @@ public async Task GetAvailableHoursAsync_WhenEmployeeScheduleIsInactive_ShouldRe
response.Message.Should().Be(expectedMessage);
}

[TestMethod]
[Test]
public async Task GetAvailableHoursAsync_WhenOfficeScheduleIsInactive_ShouldReturnsAnErrorMessage()
{
// Arrange
Expand All @@ -96,7 +95,7 @@ public async Task GetAvailableHoursAsync_WhenOfficeScheduleIsInactive_ShouldRetu
response.Message.Should().Be(expectedMessage);
}

[TestMethod]
[Test]
public async Task GetAvailableHoursAsync_WhenOfficeIsInactive_ShouldReturnsAnErrorMessage()
{
// Arrange
Expand All @@ -114,7 +113,7 @@ public async Task GetAvailableHoursAsync_WhenOfficeIsInactive_ShouldReturnsAnErr
response.Message.Should().Be(expectedMessage);;
}

[TestMethod]
[Test]
public async Task GetAvailableHoursAsync_WhenEmployeeDoesNotHaveMorningOrAfternoonSchedule_ShouldReturnsAnErrorMessage()
{
// Arrange
Expand All @@ -131,7 +130,7 @@ public async Task GetAvailableHoursAsync_WhenEmployeeDoesNotHaveMorningOrAfterno
response.Message.Should().Be(NoMorningOrAfternoonHoursMessage);
}

[TestMethod]
[Test]
public async Task GetAvailableHoursAsync_WhenDentalServiceIdIsInvalid_ShouldReturnsAnErrorMessage()
{
// Arrange
Expand All @@ -154,7 +153,7 @@ public async Task GetAvailableHoursAsync_WhenDentalServiceIdIsInvalid_ShouldRetu
response.Message.Should().Be(DentalServiceNotAvailableMessage);
}

[TestMethod]
[Test]
public async Task GetAvailableHoursAsync_WhenEmployeeHasMorningAndAfternoonSchedule_ShouldReturnsAvailableHours()
{
// Arrange
Expand Down Expand Up @@ -199,7 +198,7 @@ public async Task GetAvailableHoursAsync_WhenEmployeeHasMorningAndAfternoonSched
availableHours.Should().BeEquivalentTo(expectedList);
}

[TestMethod]
[Test]
public async Task GetAvailableHoursAsync_WhenEmployeeHasMorningSchedule_ShouldReturnsAvailableHours()
{
// Arrange
Expand Down Expand Up @@ -237,7 +236,7 @@ public async Task GetAvailableHoursAsync_WhenEmployeeHasMorningSchedule_ShouldRe
availableHours.Should().BeEquivalentTo(expectedList);
}

[TestMethod]
[Test]
public async Task GetAvailableHoursAsync_WhenEmployeeHasAfternoonSchedule_ShouldReturnsAvailableHours()
{
// Arrange
Expand Down Expand Up @@ -273,7 +272,7 @@ public async Task GetAvailableHoursAsync_WhenEmployeeHasAfternoonSchedule_Should
availableHours.Should().BeEquivalentTo(expectedList);
}

[TestMethod]
[Test]
public async Task GetAvailableHoursAsync_WhenSchedulesAreNotAvailable_ShouldReturnsResponseWithoutAvailableHours()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
namespace DentallApp.UnitTests.Features.AvailabilityHours;

[TestClass]
public partial class AvailabilityTests
{
[DataTestMethod]
[DynamicData(nameof(GetData), DynamicDataSourceType.Method)]
[TestCaseSource(typeof(GetAvailableHoursTestCases))]
public void GetAvailableHours_WhenNumberOfUnavailableHoursIsGreaterThanOrEqualToZero_ShouldReturnsAvailableHours(
string testId, AvailabilityOptions options, List<AvailableTimeRangeDto> expectedList)
AvailabilityOptions options,
List<AvailableTimeRangeDto> expectedList)
{
// Act
var availableHours = Availability.GetAvailableHours(options);
Expand All @@ -15,7 +14,7 @@ public void GetAvailableHours_WhenNumberOfUnavailableHoursIsGreaterThanOrEqualTo
availableHours.Should().BeEquivalentTo(expectedList);
}

[TestMethod]
[TestCase]
public void GetAvailableHours_WhenDentistHasSomeTimeoffOrRestTime_ShouldTakeItAsRangeOfUnavailableTime()
{
// Arrange
Expand Down Expand Up @@ -57,7 +56,7 @@ public void GetAvailableHours_WhenDentistHasSomeTimeoffOrRestTime_ShouldTakeItAs
availableHours.Should().BeEquivalentTo(expectedList);
}

[TestMethod]
[TestCase]
public void GetAvailableHours_WhenDurationOfDentalServiceIsEqualToZero_ShouldThrowArgumentException()
{
// Arrange
Expand All @@ -76,7 +75,7 @@ public void GetAvailableHours_WhenDurationOfDentalServiceIsEqualToZero_ShouldThr
act.Should().Throw<InvalidOperationException>();
}

[TestMethod]
[TestCase]
public void GetAvailableHours_WhenNumberOfAvailableHoursIsZero_ShouldReturnsNull()
{
// Arrange
Expand All @@ -102,7 +101,7 @@ public void GetAvailableHours_WhenNumberOfAvailableHoursIsZero_ShouldReturnsNull
availableHours.Should().BeNull();
}

[TestMethod]
[TestCase]
public void GetAvailableHours_WhenAppointmentDateIsEqualToTheCurrentDate_ShouldDiscardAvailableHoursThatAreLessThanTheCurrentTime()
{
// Arrange
Expand Down Expand Up @@ -140,14 +139,13 @@ public void GetAvailableHours_WhenAppointmentDateIsEqualToTheCurrentDate_ShouldD
availableHours.Should().BeEquivalentTo(expectedList);
}

[DataTestMethod]
[DataRow("08:20", "09:00",
[TestCase("08:20", "09:00",
"09:00", "09:30")]
[DataRow("11:40", "12:20",
[TestCase("11:40", "12:20",
"11:00", "11:40")]
[DataRow("10:00", "10:30",
[TestCase("10:00", "10:30",
"10:40", "11:20")]
[DataRow("10:00", "10:30",
[TestCase("10:00", "10:30",
"09:00", "09:40")]
public void IsNotAvailable_WhenNewTimeRangeIsAvailable_ShouldReturnsFalse(
string newStartHour,
Expand All @@ -171,18 +169,17 @@ public void IsNotAvailable_WhenNewTimeRangeIsAvailable_ShouldReturnsFalse(
result.Should().BeFalse();
}

[DataTestMethod]
[DataRow("09:00", "09:30",
[TestCase("09:00", "09:30",
"09:00", "09:30")]
[DataRow("09:00", "09:30",
[TestCase("09:00", "09:30",
"09:20", "09:35")]
[DataRow("10:00", "10:30",
[TestCase("10:00", "10:30",
"10:25", "11:20")]
[DataRow("10:00", "10:30",
[TestCase("10:00", "10:30",
"09:00", "10:10")]
[DataRow("10:00", "10:30",
[TestCase("10:00", "10:30",
"10:29", "12:00")]
[DataRow("12:20", "12:50",
[TestCase("12:20", "12:50",
"12:00", "13:00")]
public void IsNotAvailable_WhenNewTimeRangeIsNotAvailable_ShouldReturnsTrue(
string newStartHour,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace DentallApp.UnitTests.Features.AvailabilityHours;
namespace DentallApp.UnitTests.Features.AvailabilityHours;

public partial class AvailabilityTests
public class GetAvailableHoursTestCases : IEnumerable
{
public static IEnumerable<object[]> GetData()
public IEnumerator GetEnumerator()
{
var dentistStartHour = TimeSpan.Parse("7:00");
var dentistEndHour = TimeSpan.Parse("13:10");
Expand All @@ -16,7 +16,6 @@ public static IEnumerable<object[]> GetData()

yield return new object[]
{
"test1",
new AvailabilityOptions
{
DentistStartHour = dentistStartHour,
Expand All @@ -39,7 +38,6 @@ public static IEnumerable<object[]> GetData()

yield return new object[]
{
"test2",
new AvailabilityOptions
{
DentistStartHour = dentistStartHour,
Expand All @@ -58,7 +56,6 @@ public static IEnumerable<object[]> GetData()

yield return new object[]
{
"test3",
new AvailabilityOptions
{
DentistStartHour = dentistStartHour,
Expand All @@ -76,7 +73,6 @@ public static IEnumerable<object[]> GetData()

yield return new object[]
{
"test4",
new AvailabilityOptions
{
DentistStartHour = dentistStartHour,
Expand All @@ -92,7 +88,6 @@ public static IEnumerable<object[]> GetData()

yield return new object[]
{
"test5",
new AvailabilityOptions
{
DentistStartHour = dentistStartHour,
Expand All @@ -109,7 +104,6 @@ public static IEnumerable<object[]> GetData()

yield return new object[]
{
"test6",
new AvailabilityOptions
{
DentistStartHour = TimeSpan.Parse("9:30"),
Expand All @@ -134,7 +128,6 @@ public static IEnumerable<object[]> GetData()

yield return new object[]
{
"test7",
new AvailabilityOptions
{
DentistStartHour = TimeSpan.Parse("9:30"),
Expand All @@ -161,7 +154,6 @@ public static IEnumerable<object[]> GetData()

yield return new object[]
{
"test8",
new AvailabilityOptions
{
DentistStartHour = dentistStartHour,
Expand All @@ -188,7 +180,6 @@ public static IEnumerable<object[]> GetData()

yield return new object[]
{
"test9",
new AvailabilityOptions
{
DentistStartHour = TimeSpan.Parse("8:00"),
Expand Down
Loading