Skip to content

Commit

Permalink
Added the bot dialog tests to the integration test project (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDave1999 authored Apr 18, 2023
1 parent 57c64d4 commit e819778
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 27 deletions.
8 changes: 7 additions & 1 deletion DentallApp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DentallApp", "src\DentallApp.csproj", "{E354A181-1E6C-4F76-8D99-96E5A6824FC1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DentallApp.Tests", "tests\DentallApp.UnitTests\DentallApp.UnitTests.csproj", "{BE6318A1-900B-4E8E-8AAE-C391F881C844}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DentallApp.UnitTests", "tests\DentallApp.UnitTests\DentallApp.UnitTests.csproj", "{BE6318A1-900B-4E8E-8AAE-C391F881C844}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DentallApp.IntegrationTests", "tests\DentallApp.IntegrationTests\DentallApp.IntegrationTests.csproj", "{3897DDB9-5C4F-4664-94D7-756A5E673951}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -24,5 +26,9 @@ Global
{BE6318A1-900B-4E8E-8AAE-C391F881C844}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE6318A1-900B-4E8E-8AAE-C391F881C844}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE6318A1-900B-4E8E-8AAE-C391F881C844}.Release|Any CPU.Build.0 = Release|Any CPU
{3897DDB9-5C4F-4664-94D7-756A5E673951}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3897DDB9-5C4F-4664-94D7-756A5E673951}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3897DDB9-5C4F-4664-94D7-756A5E673951}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3897DDB9-5C4F-4664-94D7-756A5E673951}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.10.0" />
<PackageReference Include="JustMock" Version="2023.1.117.1" />
<PackageReference Include="Microsoft.Bot.Builder.Testing" Version="4.18.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\DentallApp.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DentallApp.UnitTests.Features.Chatbot.Dialogs;
namespace DentallApp.IntegrationTests.Features.Chatbot.Dialogs;

public static class ActivityFactory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DentallApp.UnitTests.Features.Chatbot.Dialogs;
namespace DentallApp.IntegrationTests.Features.Chatbot.Dialogs;

public static class BotServiceMockFactory
{
Expand All @@ -13,7 +13,7 @@ public static class BotServiceMockFactory
public const int PriceMin = 5;
public const int PriceMax = 10;

public static IAppointmentBotService CreateMock()
public static IAppointmentBotService CreateBotServiceMock()
{
var botService = Mock.Create<IAppointmentBotService>();
Mock.Arrange(() => botService.GetPatientsAsync(Arg.IsAny<UserProfile>()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DentallApp.UnitTests.Features.Chatbot.Dialogs;
namespace DentallApp.IntegrationTests.Features.Chatbot.Dialogs;

public partial class RootDialogTests
{
Expand Down Expand Up @@ -26,7 +26,6 @@ public async Task Bot_WhenIncomingActivityHasValuePropertyWithNull_ShouldSendAnE
reply = await _testClient.SendActivityAsync<IMessageActivity>(incomingActivity);
reply.Text.Should().Be(SelectDentistMessage);

Environment.SetEnvironmentVariable(AppSettings.MaxDaysInCalendar, "60");
await _testClient.SendActivityAsync<IMessageActivity>(CreateActivityWithSelectedDentistId());
_testClient.GetNextReply<IMessageActivity>();
_testClient.GetNextReply<IMessageActivity>();
Expand Down Expand Up @@ -72,7 +71,6 @@ public async Task Bot_WhenIncomingActivityHasValuePropertyWithoutJsonFormat_Shou
reply.Text.Should().Be(SelectDentistMessage);
_testClient.GetNextReply<IMessageActivity>();

Environment.SetEnvironmentVariable(AppSettings.MaxDaysInCalendar, "60");
await _testClient.SendActivityAsync<IMessageActivity>(CreateActivityWithSelectedDentistId());
_testClient.GetNextReply<IMessageActivity>();
_testClient.GetNextReply<IMessageActivity>();
Expand Down Expand Up @@ -112,7 +110,6 @@ public async Task Bot_WhenThereAreNoHoursAvailable_ShouldSendAnErrorMessage()
await _testClient.SendActivityAsync<IMessageActivity>(CreateActivityWithSelectedDentalServiceId());
_testClient.GetNextReply<IMessageActivity>();

Environment.SetEnvironmentVariable(AppSettings.MaxDaysInCalendar, "60");
await _testClient.SendActivityAsync<IMessageActivity>(CreateActivityWithSelectedDentistId());
_testClient.GetNextReply<IMessageActivity>();
_testClient.GetNextReply<IMessageActivity>();
Expand Down Expand Up @@ -148,7 +145,6 @@ public async Task Bot_WhenDateAndTimeAppointmentIsNotAvailable_ShouldSendAnError
await _testClient.SendActivityAsync<IMessageActivity>(CreateActivityWithSelectedDentalServiceId());
_testClient.GetNextReply<IMessageActivity>();

Environment.SetEnvironmentVariable(AppSettings.MaxDaysInCalendar, "60");
await _testClient.SendActivityAsync<IMessageActivity>(CreateActivityWithSelectedDentistId());
_testClient.GetNextReply<IMessageActivity>();
_testClient.GetNextReply<IMessageActivity>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DentallApp.UnitTests.Features.Chatbot.Dialogs;
namespace DentallApp.IntegrationTests.Features.Chatbot.Dialogs;

public partial class RootDialogTests
{
Expand All @@ -9,9 +9,10 @@ public partial class RootDialogTests
[SetUp]
public void TestInitialize()
{
_botService = CreateMock();
_botService = CreateBotServiceMock();
_dateTimeProvider = Mock.Create<IDateTimeProvider>();
_testClient = new(Channels.Webchat, new RootDialog(_botService, _dateTimeProvider));
Environment.SetEnvironmentVariable(AppSettings.MaxDaysInCalendar, "60");
}

[TestCase]
Expand Down Expand Up @@ -49,7 +50,6 @@ private async Task SendReplyWithChoiceSetAsync(string choiceType, Activity incom

private async Task SendReplyWithInputDateAsync(Activity incomingActivity)
{
Environment.SetEnvironmentVariable(AppSettings.MaxDaysInCalendar, "60");
Mock.Arrange(() => _dateTimeProvider.Now).Returns(new DateTime(2023, 01, 01));

var reply = await _testClient.SendActivityAsync<IMessageActivity>(incomingActivity);
Expand Down
23 changes: 23 additions & 0 deletions tests/DentallApp.IntegrationTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
global using NUnit.Framework;
global using FluentAssertions;
global using Telerik.JustMock;
global using AdaptiveCards;
global using Microsoft.Bot.Connector;
global using Microsoft.Bot.Builder.Testing;
global using Microsoft.Bot.Schema;
global using Newtonsoft.Json.Linq;

global using static DentallApp.IntegrationTests.Features.Chatbot.Dialogs.BotServiceMockFactory;
global using static DentallApp.IntegrationTests.Features.Chatbot.Dialogs.ActivityFactory;

global using DentallApp.Features.Chatbot;
global using DentallApp.Features.Chatbot.Models;
global using DentallApp.Features.Chatbot.Dialogs;
global using DentallApp.Features.Appointments.DTOs;
global using DentallApp.Features.SpecificTreatments.DTOs;
global using DentallApp.Features.AvailabilityHours.DTOs;

global using DentallApp.Responses;
global using DentallApp.Configuration;
global using DentallApp.Helpers.DateTimeHelpers;
global using static DentallApp.Constants.ResponseMessages;
3 changes: 1 addition & 2 deletions tests/DentallApp.UnitTests/DentallApp.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.10.0" />
<PackageReference Include="JustMock" Version="2022.3.912.3" />
<PackageReference Include="Microsoft.Bot.Builder.Testing" Version="4.18.1" />
<PackageReference Include="JustMock" Version="2023.1.117.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
Expand Down
13 changes: 0 additions & 13 deletions tests/DentallApp.UnitTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
global using System.Collections;
global using NUnit.Framework;
global using FluentAssertions;
global using AdaptiveCards;
global using Microsoft.Bot.Connector;
global using Microsoft.Bot.Schema;
global using Microsoft.Bot.Builder.Testing;
global using Telerik.JustMock;
global using System.Security.Claims;
global using Newtonsoft.Json.Linq;
global using DotEnv.Core;

global using DentallApp.Features.AvailabilityHours;
Expand All @@ -19,15 +15,11 @@
global using DentallApp.Features.SecurityToken;
global using DentallApp.Features.Roles;
global using DentallApp.Features.Appointments;
global using DentallApp.Features.Appointments.DTOs;
global using DentallApp.Features.EmployeeSchedules;
global using DentallApp.Features.EmployeeSchedules.DTOs;
global using DentallApp.Features.GeneralTreatments;
global using DentallApp.Features.GeneralTreatments.DTOs;
global using DentallApp.Features.SpecificTreatments.DTOs;
global using DentallApp.Features.PublicHolidays.Offices;
global using DentallApp.Features.Chatbot;
global using DentallApp.Features.Chatbot.Dialogs;
global using DentallApp.Features.Chatbot.Models;
global using DentallApp.Features.Chatbot.DirectLine;
global using DentallApp.Features.Chatbot.DirectLine.Services;
Expand All @@ -37,9 +29,4 @@
global using DentallApp.Helpers.DateTimeHelpers;
global using DentallApp.Configuration;
global using DentallApp.DataAccess.Repositories;
global using DentallApp.Responses;
global using static DentallApp.Constants.ResponseMessages;

global using static DentallApp.UnitTests.Features.Chatbot.Dialogs.BotServiceMockFactory;
global using static DentallApp.UnitTests.Features.Chatbot.Dialogs.ActivityFactory;

0 comments on commit e819778

Please sign in to comment.