Skip to content

Commit

Permalink
CU-8687yhbz5 adding missing smoke test project.
Browse files Browse the repository at this point in the history
  • Loading branch information
ucswift committed May 10, 2024
1 parent 4ee57b4 commit 4357cbb
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ Build/*
.idea/*
Tests/Resgrid.TestHarness/*
Tests/Resgrid.TestHarnessCore/*
Tests/Resgrid.SmokeTests/*
Web/Resgrid.WebCore/appsettings.Azure.json
Web/Resgrid.WebCore/appsettings.Development.json
Web/Resgrid.WebCore/appsettings.Production.json
Expand Down
145 changes: 145 additions & 0 deletions Tests/Resgrid.SmokeTests/ApiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
using System;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using NUnit.Framework;
using Resgrid.Model;
using Resgrid.Model.Helpers;
using Resgrid.Model.Services;
using RestSharp;

namespace Resgrid.SmokeTests
{
[TestFixture]
public class ApiTests : SmokeTestBase
{
private const string Token = "RkRSbUUwWjUxajAyNVNuRlhKdGp5c0VpeGFFQ3l3SUZlZEtWaUwvOUxTbz0=";

[Test]
public async Task GetToken()
{
var client = new RestClient("http://resgridapi.local");

var setStatusRequest = new RestRequest("api/v3/Auth/Validate", Method.Post);

setStatusRequest.AddObject(new
{
Usr = "TestUser",
Pass = "Password"
});

var setStatusResponse = await client.ExecuteAsync(setStatusRequest);
setStatusResponse.StatusCode.Should().Be(HttpStatusCode.OK);
setStatusResponse.Content.Should().NotBeNullOrWhiteSpace();
}

[Test]
public async Task TestUserStatusApiCall()
{
var client = new RestClient("http://resgridapi.local");

var setStatusRequest = new RestRequest("api/v3/Status/SetCurrentStatus", Method.Post);
var getStatusRequest = new RestRequest("api/v3/Status/GetCurrentStatus", Method.Get);

setStatusRequest.AddHeader("Authorization", "Basic " + Token);
getStatusRequest.AddHeader("Authorization", "Basic " + Token);

var rnd = new Random();
var type = rnd.Next(0, 3);

var statusInput = new StatusInput();
statusInput.Typ = type;
setStatusRequest.AddObject(statusInput);

var setStatusResponse = await client.ExecuteAsync(setStatusRequest);

Thread.Sleep(250);

var getStatusResponse = await client.ExecuteAsync<StatusResult>(getStatusRequest);

if (setStatusResponse.StatusCode == HttpStatusCode.Created)
{
try
{
var client2 = new RestClient("https://status.resgrid.com");
var setMetricRequest = new RestRequest("api/v1/metrics/1/points", Method.Post);

//client2.Execute(setMetricRequest);
}
catch { }
}

setStatusResponse.StatusCode.Should().Be(HttpStatusCode.Created);
getStatusResponse.Content.Should().NotBeNullOrWhiteSpace();
getStatusResponse.Data.Should().NotBeNull();
getStatusResponse.Data.Act.Should().Be(type);
setStatusResponse.Content.Should().NotContain("Authorization has been denied for this request");
getStatusResponse.Content.Should().NotContain("Authorization has been denied for this request");
}

[Test]
public async Task TestUserStaffingLevelApiCall()
{
var tasks = await Resolve<IScheduledTasksService>().GetScheduledStaffingTasksForUserAsync("50DEC5DB-2612-4D6A-97E3-2F04B7228C85");
var department = await Resolve<IDepartmentsService>().GetDepartmentByIdAsync(971);
//var username = "TestUser";

var client = new RestClient("http://resgridapi.local");
//var stringData = username + "|" + department.DepartmentId + "|" + department.Code;

var request = new RestRequest("api/v3/Staffing/GetCurrentStaffing", Method.Get);

request.AddHeader("Authorization", "Basic " + Token);
var response = await client.ExecuteAsync<StaffingResult>(request);

response.Content.Should().NotBeNullOrWhiteSpace();
response.Data.Should().NotBeNull();
response.Content.Should().NotContain("Authorization has been denied for this request");

if (tasks != null && tasks.Count > 0)
{
var currentTime = DateTime.UtcNow.TimeConverter(department);
var currentStaffing = (from task in tasks
let whenShouldJobRun = task.WhenShouldJobBeRun(currentTime)
where whenShouldJobRun < currentTime
orderby whenShouldJobRun descending
select task).FirstOrDefault();
var currentStaffingLevel = int.Parse(currentStaffing.Data);

if (currentTime.Minute <= 53)
response.Data.Typ.Should().Be(currentStaffingLevel);
}
}
}

public class StatusInput
{
public string Uid { get; set; }
public int Typ { get; set; }
public int Rto { get; set; }
public string Geo { get; set; }
public int Dtp { get; set; }
public string Not { get; set; }
}

public class StaffingResult
{
public string Uid { get; set; }
public string Nme { get; set; }
public int Typ { get; set; }
public DateTime Tms { get; set; }
public string Not { get; set; }
}

public class StatusResult
{
public string Uid { get; set; }
public int Act { get; set; }
public DateTime Ats { get; set; }
public int Ste { get; set; }
public DateTime Sts { get; set; }
public int Did { get; set; }
}
}
22 changes: 22 additions & 0 deletions Tests/Resgrid.SmokeTests/Resgrid.SmokeTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Configurations>Debug;Release;Docker</Configurations>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Resgrid.Tests\Bootstrapper.cs" Link="Bootstrapper.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="SimpleBrowser" Version="0.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\Resgrid.Config\Resgrid.Config.csproj" />
<ProjectReference Include="..\..\Core\Resgrid.Framework\Resgrid.Framework.csproj" />
<ProjectReference Include="..\..\Core\Resgrid.Model\Resgrid.Model.csproj" />
<ProjectReference Include="..\..\Core\Resgrid.Services\Resgrid.Services.csproj" />
<ProjectReference Include="..\..\Repositories\Resgrid.Repositories.DataRepository\Resgrid.Repositories.DataRepository.csproj" />
<ProjectReference Include="..\..\Workers\Resgrid.Workers.Framework\Resgrid.Workers.Framework.csproj" />
</ItemGroup>
</Project>
46 changes: 46 additions & 0 deletions Tests/Resgrid.SmokeTests/ResponderWebTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//using FluentAssertions;
//using NUnit.Framework;
//using SimpleBrowser;

//namespace Resgrid.SmokeTests
//{
// [TestFixture]
// public class ResponderWebTests : SmokeTestBase
// {
// [Test]
// public void TestResponderWebEdition()
// {
// var browser = new Browser();
// // log the browser request/response data to files so we can interrogate them in case of an issue with our scraping
// //browser.RequestLogged += OnBrowserRequestLogged;
// //browser.MessageLogged += new Action<Browser, string>(OnBrowserMessageLogged);
// browser.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10";

// browser.Navigate("https://responder.resgrid.com");
// LastRequestFailed(browser).Should().Be(false);
// }

// [Test]
// public void TestUnitWebEdition()
// {
// var browser = new Browser();
// // log the browser request/response data to files so we can interrogate them in case of an issue with our scraping
// //browser.RequestLogged += OnBrowserRequestLogged;
// //browser.MessageLogged += new Action<Browser, string>(OnBrowserMessageLogged);
// browser.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10";

// browser.Navigate("https://unit.resgrid.com");
// LastRequestFailed(browser).Should().Be(false);
// }

// static bool LastRequestFailed(Browser browser)
// {
// if (browser.LastWebException != null)
// {
// browser.Log("There was an error loading the page: " + browser.LastWebException.Message);
// return true;
// }
// return false;
// }
// }
//}
39 changes: 39 additions & 0 deletions Tests/Resgrid.SmokeTests/SmokeTestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Autofac;
using NUnit.Framework;
using Resgrid.Tests;

namespace Resgrid.SmokeTests
{
public class SmokeTestBase
{
static SmokeTestBase()
{
Bootstrapper.Initialize();
}

protected T Resolve<T>()
{
return Bootstrapper.GetKernel().Resolve<T>();
}

[SetUp]
public void SetupContext_ALL()
{
Before_all_tests();
}

[TearDown]
public void TearDownContext_ALL()
{
After_all_tests();
}

protected virtual void Before_all_tests()
{
}

protected virtual void After_all_tests()
{
}
}
}
61 changes: 61 additions & 0 deletions Tests/Resgrid.SmokeTests/WebsiteTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using FluentAssertions;
using NUnit.Framework;
using RestSharp;
using SimpleBrowser;

namespace Resgrid.SmokeTests
{
[TestFixture]
public class WebsiteTests : SmokeTestBase
{
[Test]
public void TestWebsiteLogin()
{
var browser = new Browser();
// log the browser request/response data to files so we can interrogate them in case of an issue with our scraping
//browser.RequestLogged += OnBrowserRequestLogged;
//browser.MessageLogged += new Action<Browser, string>(OnBrowserMessageLogged);
browser.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10";

browser.Navigate("https://resgrid.com/Account/LogOn");
LastRequestFailed(browser).Should().Be(false);

var userNameField = browser.Find("Username");
if (userNameField.Exists)
userNameField.Value = "TestUser";

var passwordField = browser.Find("Password");
if (passwordField.Exists)
passwordField.Value = "Password";

var loginButton = browser.Find(ElementType.Button, "type", "submit");//.Click();
if (loginButton.Exists)
loginButton.Click();

if (LastRequestFailed(browser) == false && browser.ContainsText("Test Department"))
{
try
{
var client2 = new RestClient("https://status.resgrid.com");
var setMetricRequest = new RestRequest("api/v1/metrics/2/points", Method.Post);

//client2.Execute(setMetricRequest);
}
catch { }
}

LastRequestFailed(browser).Should().Be(false);
browser.ContainsText("Test Department").Should().Be(true);
}

static bool LastRequestFailed(Browser browser)
{
if (browser.LastWebException != null)
{
browser.Log("There was an error loading the page: " + browser.LastWebException.Message);
return true;
}
return false;
}
}
}
3 changes: 1 addition & 2 deletions Web/Resgrid.Web.ServicesCore/Resgrid.Web.ServicesCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.7.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.7.1" />
<PackageReference Include="protobuf-net" Version="3.2.30" />
<PackageReference Include="Sentry" Version="4.2.1" />
<PackageReference Include="Sentry.AspNetCore" Version="4.2.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.5.0" />
Expand Down
4 changes: 2 additions & 2 deletions Web/Resgrid.WebCore/Resgrid.WebCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
<PackageReference Include="BundlerMinifier.Core" Version="3.2.449" />
<PackageReference Include="NUglify" Version="1.21.4" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.7.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageReference Include="protobuf-net" Version="3.2.30" />
<PackageReference Include="Sentry" Version="4.2.1" />
<PackageReference Include="Sentry.AspNetCore" Version="4.2.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.5.0" />
Expand Down

0 comments on commit 4357cbb

Please sign in to comment.