Skip to content

Commit 632454b

Browse files
committed
- fix tests
1 parent dd45c79 commit 632454b

13 files changed

+97
-44
lines changed

src/eAuthor.API/Controllers/BaseDocxTemplatesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public BaseDocxTemplatesController(IBaseDocxTemplateRepository repo)
1919

2020
[HttpPost("upload")]
2121
[RequestSizeLimit(20_000_000)] // 20MB
22-
public async Task<IActionResult> Upload([FromForm] IFormFile file)
22+
public async Task<IActionResult> Upload([FromBody] FormFile file)
2323
{
2424
if (file == null || file.Length == 0)
2525
return BadRequest("File required");

src/eAuthor.API/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@
113113
{
114114
cfg.SwaggerDoc("v1", new()
115115
{
116-
Title = "Word Templating API",
116+
Title = "eAuthor API",
117117
Version = "v1",
118-
Description = "Dynamic DOCX generation & templating platform"
118+
Description = "Dynamic document generation & templating platform"
119119
});
120120

121121
// JWT header

src/eAuthor.API/Properties/launchSettings.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,22 @@
2525
},
2626
"publishAllPorts": true,
2727
"useSSL": true
28+
},
29+
"IIS Express": {
30+
"commandName": "IISExpress",
31+
"launchBrowser": true,
32+
"environmentVariables": {
33+
"ASPNETCORE_ENVIRONMENT": "Development"
34+
}
2835
}
2936
},
30-
"$schema": "https://json.schemastore.org/launchsettings.json"
37+
"$schema": "https://json.schemastore.org/launchsettings.json",
38+
"iisSettings": {
39+
"windowsAuthentication": false,
40+
"anonymousAuthentication": true,
41+
"iisExpress": {
42+
"applicationUrl": "http://localhost:57506/",
43+
"sslPort": 44341
44+
}
45+
}
3146
}
Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Dapper;
22
using eAuthor.Models;
3+
using System.Data;
34

45
namespace eAuthor.Repositories.Impl;
56

@@ -8,7 +9,9 @@ public class DocumentGenerationJobRepository : IDocumentGenerationJobRepository
89
private readonly IDapperContext _ctx;
910

1011
public DocumentGenerationJobRepository(IDapperContext ctx)
11-
{ _ctx = ctx; }
12+
{
13+
_ctx = ctx;
14+
}
1215

1316
public async Task<IEnumerable<DocumentGenerationJob>> GetByCorrelationAsync(Guid correlationId)
1417
{
@@ -28,50 +31,89 @@ public async Task<IEnumerable<DocumentGenerationJob>> GetByCorrelationAsync(Guid
2831
public async Task InsertBatchAsync(IEnumerable<DocumentGenerationJob> jobs)
2932
{
3033
using var conn = _ctx.CreateConnection();
34+
if (conn.State != ConnectionState.Open)
35+
conn.Open();
36+
3137
using var tx = conn.BeginTransaction();
32-
foreach (var j in jobs)
33-
await conn.ExecuteAsync(@"
34-
INSERT INTO DocumentGenerationJobs
35-
(Id, TemplateId, Status, InputData, CreatedUtc, CorrelationId, BatchGroup)
36-
VALUES (@Id,@TemplateId,@Status,@InputData,@CreatedUtc,@CorrelationId,@BatchGroup);", j, tx);
37-
tx.Commit();
38+
try
39+
{
40+
foreach (var j in jobs)
41+
{
42+
await conn.ExecuteAsync(@"
43+
INSERT INTO DocumentGenerationJobs
44+
(Id, TemplateId, Status, InputData, CreatedUtc, CorrelationId, BatchGroup)
45+
VALUES (@Id,@TemplateId,@Status,@InputData,@CreatedUtc,@CorrelationId,@BatchGroup);",
46+
j, tx);
47+
}
48+
tx.Commit();
49+
}
50+
catch
51+
{
52+
try
53+
{ tx.Rollback(); }
54+
catch { /* ignore rollback errors */ }
55+
throw;
56+
}
3857
}
3958

40-
public bool LockingSupported => true;
41-
42-
public bool UseAppLock => false;
43-
4459
public async Task<(bool, DocumentGenerationJob?)> TryStartNextPendingAsync()
4560
{
4661
using var conn = _ctx.CreateConnection();
47-
using var tx = conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
48-
// pick one pending
49-
var candidate = await conn.QueryFirstOrDefaultAsync<DocumentGenerationJob>(
50-
"SELECT TOP 1 * FROM DocumentGenerationJobs WITH (UPDLOCK, READPAST, ROWLOCK) WHERE Status='Pending' ORDER BY CreatedUtc");
51-
if (candidate == null)
62+
if (conn.State != ConnectionState.Open)
63+
conn.Open();
64+
65+
using var tx = conn.BeginTransaction(IsolationLevel.ReadCommitted);
66+
try
5267
{
68+
var candidate = await conn.QueryFirstOrDefaultAsync<DocumentGenerationJob>(
69+
"SELECT TOP 1 * FROM DocumentGenerationJobs WITH (UPDLOCK, READPAST, ROWLOCK) WHERE Status='Pending' ORDER BY CreatedUtc",
70+
transaction: tx);
71+
72+
if (candidate == null)
73+
{
74+
tx.Commit();
75+
return (false, candidate);
76+
}
77+
78+
await conn.ExecuteAsync(
79+
"UPDATE DocumentGenerationJobs SET Status='Processing', StartedUtc=SYSUTCDATETIME() WHERE Id=@Id",
80+
new { candidate.Id }, tx);
81+
5382
tx.Commit();
54-
return (false, candidate);
83+
84+
candidate.Status = "Processing";
85+
candidate.StartedUtc = DateTime.UtcNow;
86+
return (true, candidate);
87+
}
88+
catch
89+
{
90+
try
91+
{ tx.Rollback(); }
92+
catch { /* ignore rollback errors */ }
93+
throw;
5594
}
56-
await conn.ExecuteAsync("UPDATE DocumentGenerationJobs SET Status='Processing', StartedUtc=SYSUTCDATETIME() WHERE Id=@Id",
57-
new { candidate.Id }, tx);
58-
tx.Commit();
59-
candidate.Status = "Processing";
60-
candidate.StartedUtc = DateTime.UtcNow;
61-
return (true, candidate);
6295
}
6396

6497
public async Task CompleteSuccessAsync(Guid id, byte[] file)
6598
{
6699
using var conn = _ctx.CreateConnection();
67-
await conn.ExecuteAsync(@"UPDATE DocumentGenerationJobs SET Status='Completed', ResultFile=@ResultFile, CompletedUtc=SYSUTCDATETIME()
68-
WHERE Id=@Id", new { Id = id, ResultFile = file });
100+
await conn.ExecuteAsync(@"
101+
UPDATE DocumentGenerationJobs
102+
SET Status='Completed', ResultFile=@ResultFile, CompletedUtc=SYSUTCDATETIME()
103+
WHERE Id=@Id",
104+
new { Id = id, ResultFile = file });
69105
}
70106

71107
public async Task CompleteFailureAsync(Guid id, string error)
72108
{
73109
using var conn = _ctx.CreateConnection();
74-
await conn.ExecuteAsync(@"UPDATE DocumentGenerationJobs SET Status='Failed', ErrorMessage=@Error, CompletedUtc=SYSUTCDATETIME()
75-
WHERE Id=@Id", new { Id = id, Error = error });
110+
await conn.ExecuteAsync(@"
111+
UPDATE DocumentGenerationJobs
112+
SET Status='Failed', ErrorMessage=@Error, CompletedUtc=SYSUTCDATETIME()
113+
WHERE Id=@Id",
114+
new { Id = id, Error = error });
76115
}
116+
117+
public bool LockingSupported => true;
118+
public bool UseAppLock => false;
77119
}

src/eAuthor.API/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"ConnectionStrings": {
3-
"Default": "Server=localhost\\MSSQLSERVER01;Database=author;Trusted_Connection=True;"
3+
"Default": "Server=localhost\\MSSQLSERVER01;Database=author;Integrated Security=SSPI;Encrypt=True;TrustServerCertificate=True;"
44
},
55
"Logging": {
66
"LogLevel": {

tests/eAuthor.API.Tests/ArrayIndexExpressionTests.cs renamed to tests/eAuthor.API.Tests/Services/ArrayIndexExpressionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using NUnit.Framework;
33
using System.Text.Json;
44

5-
namespace eAuthor.API.Tests;
5+
namespace eAuthor.API.Tests.Services;
66

77
public class ArrayIndexExpressionTests
88
{

tests/eAuthor.API.Tests/ConditionalElseIfTests.cs renamed to tests/eAuthor.API.Tests/Services/ConditionalElseIfTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using eAuthor.Services.Expressions;
44
using eAuthor.Services.Impl;
55

6-
namespace eAuthor.API.Tests;
6+
namespace eAuthor.API.Tests.Services;
77

88
public class ConditionalElseIfTests
99
{

tests/eAuthor.API.Tests/ConditionalProcessorTests.cs renamed to tests/eAuthor.API.Tests/Services/ConditionalProcessorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using eAuthor.Services.Expressions;
44
using NUnit.Framework;
55

6-
namespace eAuthor.API.Tests;
6+
namespace eAuthor.API.Tests.Services;
77

88
public class ConditionalProcessorTests
99
{

tests/eAuthor.API.Tests/DocumentGenerationTests.cs renamed to tests/eAuthor.API.Tests/Services/DocumentGenerationTests.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using eAuthor.Services.Impl;
1212
using NUnit.Framework;
1313

14-
namespace eAuthor.API.Tests
14+
namespace eAuthor.API.Tests.Services
1515
{
1616
[TestFixture]
1717
public class DocumentGenerationTests
@@ -238,13 +238,9 @@ public void ExpressionEvaluator_ArrayIndexIfSupported_OtherwiseInconclusive()
238238
var exprIndex = _parser.Parse("/Data/Items[1]/Value");
239239
var el = _evaluator.ResolvePath(json, exprIndex.DataPath);
240240
if (el?.ValueKind == JsonValueKind.String)
241-
{
242241
Assert.That(el?.GetString(), Is.EqualTo("B"));
243-
}
244242
else
245-
{
246243
Assert.Inconclusive("Array index parse returned non-string element; parser may not support indexing.");
247-
}
248244
}
249245
catch (Exception ex)
250246
{

tests/eAuthor.API.Tests/ExpressionEvaluatorTests.cs renamed to tests/eAuthor.API.Tests/Services/ExpressionEvaluatorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using NUnit.Framework;
33
using System.Text.Json;
44

5-
namespace eAuthor.API.Tests;
5+
namespace eAuthor.API.Tests.Services;
66

77
public class ExpressionEvaluatorTests
88
{

0 commit comments

Comments
 (0)