Skip to content

Commit a79ef2d

Browse files
authored
Merge pull request #598 from bcgov/ricander
Ricander
2 parents 6274fdc + 5f5e0f9 commit a79ef2d

9 files changed

+122
-141
lines changed

Test/UITest/DataBase/UnitOfWork/UnitOfWork.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
using Microsoft.EntityFrameworkCore;
22
using DataBase.Repositories;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
83
using DataBase.Entities;
94

105
namespace DataBase.UnitOfWork
@@ -112,14 +107,16 @@ public GenericRepository<DssRentalListing> DssRentalListingRepository
112107
get => _DssRentalListingRepository ?? new GenericRepository<DssRentalListing>(_context);
113108
}
114109

115-
110+
116111

117112
public UnitOfWork(DbContext context)
118113
{
119114
if (context != null)
120115
{
121116
_context = context;
122117
}
118+
else
119+
throw new ArgumentNullException(nameof(context));
123120
}
124121

125122
public void ResetDB()
@@ -132,7 +129,15 @@ public void ResetDB()
132129

133130
public void Save()
134131
{
135-
_context.SaveChanges();
132+
try
133+
{
134+
_context.SaveChanges();
135+
}
136+
catch (DbUpdateException ex)
137+
{
138+
Console.WriteLine("Unable to save changes to database");
139+
throw ex;
140+
}
136141
}
137142

138143
protected virtual void Dispose(bool disposing)
Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Configuration;
2+
using OpenQA.Selenium;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -20,7 +21,6 @@ public class AuthHelper
2021
private string _TestUserName;
2122
private string _TestPassword;
2223
private AppSettings _AppSettings;
23-
private LogonTypeEnum? _LogonType;
2424
private BCIDPage _BCIDPage;
2525

2626
public AuthHelper(IDriver Driver)
@@ -31,67 +31,99 @@ public AuthHelper(IDriver Driver)
3131
_BCIDPage = new BCIDPage(_Driver);
3232
_AppSettings = new AppSettings();
3333
}
34-
public LogonTypeEnum SetLogonType(UserTypeEnum UserType)
34+
private LogonTypeEnum? SetLogonType(UserTypeEnum UserType)
3535
{
36-
LogonTypeEnum _LogonType;
36+
LogonTypeEnum? logonType;
3737
switch (UserType)
3838
{
3939
case UserTypeEnum.BCGOVERNMENTSTAFF:
4040
case UserTypeEnum.CEUSTAFF:
4141
case UserTypeEnum.CEUADMIN:
4242
{
43-
_LogonType = SFEnums.LogonTypeEnum.IDIR;
43+
logonType = SFEnums.LogonTypeEnum.IDIR;
4444
break;
4545
}
4646
case UserTypeEnum.LOCALGOVERNMENT:
4747
case UserTypeEnum.SHORTTERMRENTALPLATFORM:
4848
{
49-
_LogonType = SFEnums.LogonTypeEnum.BCID;
49+
logonType = SFEnums.LogonTypeEnum.BCID;
5050
break;
5151
}
5252
default:
5353
throw new ArgumentException("Unknown User Type (" + UserType + ")");
5454
}
55-
return (_LogonType);
55+
if (null == logonType)
56+
{
57+
}
58+
return (logonType);
5659
}
5760

5861
public LogonTypeEnum? Authenticate(string UserName, string Password, UserTypeEnum UserType)
5962
{
63+
LogonTypeEnum? logonType;
6064
_TestUserName = UserName;
6165
_TestPassword = Password;
62-
_LogonType = SetLogonType(UserType);
66+
logonType = SetLogonType(UserType);
6367

6468
_Driver.Url = _AppSettings.GetServer("default");
6569
_Driver.Navigate();
6670

67-
switch (_LogonType)
68-
{
69-
case LogonTypeEnum.IDIR:
70-
{
71-
_PathFinderPage.IDRButton.Click();
72-
_IDRLoginPage.UserNameTextBox.WaitFor(5);
73-
_IDRLoginPage.UserNameTextBox.EnterText(_TestUserName);
74-
_IDRLoginPage.PasswordTextBox.EnterText(_TestPassword);
75-
_IDRLoginPage.ContinueButton.Click();
76-
break;
77-
}
78-
case LogonTypeEnum.BCID:
79-
{
80-
_PathFinderPage.BCIDButton.Click();
81-
_BCIDPage.UserNameTextBox.WaitFor(5);
82-
_BCIDPage.UserNameTextBox.EnterText(_TestUserName);
83-
_BCIDPage.PasswordTextBox.EnterText(_TestPassword);
84-
_BCIDPage.ContinueButton.Click();
85-
break;
86-
}
87-
}
71+
bool result = false;
72+
int i = 0;
8873

89-
if (_Driver.Url.ToLower().Contains("logon.cgi"))
74+
//Sleep for 5 seconds and try twice in case text boxes are rendered, but not yet ready. Selenium WaitFor would be a better option than
75+
// Sleep, but it is not reliable for authentication
76+
while ((result == false) && (i++ < 2))
9077
{
91-
_LogonType = null;
78+
switch (logonType)
79+
{
80+
case LogonTypeEnum.IDIR:
81+
{
82+
try
83+
{
84+
_PathFinderPage.IDRButton.Click();
85+
Thread.Sleep(5000);
86+
//_IDRLoginPage.UserNameTextBox.WaitFor(30);
87+
_IDRLoginPage.UserNameTextBox.EnterText(_TestUserName);
88+
_IDRLoginPage.PasswordTextBox.EnterText(_TestPassword);
89+
_IDRLoginPage.ContinueButton.Click();
90+
result = true;
91+
}
92+
catch (Exception ex) when (ex is NoSuchElementException || ex is WebDriverTimeoutException)
93+
{
94+
if (_Driver.GetCurrentURL().Contains(@"openid-connect/auth"))
95+
continue;
96+
}
97+
98+
break;
99+
}
100+
case LogonTypeEnum.BCID:
101+
{
102+
try
103+
{
104+
_PathFinderPage.BCIDButton.Click();
105+
Thread.Sleep(5000);
106+
_BCIDPage.UserNameTextBox.WaitFor(5);
107+
_BCIDPage.UserNameTextBox.EnterText(_TestUserName);
108+
_BCIDPage.PasswordTextBox.EnterText(_TestPassword);
109+
_BCIDPage.ContinueButton.Click();
110+
result = true;
111+
}
112+
catch (Exception ex) when (ex is NoSuchElementException || ex is WebDriverTimeoutException)
113+
{
114+
if (_Driver.GetCurrentURL().Contains(@"openid-connect/auth"))
115+
continue;
116+
}
117+
118+
break;
119+
}
120+
}
92121
}
93122

94-
return (_LogonType);
123+
if (result == false)
124+
logonType = null;
125+
126+
return (logonType);
95127
}
96128
}
97129
}

Test/UITest/SpecFlowProjectBDD/Helpers/DataBaseHelper.cs

Lines changed: 0 additions & 60 deletions
This file was deleted.

Test/UITest/SpecFlowProjectBDD/StepDefinitions/DenyAccessToSystem.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public sealed class DenyAccessToSystem
1616
{
1717
private IDriver _Driver;
1818
private LayoutPage _LayoutPage;
19-
private DelistingWarningPage _DelistingWarningPage;
2019
private PathFinderPage _PathFinderPage;
2120
private IDirLoginPage _IDirPage;
2221
private NoticeOfTakeDownPage _NoticeOfTakeDownPage;
@@ -31,6 +30,7 @@ public sealed class DenyAccessToSystem
3130
AppSettings _AppSettings;
3231
private IUnitOfWork _UnitOfWork;
3332
private SFEnums.Environment _Environment = SFEnums.Environment.LOCAL;
33+
private SFEnums.LogonTypeEnum? _LogonType;
3434

3535

3636
public DenyAccessToSystem(SeleniumDriver Driver)
@@ -93,15 +93,16 @@ public void IAttemptToAccessTheDataSharingSystem(string UserName, string Email,
9393

9494
_UnitOfWork.Save();
9595
/////////////////////////////////////////////////////////////
96-
96+
9797
UserHelper userHelper = new UserHelper();
9898

9999
_UserType = userHelper.SetUserType(RoleName);
100100

101101
AuthHelper authHelper = new AuthHelper(_Driver);
102102

103103
//Authenticate user using IDir or BCID depending on the user
104-
authHelper.Authenticate(_TestUserName, _TestPassword, _UserType);
104+
_LogonType = authHelper.Authenticate(_TestUserName, _TestPassword, _UserType);
105+
ClassicAssert.IsNotNull(_LogonType, "Logon FAILED");
105106

106107
}
107108

@@ -115,6 +116,15 @@ public void IDontHaveTheRequiredAccessPermissions()
115116
public void IShouldSeeASpecificMessageIndicatingThatAccessIsRestricted()
116117
{
117118
System.Threading.Thread.Sleep(1000);
119+
try
120+
{
121+
ClassicAssert.IsTrue(_Driver.Url.Contains("/401"));
122+
}
123+
catch
124+
{
125+
Thread.Sleep(2000);
126+
}
127+
118128
ClassicAssert.IsTrue(_LayoutPage.Driver.PageSource.Contains("401 Access Denied"));
119129
}
120130

Test/UITest/SpecFlowProjectBDD/StepDefinitions/ManagingAccess.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public sealed class ManagingAccess
3737
private DssDbContext _DssDBContext;
3838
private IUnitOfWork _UnitOfWork;
3939
private SFEnums.Environment _Environment = SFEnums.Environment.LOCAL;
40+
private SFEnums.LogonTypeEnum? _LogonType;
4041

4142
public ManagingAccess(SeleniumDriver Driver)
4243
{
@@ -91,7 +92,8 @@ public void GivenIAmAauthenticatedGovernmentUser(string UserName, string Expecte
9192
AuthHelper authHelper = new AuthHelper(_Driver);
9293

9394
//Authenticate user using IDir or BCID depending on the user
94-
authHelper.Authenticate(_TestUserName, _TestPassword, UserTypeEnum.BCGOVERNMENTSTAFF);
95+
_LogonType = authHelper.Authenticate(_TestUserName, _TestPassword, UserTypeEnum.BCGOVERNMENTSTAFF);
96+
ClassicAssert.IsNotNull(_LogonType, "Logon FAILED");
9597

9698

9799
IWebElement TOC = null;

Test/UITest/SpecFlowProjectBDD/StepDefinitions/SendNoticeOfTakedownWithoutADSSlisting.cs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public sealed class SendNoticeOfTakedownWithoutADSSlisting
2525
private string _TestPassword;
2626
private bool _ExpectedResult = false;
2727
private AppSettings _AppSettings;
28+
private SFEnums.LogonTypeEnum? _LogonType;
2829

2930
public SendNoticeOfTakedownWithoutADSSlisting(SeleniumDriver Driver)
3031
{
@@ -52,7 +53,9 @@ public void GivenIAmAauthenticatedLGStaffMemberUser(string UserName, string Expe
5253
AuthHelper authHelper = new AuthHelper(_Driver);
5354

5455
//Authenticate user using IDir or BCID depending on the user
55-
authHelper.Authenticate(_TestUserName, _TestPassword, UserTypeEnum.LOCALGOVERNMENT);
56+
_LogonType = authHelper.Authenticate(_TestUserName, _TestPassword, UserTypeEnum.LOCALGOVERNMENT);
57+
//Authenticate user using IDir or BCID depending on the user
58+
ClassicAssert.IsNotNull(_LogonType, "Logon FAILED");
5659

5760
IWebElement TOC = null;
5861

@@ -94,13 +97,6 @@ public void IShouldBePresentedWithAFieldToSelectWhichPlatformToSendTheWarningTo(
9497
_DelistingWarningPage.PlatformReceipientDropdown.Click();
9598
}
9699

97-
//[Then("I should be presented with a dropdown menu to select reason for delisting")]
98-
//public void IShouldBePresentedWithADropdownMenuToSelectReasonForDelisting()
99-
//{
100-
// _DelistingWarningPage.ReasonDropdown.Click();
101-
// _DelistingWarningPage.ReasonDropdown.Click();
102-
//}
103-
104100
[Then(@"I should see an optional field for Listing ID ""(.*)""")]
105101
public void IShouldSeeAnOptionalFieldForListingID(string ListingID)
106102
{
@@ -153,20 +149,6 @@ public void ThenTheSystemShouldValidateTheEmailFormat()
153149
{
154150
}
155151

156-
////ReasonForDelisting
157-
//[When("I select a reason for delisting")]
158-
//public void WhenISelectAReasonForDelisting()
159-
//{
160-
// _DelistingWarningPage.ReasonDropdown.Click();
161-
// _DelistingWarningPage.ReasonDropdown.ExecuteJavaScript(@"document.querySelector(""#reasonId_0"").click()");
162-
//}
163-
164-
//[Then("the system should present a list of reasons for requesting delisting: No business licence provided, invalid business licence number, expired business licence, or suspended business license")]
165-
//public void ThenTheSystemShouldPresentAListOfReasonsForRequestingDelisting()
166-
//{
167-
168-
//}
169-
170152
// CC and Send Copy Options:
171153
[When("submitting a notice")]
172154
public void WhenSubmittingANotice()

Test/UITest/SpecFlowProjectBDD/StepDefinitions/SendTakeDownRequestWithoutADSSListing.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public sealed class SendTakeDownRequestWithoutADSSListing
2626
private bool _ExpectedResult = false;
2727
private IDriver _Driver;
2828
private AppSettings _AppSettings;
29+
private SFEnums.LogonTypeEnum? _LogonType;
2930

3031
public SendTakeDownRequestWithoutADSSListing(SeleniumDriver Driver)
3132
{
@@ -53,7 +54,8 @@ public void GivenIAmAauthenticatedLGStaffMemberUser(string UserName, string Expe
5354
AuthHelper authHelper = new AuthHelper(_Driver);
5455

5556
//Authenticate user using IDir or BCID depending on the user
56-
authHelper.Authenticate(_TestUserName, _TestPassword, UserTypeEnum.LOCALGOVERNMENT);
57+
_LogonType = authHelper.Authenticate(_TestUserName, _TestPassword, UserTypeEnum.LOCALGOVERNMENT);
58+
ClassicAssert.IsNotNull(_LogonType, "Logon FAILED");
5759

5860
IWebElement TOC = null;
5961

@@ -121,7 +123,6 @@ public void TheSystemShouldValidateTheIDFormat()
121123
}
122124

123125
//ListingURLField
124-
//[When(@"Entering the listing URL")]
125126
[When(@"Entering the listing URL ""(.*)""")]
126127
public void WhenEnteringTheListingURL(string URL)
127128
{

0 commit comments

Comments
 (0)