EnVisageOnline/Main-RMO/Source/IntegrationTests/Scenarios/ScenarioTests.cs

101 lines
6.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using EnVisage.Code;
using IntegrationTests.Helpers;
using IntegrationTests.Helpers.Pages;
using IntegrationTests.Models;
using IntegrationTests.Properties;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
namespace IntegrationTests.Scenarios
{
[TestFixture]
public class ScenarioTests : BaseIntegrationTest
{
public IEnumerable<TestCaseData> CreateScenarioTestCases
{
get
{
yield return new TestCaseData("New Web - Basic Template with default period Scenario", "dc3535", Constants.TestData.TemplateIdNewWeb, ScenarioType.Portfolio, DateTime.Today, DateTime.Today.AddDays(12 * 7), DateTime.Today, 5, 500000M, 35M, 0.48M, 325000M, 100000M, 260000.0001M, 52000.0000M, 3.330489M).SetName("New Web - Basic Scenario with default values");
//yield return new TestCaseData("Half Year Scenario", "dc3535", Constants.TestData.TemplateIdLargeFsaCr, ScenarioType.Portfolio, "10/30/2014", "4/30/2015", "10/30/2014", 5, 500000.0M, 35.0M, 0.48M, 325000.0M, 100000.0M, 260000.0015M, 52000.0003M).SetName("Half Year");
//yield return new TestCaseData("2 Years Scenario", "dc3535", Constants.TestData.TemplateIdLargeFsaCr, ScenarioType.Portfolio, "10/30/2014", "10/30/2016", "10/30/2014", 5, 500000.0M, 35.0M, 0.48M, 325000.0M, 100000.0M, 260000.0145M, 52000.0029M).SetName("2 Years");
//yield return new TestCaseData("1 Year starting from the next year Scenario", "dc3535", Constants.TestData.TemplateIdLargeFsaCr, ScenarioType.Portfolio, "1/1/2015", "1/1/2016", "1/1/2015", 5, 500000.0M, 35.0M, 0.48M, 325000.0M, 100000.0M, 259999.9993M, 51999.9999M).SetName("1 Year starting from the next year");
}
}
[Test]
[TestCaseSource("CreateScenarioTestCases")]
public void CreateScenario(string name, string color, Guid templateId, ScenarioType type, DateTime startDate, DateTime endDate, DateTime mileDate,
int milestones, decimal revenue, decimal grossMargin, decimal calcGrossMargin, decimal tdDirectCosts, decimal tdRevenuePerMilestone,
decimal buDirectCosts, decimal buCostsPerMilestone, decimal webDeveloperThirdWeekQuantity)
{
Browser.WaitForAjax(WebDriver);
BLL.CreateProject(WebDriver);
Project project = null;
using (var db = new EnvisageTestContext())
{
project = db.Projects.FirstOrDefault();
}
if (project == null)
Assert.Fail("Cannot find created project");
var page = DriverContext.CreatePage<CreateScenarioPage>(Settings.Default.WebSiteUrl + "Scenarios/Edit?parentId=" + project.Id);
page.EnterScenarioInfo(WebDriver, name, color, templateId, type, startDate.ToShortDateString(), endDate.ToShortDateString(), mileDate.ToShortDateString(), milestones, revenue, grossMargin);
page.Save(WebDriver);
Console.WriteLine("start assert");
Assert.AreEqual(Settings.Default.WebSiteUrl + "Project", WebDriver.Url);
using (var db = new EnvisageTestContext())
{
var scenario = db.Scenarios.FirstOrDefault(t => t.ParentId == project.Id);
#region validate inputs
Assert.IsNotNull(scenario, "The scenario was not created");
Assert.AreEqual(project.Id, scenario.ParentId, "The scenario parentId has been set incorrectly");
Assert.AreEqual(name, scenario.Name, "The scenario name has been set incorrectly");
Assert.AreEqual(color, scenario.Color, "The scenario color has been set incorrectly");
Assert.AreEqual(startDate, scenario.StartDate.Value, "The scenario start date has been set incorrectly");
Assert.AreEqual(endDate, scenario.EndDate.Value, "The scenario start date has been set incorrectly");
Assert.AreEqual(mileDate, scenario.ShotStartDate.Value, "The scenario start date has been set incorrectly");
Assert.AreEqual(templateId, scenario.TemplateId.Value, "The scenario template has been set incorrectly");
Assert.AreEqual((int)type, scenario.Type, "The scenario type has been set incorrectly");
Assert.AreEqual(milestones, scenario.Shots.Value, "The scenario total milestones has been set incorrectly");
Assert.AreEqual(revenue, scenario.ProjectedRevenue.Value, "The scenario projected revenue has been set incorrectly");
Assert.AreEqual(grossMargin / 100.0M, scenario.ExpectedGrossMargin.Value, "The scenario expected gross margin has been set incorrectly");
#endregion
#region validate calculations
Assert.AreEqual(calcGrossMargin, scenario.CalculatedGrossMargin.Value, "The scenario calculated gross margin (forecast) has been set incorrectly");
Assert.AreEqual(tdDirectCosts, scenario.TDDirectCosts.Value, "The scenario top-down direct costs margin has been set incorrectly");
Assert.AreEqual(tdRevenuePerMilestone, scenario.ProjectedRevenue.Value, "The scenario top-down revenue per milestone (forecast) has been set incorrectly");
Assert.AreEqual(buDirectCosts, scenario.BUDirectCosts.Value, "The scenario bottom-up direct costs (forecast) has been set incorrectly");
Assert.AreEqual(buCostsPerMilestone, scenario.BURevenueShot.Value, "The scenario bottom-up costs per milestone (forecast) has been set incorrectly");
var scenarioDetail = db.ScenarioDetails.FirstOrDefault(
t => t.ExpenditureCategoryId == Constants.TestData.TemplateIdNewWeb && t.WeekOrdinal == 3);
Assert.IsNotNull(scenarioDetail, "Cannot find a third scenario detail record for '{0}' expenditure category.", Constants.TestData.TemplateIdNewWeb);
Assert.AreEqual(templateId, scenarioDetail.Quantity, "Third scenario detail record's quantity has been set incorrectly.");
#endregion
}
Console.WriteLine("end assert");
}
//[Test]
//public void test()
//{
// Browser.WaitForAjax(WebDriver);
// var page = DriverContext.CreatePage<CreateScenarioPage>(Settings.Default.WebSiteUrl + "Scenarios/Edit?parentId=bae78141-0ac4-4dbc-bb81-f90b73f6b10a");
// page.StartDateTextBox.Clear();
// page.StartDateTextBox.SendKeys("123456");
// page.EndDateTextBox.Clear();
// page.EndDateTextBox.SendKeys("987654");
// var wait = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(30));
// var tr = wait.Until(driver => driver.FindElement(By.CssSelector("#prjcts tbody tr")));
//}
}
}