-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CU-8687yhbz5 adding missing smoke test project.
- Loading branch information
Showing
8 changed files
with
316 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
// } | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters