Skip to content

Commit a657de4

Browse files
committed
Integration test for OnDataProcessed event added
1 parent 3010add commit a657de4

File tree

8 files changed

+154
-0
lines changed

8 files changed

+154
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace Tests.Integration.Mvc.Controllers
2+
{
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Web.Mvc;
6+
using JQDT.Models;
7+
8+
public class TestOnActionExecutedController : Controller
9+
{
10+
public ActionResult Index()
11+
{
12+
return View();
13+
}
14+
15+
[CustomOnActionExecuted]
16+
public ActionResult GetData()
17+
{
18+
var data = new List<OnActionExecutedTestModel>();
19+
for (int i = 1; i <= 5; i++)
20+
{
21+
data.Add(new OnActionExecutedTestModel { Number = i });
22+
}
23+
24+
return this.View(data.AsQueryable());
25+
}
26+
}
27+
28+
public class OnActionExecutedTestModel
29+
{
30+
public int Number { get; set; }
31+
}
32+
33+
public class CustomOnActionExecutedAttribute : JQDT.MVC.JQDataTableAttribute
34+
{
35+
public override void OnDataProcessed(ref object data, RequestInfoModel requestInfoModel)
36+
{
37+
var list = ((IQueryable<OnActionExecutedTestModel>)data).ToList();
38+
for (int i = 6; i <= 10; i++)
39+
{
40+
list.Add(new OnActionExecutedTestModel { Number = i });
41+
}
42+
43+
data = list.AsQueryable();
44+
}
45+
}
46+
}

src/Tests/integrationtests/Tests.Integration.Mvc/Tests.Integration.Mvc.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
<Compile Include="App_Start\RouteConfig.cs" />
153153
<Compile Include="Configuration\SettingsProvider.cs" />
154154
<Compile Include="Controllers\HomeController.cs" />
155+
<Compile Include="Controllers\TestOnActionExecutedController.cs" />
155156
<Compile Include="EntityFrameworkClasses\AppContext.cs" />
156157
<Compile Include="Global.asax.cs">
157158
<DependentUpon>Global.asax</DependentUpon>
@@ -213,6 +214,7 @@
213214
<Content Include="Scripts\jquery-3.2.1.slim.min.map" />
214215
<Content Include="Scripts\jquery-3.2.1.min.map" />
215216
<None Include="Views\Home\AllTypesData.cshtml" />
217+
<Content Include="Views\TestOnActionExecuted\Index.cshtml" />
216218
</ItemGroup>
217219
<ItemGroup>
218220
<Folder Include="App_Data\" />
@@ -226,6 +228,10 @@
226228
<Project>{d845ab6d-1887-4597-9256-148ad0a11459}</Project>
227229
<Name>JQDT.MVC</Name>
228230
</ProjectReference>
231+
<ProjectReference Include="..\..\..\JQDT\JQDT.csproj">
232+
<Project>{C82E4675-88AB-4B78-8475-F1521BDAE330}</Project>
233+
<Name>JQDT</Name>
234+
</ProjectReference>
229235
<ProjectReference Include="..\..\TestData.Data\TestData.Data.csproj">
230236
<Project>{F7F12DE8-F3C3-42A4-BBE4-1868D287D388}</Project>
231237
<Name>TestData.Data</Name>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
@{
3+
ViewBag.Title = "Index";
4+
Layout = "~/Views/Shared/_Layout.cshtml";
5+
}
6+
7+
8+
@{
9+
ViewBag.Title = "Index";
10+
Layout = "~/Views/Shared/_Layout.cshtml";
11+
}
12+
13+
<table class="display" cellspacing="0" width="100%">
14+
<thead>
15+
<tr>
16+
<th>Test</th>
17+
</tr>
18+
</thead>
19+
20+
<tfoot>
21+
<tr>
22+
<th>Test</th>
23+
</tr>
24+
</tfoot>
25+
</table>
26+
27+
@section Scripts {
28+
<script>
29+
var table = $('table').DataTable({
30+
"proccessing": true,
31+
"serverSide": true,
32+
"ajax": {
33+
url: "@Url.Action("GetData", "TestOnActionExecuted")",
34+
type: 'POST'
35+
},
36+
"columns": [
37+
{ "data": "Number" },
38+
]
39+
});
40+
</script>
41+
}
42+

src/Tests/integrationtests/Tests.SeleniumTests/Common/GlobalConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class GlobalConstants
44
{
55
public const string ServerBaseUrl = "http://localhost:54390/";
66
public const string AllTypesDataPageRelativeUrl = "Home/AllTypesData/";
7+
public const string OnDataProcessedTestPageRelativeUrl = "TestOnActionExecuted/";
78
public const int GlobalThreadSleep = 1000;
89
public const string NotCompletedTest = "Not completed test";
910
public const string AllTypesModelFullDataUrl = "home/GetFullData";

src/Tests/integrationtests/Tests.SeleniumTests/Common/Navigator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ public IWebPage AllTypesDataPage()
1616
{
1717
return new AllTypesDataPage(this.driver);
1818
}
19+
20+
public IWebPage OnDataExecutedEventTestsPage()
21+
{
22+
return new OnDataProcessedTestsPage(this.driver);
23+
}
1924
}
2025
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Tests.SeleniumTests.Pages
2+
{
3+
using Common;
4+
using OpenQA.Selenium;
5+
6+
public class OnDataProcessedTestsPage : IWebPage
7+
{
8+
private readonly IWebDriver driver;
9+
10+
public OnDataProcessedTestsPage(IWebDriver driver)
11+
{
12+
this.driver = driver;
13+
}
14+
15+
public void GoTo(string queryString = null)
16+
{
17+
this.driver.Navigate().GoToUrl(GlobalConstants.ServerBaseUrl + GlobalConstants.OnDataProcessedTestPageRelativeUrl + queryString);
18+
}
19+
}
20+
}

src/Tests/integrationtests/Tests.SeleniumTests/Tests.SeleniumTests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@
8888
<Compile Include="ExtensionMethods\EnumerableExtensionMethods.cs" />
8989
<Compile Include="ExtensionMethods\SearchContextExtensionMethods.cs" />
9090
<Compile Include="Models\MinMaxRandomModel.cs" />
91+
<Compile Include="Pages\OnDataProcessedTestsPage.cs" />
9192
<Compile Include="TestsSetupClass.cs" />
9293
<Compile Include="Pages\AllTypesDataPage.cs" />
9394
<Compile Include="Pages\IWebPage.cs" />
9495
<Compile Include="Properties\AssemblyInfo.cs" />
9596
<Compile Include="Tests\ColumnFiltersIntegrationTests.cs" />
9697
<Compile Include="Tests\CustomFiltersIntegrationTests.cs" />
98+
<Compile Include="Tests\OnActionExecutedIntegrationTests.cs" />
9799
<Compile Include="Tests\SearchIntegrationTests.cs" />
98100
<Compile Include="Tests\SortDataIntegrationTests.cs" />
99101
</ItemGroup>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Linq;
2+
using NUnit.Framework;
3+
using OpenQA.Selenium;
4+
using Tests.SeleniumTests.Common;
5+
6+
namespace Tests.SeleniumTests.Tests
7+
{
8+
public class OnActionExecutedIntegrationTests
9+
{
10+
private IWebDriver driver;
11+
12+
private Navigator navigator;
13+
14+
[SetUp]
15+
public void SetUp()
16+
{
17+
this.driver = DriverSingletonProvider.GetDriver();
18+
this.navigator = new Navigator(driver);
19+
}
20+
21+
[Test]
22+
public void ExpectToAddAdditionalDataFromOnActionExecutedEvent()
23+
{
24+
navigator.OnDataExecutedEventTestsPage().GoTo();
25+
var table = new TableElement("table", this.driver);
26+
var actualValues = table.GetColumnRowValuesUntilAny("Test");
27+
28+
var expectedValues = Enumerable.Range(1, 10).Select(x => x.ToString());
29+
Assert.IsTrue(expectedValues.SequenceEqual(actualValues));
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)