217 lines
7.9 KiB
C#
217 lines
7.9 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Microsoft.Win32;
|
|
using Net.Mail;
|
|
using System;
|
|
using System.Threading;
|
|
|
|
namespace Prevu
|
|
{
|
|
public class BaseTest
|
|
{
|
|
|
|
#region Fields
|
|
|
|
const string regKey = "HKEY_CURRENT_USER\\Software\\TestSystem\\MailMessages";
|
|
|
|
static Browser browser = Browser.Firefox;
|
|
static string domain = "http://qa.prevuplan.com/";
|
|
|
|
private static TestRegistrator testRegistrator;
|
|
public const int testTimeout = 600000;
|
|
public static WebDriver driver;
|
|
public static LoginPage loginPage;
|
|
public static UsersPage usersPage;
|
|
public static ForgotPasswordPage forgotPasswordPage;
|
|
public static ActivateUserAccountPage activateUserAccountPage;
|
|
public static GLAccountsPage glAccountsPage;
|
|
public static ClientsPage clientsPage;
|
|
public static ExpenditureCategoriesPage expenditureCategoriesPage;
|
|
public static CompaniesPage companiesPage;
|
|
public static TeamBoardPage teamBoardPage;
|
|
public static PeopleResourcePage peopleResourcePage;
|
|
public static WorkWeeksPage workWeeksPage;
|
|
public static CapacityManagementPage capacityManagementPage;
|
|
public static ProjectScenariosPage projectScenariosPage;
|
|
public static string tempId;
|
|
|
|
#endregion Fields
|
|
|
|
#region Properties
|
|
|
|
private TestContext testContextInstance;
|
|
public TestContext TestContext
|
|
{
|
|
get { return testContextInstance; }
|
|
set { testContextInstance = value; }
|
|
}
|
|
|
|
#endregion Properties
|
|
|
|
#region Initialization & CleanUp
|
|
|
|
[ClassInitialize()]
|
|
public static void ClassInitialize(TestContext TestContext)
|
|
{
|
|
testRegistrator = new TestRegistrator(domain);
|
|
driver = new WebDriver(browser, domain);
|
|
loginPage = new LoginPage(driver);
|
|
forgotPasswordPage = new ForgotPasswordPage(driver);
|
|
usersPage = new UsersPage(driver);
|
|
activateUserAccountPage = new ActivateUserAccountPage(driver);
|
|
glAccountsPage = new GLAccountsPage(driver);
|
|
clientsPage = new ClientsPage(driver);
|
|
expenditureCategoriesPage = new ExpenditureCategoriesPage(driver);
|
|
companiesPage = new CompaniesPage(driver);
|
|
teamBoardPage = new TeamBoardPage(driver);
|
|
peopleResourcePage = new PeopleResourcePage(driver);
|
|
workWeeksPage = new WorkWeeksPage(driver);
|
|
capacityManagementPage = new CapacityManagementPage(driver);
|
|
projectScenariosPage = new ProjectScenariosPage(driver);
|
|
tempId = GetTempID();
|
|
}
|
|
|
|
[ClassCleanup]
|
|
public static void ClassCleanup()
|
|
{
|
|
driver.Close();
|
|
}
|
|
|
|
[TestInitialize()]
|
|
public void TestInitialize()
|
|
{
|
|
testRegistrator.RegisterStart(TestContext, driver);
|
|
}
|
|
|
|
[TestCleanup()]
|
|
public void TestCleanup()
|
|
{
|
|
testRegistrator.RegisterFinish(TestContext, driver);
|
|
}
|
|
|
|
#endregion Initialization & CleanUp
|
|
|
|
public static string GetTempID()
|
|
{
|
|
return new Random().Next(1000000, 9999999).ToString();
|
|
}
|
|
|
|
public void IgnoreExistingEmailMessages(string userName, string password)
|
|
{
|
|
try
|
|
{
|
|
Pop3Client GmailClient = new Pop3Client("pop.gmail.com", 995, true, userName, password);
|
|
GmailClient.Authenticate();
|
|
foreach (Pop3ListItem item in GmailClient.List())
|
|
{
|
|
if (item != null)
|
|
{
|
|
MailMessageEx mail = GmailClient.RetrMailMessageEx(item);
|
|
if (mail != null)
|
|
{
|
|
string regValue = (string)Registry.GetValue(regKey, mail.MessageId, "");
|
|
if (string.IsNullOrEmpty(regValue))
|
|
{
|
|
Registry.SetValue(regKey, mail.MessageId, mail.Subject);
|
|
}
|
|
}
|
|
GmailClient.Dele(item);
|
|
}
|
|
}
|
|
GmailClient.Quit();
|
|
GmailClient.ClearMailBox();
|
|
GmailClient.Dispose();
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
public bool CheckEmailMessage(string userName, string password,
|
|
string emailFrom, string emailTo, string subject, string[] bodyTags,
|
|
out string outBody)
|
|
{
|
|
bool result = false;
|
|
outBody = null;
|
|
Pop3Client GmailClient = new Pop3Client("pop.gmail.com", 995, true, userName, password);
|
|
GmailClient.Authenticate();
|
|
bool waitLetter = true;
|
|
while (waitLetter)
|
|
{
|
|
foreach (Pop3ListItem item in GmailClient.List())
|
|
{
|
|
if (item != null)
|
|
{
|
|
MailMessageEx mail = GmailClient.RetrMailMessageEx(item);
|
|
if (mail != null)
|
|
{
|
|
string regValue = (string)Registry.GetValue(regKey, mail.MessageId, "");
|
|
if (string.IsNullOrEmpty(regValue))
|
|
{
|
|
waitLetter = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (waitLetter)
|
|
{
|
|
Thread.Sleep(1000 * 5);
|
|
GmailClient.Quit();
|
|
GmailClient = new Pop3Client("pop.gmail.com", 995, true, userName, password);
|
|
GmailClient.Authenticate();
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
foreach (Pop3ListItem item in GmailClient.List())
|
|
{
|
|
if (item != null)
|
|
{
|
|
MailMessageEx mail = GmailClient.RetrMailMessageEx(item);
|
|
if (mail != null)
|
|
{
|
|
string regValue = (string)Registry.GetValue(regKey, mail.MessageId, "");
|
|
if (string.IsNullOrEmpty(regValue))
|
|
{
|
|
if ((mail.From.Address == emailFrom) && (mail.To[0].Address == emailTo) &&
|
|
(mail.Subject == subject))
|
|
{
|
|
Registry.SetValue(regKey, mail.MessageId, mail.Subject);
|
|
int passedCount = 0;
|
|
outBody = mail.Body.Replace("=", "");
|
|
for (var i = 0; i < bodyTags.Length; i++)
|
|
{
|
|
if (outBody.IndexOf(bodyTags[i]) < 0)
|
|
{
|
|
result = false;
|
|
break;
|
|
}
|
|
else {
|
|
passedCount++;
|
|
}
|
|
}
|
|
result = passedCount == bodyTags.Length;
|
|
}
|
|
}
|
|
}
|
|
GmailClient.Dele(item);
|
|
}
|
|
}
|
|
GmailClient.Quit();
|
|
GmailClient.ClearMailBox();
|
|
GmailClient.Dispose();
|
|
}
|
|
catch { }
|
|
return result;
|
|
}
|
|
|
|
public static int GetIntNegative()
|
|
{
|
|
return new Random().Next(10, 99) * -1;
|
|
}
|
|
public static int GetIntPositive()
|
|
{
|
|
return new Random().Next(10, 99);
|
|
}
|
|
}
|
|
}
|