Skip to content

Commit 2328ab3

Browse files
committed
Data processors event on app base unit tests added
1 parent 8fd4084 commit 2328ab3

File tree

5 files changed

+228
-12
lines changed

5 files changed

+228
-12
lines changed

src/Tests/UnitTests/Tests.UnitTests/ApplicationBaseUnitTests.cs

Lines changed: 153 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
public class ApplicationBaseUnitTests
1717
{
1818
[Test]
19-
public void OnDataProcessingEventShouldBeRized()
19+
public void OnDataProcessingEventShouldBeRaized()
2020
{
2121
var app = this.GetAppMock();
22-
2322
bool flag = false;
2423
app.OnDataProcessingEvent += (ref object data, RequestInfoModel requestInfoModel) =>
2524
{
@@ -33,10 +32,9 @@ public void OnDataProcessingEventShouldBeRized()
3332
}
3433

3534
[Test]
36-
public void OnDataProcessedEventShouldBeRized()
35+
public void OnDataProcessedEventShouldBeRaized()
3736
{
3837
var app = this.GetAppMock();
39-
4038
bool flag = false;
4139
app.OnDataProcessedEvent += (ref object data, RequestInfoModel requestInfoModel) =>
4240
{
@@ -50,10 +48,9 @@ public void OnDataProcessedEventShouldBeRized()
5048
}
5149

5250
[Test]
53-
public void OnSearchDataProcessingEventShouldBeRized()
51+
public void OnSearchDataProcessingEventShouldBeRaized()
5452
{
5553
var app = this.GetAppMock();
56-
5754
bool flag = false;
5855
app.OnSearchDataProcessingEvent += (ref object data, RequestInfoModel requestInfoModel) =>
5956
{
@@ -66,14 +63,158 @@ public void OnSearchDataProcessingEventShouldBeRized()
6663
Assert.IsTrue(flag);
6764
}
6865

66+
[Test]
67+
public void OnSearchDataProcessedEventShouldBeRaized()
68+
{
69+
var app = this.GetAppMock();
70+
bool flag = false;
71+
app.OnSearchDataProcessedEvent += (ref object data, RequestInfoModel requestInfoModel) =>
72+
{
73+
Trace.WriteLine(flag);
74+
flag = true;
75+
};
76+
77+
app.Execute();
78+
79+
Assert.IsTrue(flag);
80+
}
81+
82+
[Test]
83+
public void OnColumnsFilterDataProcessingEventShouldBeRaized()
84+
{
85+
var app = this.GetAppMock();
86+
bool flag = false;
87+
app.OnColumnsFilterDataProcessingEvent += (ref object data, RequestInfoModel requestInfoModel) =>
88+
{
89+
Trace.WriteLine(flag);
90+
flag = true;
91+
};
92+
93+
app.Execute();
94+
95+
Assert.IsTrue(flag);
96+
}
97+
98+
[Test]
99+
public void OnColumnsFilterDataProcessedEventShouldBeRaized()
100+
{
101+
var app = this.GetAppMock();
102+
bool flag = false;
103+
app.OnColumnsFilterDataProcessedEvent += (ref object data, RequestInfoModel requestInfoModel) =>
104+
{
105+
Trace.WriteLine(flag);
106+
flag = true;
107+
};
108+
109+
app.Execute();
110+
111+
Assert.IsTrue(flag);
112+
}
113+
114+
[Test]
115+
public void OnCustomFiltersDataProcessingEventShouldBeRaized()
116+
{
117+
var app = this.GetAppMock();
118+
bool flag = false;
119+
app.OnCustomFiltersDataProcessingEvent += (ref object data, RequestInfoModel requestInfoModel) =>
120+
{
121+
Trace.WriteLine(flag);
122+
flag = true;
123+
};
124+
125+
app.Execute();
126+
127+
Assert.IsTrue(flag);
128+
}
129+
130+
[Test]
131+
public void OnCustomFiltersDataProcessedEventShouldBeRaized()
132+
{
133+
var app = this.GetAppMock();
134+
bool flag = false;
135+
app.OnCustomFiltersDataProcessedEvent += (ref object data, RequestInfoModel requestInfoModel) =>
136+
{
137+
Trace.WriteLine(flag);
138+
flag = true;
139+
};
140+
141+
app.Execute();
142+
143+
Assert.IsTrue(flag);
144+
}
145+
146+
[Test]
147+
public void OnPagingDataProcessingEventShouldBeRaized()
148+
{
149+
var app = this.GetAppMock();
150+
bool flag = false;
151+
app.OnPagingDataProcessingEvent += (ref object data, RequestInfoModel requestInfoModel) =>
152+
{
153+
Trace.WriteLine(flag);
154+
flag = true;
155+
};
156+
157+
app.Execute();
158+
159+
Assert.IsTrue(flag);
160+
}
161+
162+
[Test]
163+
public void OnPagingDataProcessedEventShouldBeRaized()
164+
{
165+
var app = this.GetAppMock();
166+
bool flag = false;
167+
app.OnPagingDataProcessedEvent += (ref object data, RequestInfoModel requestInfoModel) =>
168+
{
169+
Trace.WriteLine(flag);
170+
flag = true;
171+
};
172+
173+
app.Execute();
174+
175+
Assert.IsTrue(flag);
176+
}
177+
178+
[Test]
179+
public void OnSortDataProcessingEventShouldBeRaized()
180+
{
181+
var app = this.GetAppMock();
182+
bool flag = false;
183+
app.OnSortDataProcessingEvent += (ref object data, RequestInfoModel requestInfoModel) =>
184+
{
185+
Trace.WriteLine(flag);
186+
flag = true;
187+
};
188+
189+
app.Execute();
190+
191+
Assert.IsTrue(flag);
192+
}
193+
194+
[Test]
195+
public void OnSortDataProcessedEventShouldBeRaized()
196+
{
197+
var app = this.GetAppMock();
198+
bool flag = false;
199+
app.OnSortDataProcessedEvent += (ref object data, RequestInfoModel requestInfoModel) =>
200+
{
201+
Trace.WriteLine(flag);
202+
flag = true;
203+
};
204+
205+
app.Execute();
206+
207+
Assert.IsTrue(flag);
208+
}
209+
69210
public AppMock<IntModel> GetAppMock()
70211
{
71212
var serviceLocatorMock = new Mock<IServiceLocator>();
72-
serviceLocatorMock.Setup(x => x.GetSearchDataProcessor<IntModel>()).Returns(this.GetDataFilterMock().Object);
73-
serviceLocatorMock.Setup(x => x.GetColumnsFilterDataProcessor<IntModel>()).Returns(this.GetDataFilterMock().Object);
74-
serviceLocatorMock.Setup(x => x.GetCustomFiltersDataProcessor<IntModel>()).Returns(this.GetDataFilterMock().Object);
75-
serviceLocatorMock.Setup(x => x.GetPagingDataProcessor<IntModel>()).Returns(this.GetDataProcessMock().Object);
76-
serviceLocatorMock.Setup(x => x.GetSortDataProcessor<IntModel>()).Returns(this.GetDataProcessMock().Object);
213+
serviceLocatorMock.Setup(x => x.GetSearchDataProcessor<IntModel>()).Returns(new DataProcessorFilterFake<IntModel>());
214+
serviceLocatorMock.Setup(x => x.GetColumnsFilterDataProcessor<IntModel>()).Returns(new DataProcessorFilterFake<IntModel>());
215+
serviceLocatorMock.Setup(x => x.GetCustomFiltersDataProcessor<IntModel>()).Returns(new DataProcessorFilterFake<IntModel>());
216+
serviceLocatorMock.Setup(x => x.GetPagingDataProcessor<IntModel>()).Returns(new DataProcessorNotFilterFake<IntModel>());
217+
serviceLocatorMock.Setup(x => x.GetSortDataProcessor<IntModel>()).Returns(new DataProcessorNotFilterFake<IntModel>());
77218
var formModelBinderMock = new Mock<IFormModelBinder>();
78219
formModelBinderMock.Setup(x => x.BindModel(It.IsAny<NameValueCollection>(), It.IsAny<IQueryable<IntModel>>())).Returns(new RequestInfoModel() { Helpers = new RequestHelpers(), TableParameters = new DataTableAjaxPostModel() });
79220
var app = new AppMock<IntModel>(serviceLocatorMock.Object, formModelBinderMock.Object);
@@ -85,7 +226,7 @@ private Mock<IDataProcess<IntModel>> GetDataProcessMock()
85226
{
86227
var mock = new Mock<IDataProcess<IntModel>>();
87228
mock.Setup(x => x.ProcessData(It.IsAny<IQueryable<IntModel>>(), It.IsAny<RequestInfoModel>())).Returns(new List<IntModel>().AsQueryable());
88-
mock.Raise(x => x.OnDataProcessedEvent += delegate { });
229+
//mock.Raise(x => x.OnDataProcessedEvent += delegate { });
89230
return mock;
90231
}
91232

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Tests.UnitTests.Mocks
2+
{
3+
using JQDT.DI;
4+
using Moq;
5+
6+
public class AppServiceLocatorMockModel<T>
7+
{
8+
public AppMock<T> AppMock { get; set; }
9+
10+
public Mock<IServiceLocator> ServiceLocatorMock { get; set; }
11+
}
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace Tests.UnitTests.Mocks
2+
{
3+
using System.Linq;
4+
using JQDT.DataProcessing;
5+
using JQDT.Delegates;
6+
using JQDT.Models;
7+
8+
internal class DataProcessorFilterFake<T> : DataProcessBase<T>, IDataFilter
9+
{
10+
public IQueryable<T> ProcessedData { get; set; }
11+
12+
public event DataProcessorEventHandler OnDataProcessingEvent = delegate { };
13+
14+
public event DataProcessorEventHandler OnDataProcessedEvent = delegate { };
15+
16+
public IQueryable<T> ProcessData(IQueryable<T> data, RequestInfoModel requestInfoModel)
17+
{
18+
this.ProcessedData = data;
19+
20+
return data;
21+
}
22+
23+
protected override IQueryable<T> OnProcessData(IQueryable<T> data, RequestInfoModel requestInfoModel)
24+
{
25+
this.ProcessedData = data;
26+
27+
return data;
28+
}
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace Tests.UnitTests.Mocks
2+
{
3+
using System.Linq;
4+
using JQDT.DataProcessing;
5+
using JQDT.Delegates;
6+
using JQDT.Models;
7+
8+
internal class DataProcessorNotFilterFake<T> : DataProcessBase<T>, IDataFilter
9+
{
10+
public IQueryable<T> ProcessedData { get; set; }
11+
12+
public event DataProcessorEventHandler OnDataProcessingEvent = delegate { };
13+
14+
public event DataProcessorEventHandler OnDataProcessedEvent = delegate { };
15+
16+
public IQueryable<T> ProcessData(IQueryable<T> data, RequestInfoModel requestInfoModel)
17+
{
18+
this.ProcessedData = data;
19+
20+
return data;
21+
}
22+
23+
protected override IQueryable<T> OnProcessData(IQueryable<T> data, RequestInfoModel requestInfoModel)
24+
{
25+
this.ProcessedData = data;
26+
27+
return data;
28+
}
29+
}
30+
}

src/Tests/UnitTests/Tests.UnitTests/Tests.UnitTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@
7878
<Compile Include="ColumnsFilterDataProcessorUnitTests.cs" />
7979
<Compile Include="Common\TestHelpers.cs" />
8080
<Compile Include="CustomFiltersDataProcessorUnitTests.cs" />
81+
<Compile Include="Mocks\AppServiceLocatorMockModel.cs" />
82+
<Compile Include="Mocks\DataProcessorFilterFake.cs" />
8183
<Compile Include="Mocks\DataProcessorMockModel.cs" />
84+
<Compile Include="Mocks\DataProcessorNotFilterFake.cs" />
8285
<Compile Include="Models\IntModel.cs" />
8386
<Compile Include="PagingDataProcessorTests.cs" />
8487
<Compile Include="Properties\AssemblyInfo.cs" />

0 commit comments

Comments
 (0)