Skip to content

Commit eee9227

Browse files
committed
Corrected tests
1 parent bb90dac commit eee9227

File tree

12 files changed

+114
-28
lines changed

12 files changed

+114
-28
lines changed

src/Server/Coderr.Server.SqlServer.Tests/Analysis/IncidentBeingAnalyzedMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public void Should_load_ignored_state_into_class_correctly()
2828
};
2929
report.Init(report.GenerateHashCodeIdentifier());
3030

31-
using (var uow = CreateUnitOfWork())
31+
using (var uow = new AnalysisDbContext(OpenConnection))
3232
{
3333
var incident = new IncidentBeingAnalyzed(report);
34-
var incRepos = new AnalyticsRepository(new AnalysisDbContext(uow), new TestConfigStore());
34+
var incRepos = new AnalyticsRepository(uow, new TestConfigStore());
3535
incRepos.CreateIncident(incident);
3636
report.IncidentId = incident.Id;
3737
incRepos.CreateReport(report);

src/Server/Coderr.Server.SqlServer.Tests/Helpers/DatabaseManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Data.SqlClient;
55
using System.Diagnostics;
66
using System.Threading;
7+
using codeRR.Server.ReportAnalyzer;
78
using Griffin.Data;
89
using Griffin.Data.Mapper;
910

@@ -66,9 +67,9 @@ public void CreateEmptyDatabase()
6667
}
6768
}
6869

69-
public IAdoNetUnitOfWork CreateUnitOfWork()
70+
public OurUnitOfWork CreateUnitOfWork()
7071
{
71-
return new AdoNetUnitOfWork(OpenConnection(), true);
72+
return new OurUnitOfWork(OpenConnection(), true);
7273
}
7374

7475
public void DeleteDatabase()

src/Server/Coderr.Server.SqlServer.Tests/Helpers/TestDataManager.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,38 @@ public void ActivateAccount(int accountId)
7474
/// </summary>
7575
public void CreateReportAndIncident(out int reportId, out int incidentId)
7676
{
77+
ErrorReportEntity report;
7778
using (var uow = CreateUnitOfWork())
7879
{
7980
CreateUserAndApplication(uow, out var accountId, out var applicationId);
8081

81-
var report = new ErrorReportEntity(applicationId, Guid.NewGuid().ToString("N"), DateTime.UtcNow,
82+
report = new ErrorReportEntity(applicationId, Guid.NewGuid().ToString("N"), DateTime.UtcNow,
8283
new ErrorReportException(new Exception("mofo")),
8384
new List<ErrorReportContext>
8485
{
8586
new ErrorReportContext("Maps", new Dictionary<string, string>())
8687
})
87-
{Title = "Missing here"};
88+
{ Title = "Missing here" };
8889
report.Init(report.GenerateHashCodeIdentifier());
8990

91+
uow.SaveChanges();
92+
}
93+
94+
using (var dbContext = new AnalysisDbContext(_connectionFactory))
95+
{
9096
var incident = new IncidentBeingAnalyzed(report);
91-
var incRepos = new AnalyticsRepository(new AnalysisDbContext(uow), ConfigStore);
97+
var incRepos = new AnalyticsRepository(dbContext, ConfigStore);
9298
incRepos.CreateIncident(incident);
9399
incidentId = incident.Id;
94100

95101
report.IncidentId = incident.Id;
96102
incRepos.CreateReport(report);
97103
reportId = report.Id;
98104

99-
uow.SaveChanges();
105+
dbContext.SaveChanges();
100106
}
107+
108+
101109
}
102110

103111
public void CreateUserAndApplication(out int accountId, out int applicationId)
@@ -207,15 +215,15 @@ public void ResetDatabase(string baseUrl)
207215
protected void CreateUserAndApplication(IAdoNetUnitOfWork uow, out int accountId, out int applicationId)
208216
{
209217
var accountRepos = new AccountRepository(uow);
210-
var account = new Account(TestUser.Username, TestUser.Password) {Email = TestUser.Email};
218+
var account = new Account(TestUser.Username, TestUser.Password) { Email = TestUser.Email };
211219
account.Activate();
212220
accountRepos.Create(account);
213221
var userRepos = new UserRepository(uow);
214-
var user = new User(account.Id, TestUser.Username) {EmailAddress =TestUser.Email};
222+
var user = new User(account.Id, TestUser.Username) { EmailAddress = TestUser.Email };
215223
userRepos.CreateAsync(user).GetAwaiter().GetResult();
216224

217225
var appRepos = new ApplicationRepository(uow);
218-
var app = new Application(account.Id, "MyTestApp") {ApplicationType = TypeOfApplication.DesktopApplication};
226+
var app = new Application(account.Id, "MyTestApp") { ApplicationType = TypeOfApplication.DesktopApplication };
219227
appRepos.CreateAsync(app).GetAwaiter().GetResult();
220228
var member = new ApplicationTeamMember(app.Id, account.Id, "Admin");
221229
appRepos.CreateAsync(member).GetAwaiter().GetResult();
@@ -224,9 +232,9 @@ protected void CreateUserAndApplication(IAdoNetUnitOfWork uow, out int accountId
224232
applicationId = app.Id;
225233
}
226234

227-
private IAdoNetUnitOfWork CreateUnitOfWork()
235+
private OurUnitOfWork CreateUnitOfWork()
228236
{
229-
return new AdoNetUnitOfWork(_connectionFactory(), true);
237+
return new OurUnitOfWork(_connectionFactory(), true);
230238
}
231239
}
232240
}

src/Server/Coderr.Server.SqlServer.Tests/IntegrationTest.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
2+
using System.Data;
23
using System.IO;
4+
using codeRR.Server.ReportAnalyzer;
35
using codeRR.Server.SqlServer.Core.Accounts;
46
using codeRR.Server.SqlServer.Tests.Helpers;
7+
using codeRR.Server.SqlServer.Tests.Models;
58
using codeRR.Server.SqlServer.Tests.Xunit;
69
using Griffin.Data;
710
using Griffin.Data.Mapper;
@@ -51,6 +54,12 @@ static IntegrationTest()
5154
public IntegrationTest(ITestOutputHelper output)
5255
{
5356
_testDataManager = new TestDataManager(_databaseManager.OpenConnection);
57+
_testDataManager.TestUser = new TestUser()
58+
{
59+
Email = "test@somewhere.com",
60+
Password = "123456",
61+
Username = "admin"
62+
};
5463
}
5564

5665
public int FirstApplicationId => _testDataManager.ApplicationId;
@@ -61,11 +70,17 @@ public void Dispose()
6170
Dispose(true);
6271
}
6372

64-
protected IAdoNetUnitOfWork CreateUnitOfWork()
73+
protected OurUnitOfWork CreateUnitOfWork()
6574
{
6675
return _databaseManager.CreateUnitOfWork();
6776
}
6877

78+
protected IDbConnection OpenConnection()
79+
{
80+
return _databaseManager.OpenConnection();
81+
}
82+
83+
6984
protected virtual void Dispose(bool isBeingDisposed)
7085
{
7186
}

src/Server/Coderr.Server.SqlServer/Analysis/AnalyticsRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ public void CreateReport(ErrorReportEntity report)
133133
collections.Add(data);
134134
}
135135

136+
_unitOfWork.Insert(report);
137+
136138
var cols = string.Join(", ", collections);
137139
var inboound = new InboundCollection
138140
{
139141
JsonData = $"[{cols}]",
140142
ReportId = report.Id
141143
};
142-
143-
_unitOfWork.Insert(report);
144144
_unitOfWork.Insert(inboound);
145145
}
146146

src/Server/Coderr.Server.SqlServer/Analysis/ErrorReportEntityMapper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public ErrorReportEntityMapper() : base("ErrorReports")
1616
.ToColumnValue(EntitySerializer.Serialize);
1717

1818
Property(x => x.ContextInfo)
19-
.Ignore();
19+
.ToPropertyValue(x => null)
20+
.ToColumnValue(x => "");
2021

2122
Property(x => x.ClientReportId)
2223
.ColumnName("ErrorId");

src/Server/Coderr.Server.SqlServer/Analysis/Jobs/InboundCollectionMapper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class InboundCollectionMapper : CrudEntityMapper<InboundCollection>
1111
{
1212
public InboundCollectionMapper() : base("ErrorReportCollectionInbound")
1313
{
14+
Property(x => x.JsonData)
15+
.ColumnName("Body");
1416

1517
}
1618
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
DECLARE @ConstraintName nvarchar(200)
2+
SELECT @ConstraintName = KCU.CONSTRAINT_NAME
3+
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC
4+
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU
5+
ON KCU.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG
6+
AND KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA
7+
AND KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
8+
WHERE
9+
KCU.TABLE_NAME = 'ApplicationVersionMonths' AND
10+
KCU.COLUMN_NAME = 'VersionId'
11+
IF @ConstraintName IS NOT NULL
12+
BEGIN
13+
EXEC('ALTER TABLE ApplicationVersionMonths DROP CONSTRAINT ' + @ConstraintName)
14+
END;
15+
ALTER TABLE ApplicationVersionMonths WITH CHECK ADD CONSTRAINT FK_ApplicationVersionMonths_ApplicationVersions FOREIGN KEY (VersionId) REFERENCES ApplicationVersions (Id) ON DELETE CASCADE;
16+
17+
18+
19+
SELECT @ConstraintName = KCU.CONSTRAINT_NAME
20+
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC
21+
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU
22+
ON KCU.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG
23+
AND KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA
24+
AND KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
25+
WHERE
26+
KCU.TABLE_NAME = 'ApplicationVersions' AND
27+
KCU.COLUMN_NAME = 'ApplicationId'
28+
IF @ConstraintName IS NOT NULL
29+
BEGIN
30+
EXEC('ALTER TABLE ApplicationVersions DROP CONSTRAINT ' + @ConstraintName)
31+
END;
32+
ALTER TABLE ApplicationVersions WITH CHECK ADD CONSTRAINT FK_ApplicationVersions_Applications FOREIGN KEY (ApplicationId) REFERENCES Applications (Id) ON DELETE CASCADE;
33+
34+
SELECT @ConstraintName = KCU.CONSTRAINT_NAME
35+
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC
36+
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU
37+
ON KCU.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG
38+
AND KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA
39+
AND KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
40+
WHERE
41+
KCU.TABLE_NAME = 'IncidentVersions' AND
42+
KCU.COLUMN_NAME = 'IncidentId'
43+
IF @ConstraintName IS NOT NULL
44+
BEGIN
45+
EXEC('ALTER TABLE IncidentVersions DROP CONSTRAINT ' + @ConstraintName)
46+
END;
47+
ALTER TABLE IncidentVersions WITH CHECK ADD CONSTRAINT FK_IncVersions_Incidents FOREIGN KEY (IncidentId) REFERENCES Incidents (Id) ON DELETE CASCADE;
48+
49+
create table ErrorReportCollectionProperties
50+
(
51+
Id int identity not null primary key,
52+
ReportId int not null constraint FK_ErrorReportCollectionProperties_ErrorReports REFERENCES ErrorReports(Id) ON DELETE CASCADE,
53+
Name varchar(50) not null,
54+
PropertyName varchar(50) not null,
55+
Value nvarchar(MAX) not null
56+
);
57+
58+
59+
create table ErrorReportCollectionInbound
60+
(
61+
Id int identity not null primary key,
62+
ReportId int not null constraint FK_ErrorReportCollectionInbound_ErrorReports REFERENCES ErrorReports(Id) ON DELETE CASCADE,
63+
Body nvarchar(max) not null
64+
);
65+
66+
UPDATE DatabaseSchema SET Version = 9;

src/Server/Coderr.Server.SqlServer/codeRR.Server.SqlServer.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@
2323
<ItemGroup>
2424
<EmbeddedResource Include="Schema\*.sql" />
2525
</ItemGroup>
26+
<ItemGroup>
27+
<None Remove="Schema\Update.v9.sql" />
28+
</ItemGroup>
2629
</Project>

src/Server/Coderr.Server.Web.Tests/applicationhost.config

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-

2-
3-
4-
5-
6-
7-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
82
<!--
93
104
IIS configuration sections.

0 commit comments

Comments
 (0)