Skip to content

Commit 26579b2

Browse files
committed
feat: using dtm common package
1 parent f79f14f commit 26579b2

25 files changed

+81
-617
lines changed

src/Dtmcli.Tests/BranchBarrierTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using Microsoft.Extensions.Primitives;
1010
using Microsoft.Extensions.Logging.Abstractions;
1111
using Microsoft.Extensions.DependencyInjection;
12-
using Dtmcli.DtmImp;
12+
using DtmCommon;
1313

1414
namespace Dtmcli.Tests
1515
{
@@ -57,7 +57,7 @@ public void CreateBranchBarrier_FromQs_Should_ThrowException()
5757

5858
var qs = new Microsoft.AspNetCore.Http.QueryCollection(dict);
5959

60-
Assert.Throws<DtmcliException>(() => _factory.CreateBranchBarrier(qs));
60+
Assert.Throws<DtmException>(() => _factory.CreateBranchBarrier(qs));
6161
}
6262
#endif
6363

@@ -174,7 +174,7 @@ public async void Call_Should_Throw_Duplicated_Exception_When_QueryPrepared_At_F
174174
var mockBusiCall = new Mock<Func<System.Data.Common.DbTransaction, Task<bool>>>();
175175

176176
// Call later
177-
var ex = await Assert.ThrowsAsync<DtmcliException>(async () => await branchBarrier.Call(connC, mockBusiCall.Object));
177+
var ex = await Assert.ThrowsAsync<DtmDuplicatedException>(async () => await branchBarrier.Call(connC, mockBusiCall.Object));
178178
Assert.Equal(Constant.ResultDuplicated, ex.Message);
179179
mockBusiCall.Verify(x => x.Invoke(It.IsAny<System.Data.Common.DbTransaction>()), Times.Never);
180180
}

src/Dtmcli.Tests/BranchIDGenTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Dtmcli.DtmImp;
1+
using DtmCommon;
22
using System;
33
using Xunit;
44

src/Dtmcli.Tests/DbSpecialTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Dtmcli.DtmImp;
1+
using DtmCommon;
22
using Microsoft.Extensions.DependencyInjection;
33
using Xunit;
44

@@ -42,15 +42,15 @@ public void Test_MsSQL_DbSpecial()
4242

4343
Assert.IsType<SqlServerDBSpecial>(special);
4444
Assert.Equal("insert into a(f) values(@f)", special.GetInsertIgnoreTemplate("a(f) values(@f)", "c"));
45-
Assert.Throws<DtmcliException>(() => special.GetXaSQL("", ""));
45+
Assert.Throws<DtmException>(() => special.GetXaSQL("", ""));
4646
}
4747

4848
[Fact]
4949
public void Test_Other_DbSpecial()
5050
{
5151
var provider = TestHelper.AddDtmCli(db: "other");
5252

53-
var ex = Assert.Throws<DtmcliException>(() => provider.GetRequiredService<DbSpecialDelegate>());
53+
var ex = Assert.Throws<DtmException>(() => provider.GetRequiredService<DbSpecialDelegate>());
5454
Assert.Equal("unknown db type 'other'", ex.Message);
5555
}
5656
}

src/Dtmcli.Tests/MsgTests.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Apps72.Dev.Data.DbMocker;
2+
using DtmCommon;
23
using Microsoft.Extensions.DependencyInjection;
34
using Moq;
45
using System;
@@ -75,7 +76,7 @@ public async void DoAndSubmitDB_Should_Throw_Exception_When_Transbase_InValid()
7576

7677
var db = new MockDbConnection();
7778

78-
await Assert.ThrowsAsync<DtmcliException>(async () => await msg.DoAndSubmitDB(busi + "/query", db, x => Task.FromResult<bool>(true)));
79+
await Assert.ThrowsAsync<DtmException>(async () => await msg.DoAndSubmitDB(busi + "/query", db, x => Task.FromResult<bool>(true)));
7980
}
8081

8182
[Fact]
@@ -94,9 +95,8 @@ public async void DoAndSubmitDB_Should_Not_Call_Barrier_When_Prepare_Fail()
9495
var db = new MockDbConnection();
9596
var mockBusiCall = new Mock<Func<DbTransaction, Task<bool>>>();
9697

97-
var res = await msg.DoAndSubmitDB(busi + "/query", db, x => Task.FromResult(true));
98+
await msg.DoAndSubmitDB(busi + "/query", db, x => Task.FromResult(true));
9899

99-
Assert.False(res);
100100
mockBusiCall.Verify(x => x.Invoke(It.IsAny<DbTransaction>()), Times.Never);
101101
}
102102

@@ -121,9 +121,8 @@ public async void DoAndSubmitDB_Should_Succeed()
121121
var mockBusiCall = new Mock<Func<DbTransaction, Task<bool>>>();
122122
mockBusiCall.Setup(x => x.Invoke(It.IsAny<DbTransaction>())).Returns(Task.FromResult(true));
123123

124-
var res = await msg.DoAndSubmitDB(busi + "/query", db, mockBusiCall.Object);
124+
await msg.DoAndSubmitDB(busi + "/query", db, mockBusiCall.Object);
125125

126-
Assert.True(res);
127126
mockBusiCall.Verify(x => x.Invoke(It.IsAny<DbTransaction>()), Times.Once);
128127
}
129128

@@ -148,10 +147,9 @@ public async void DoAndSubmitDB_Should_Abort_When_BusiCall_ThrowExeption_With_Re
148147
var mockBusiCall = new Mock<Func<DbTransaction, Task>>();
149148
mockBusiCall.Setup(x => x.Invoke(It.IsAny<DbTransaction>())).Throws(new Exception(Constant.ResultFailure));
150149

151-
var res = await msg.DoAndSubmitDB(busi + "/query", db, mockBusiCall.Object);
150+
await msg.DoAndSubmitDB(busi + "/query", db, mockBusiCall.Object);
152151

153-
Assert.False(res);
154-
dtmClient.Verify(x => x.TransCallDtm(It.IsAny<DtmImp.TransBase>(), It.IsAny<object>(), Constant.Request.OPERATION_ABORT, It.IsAny<CancellationToken>()), Times.Once);
152+
dtmClient.Verify(x => x.TransCallDtm(It.IsAny<TransBase>(), It.IsAny<object>(), Constant.Request.OPERATION_ABORT, It.IsAny<CancellationToken>()), Times.Once);
155153
}
156154

157155
[Fact]
@@ -177,10 +175,9 @@ public async void DoAndSubmitDB_Should_QueryPrepared_When_BusiCall_ThrowExeption
177175
var mockBusiCall = new Mock<Func<DbTransaction, Task<bool>>>();
178176
mockBusiCall.Setup(x => x.Invoke(It.IsAny<DbTransaction>())).Throws(new Exception("ex"));
179177

180-
var res = await msg.DoAndSubmitDB(busi + "/query", db, mockBusiCall.Object);
178+
await msg.DoAndSubmitDB(busi + "/query", db, mockBusiCall.Object);
181179

182-
Assert.False(res);
183-
dtmClient.Verify(x => x.TransRequestBranch(It.IsAny<DtmImp.TransBase>(), It.IsAny<HttpMethod>(), It.IsAny<object>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()), Times.Once);
180+
dtmClient.Verify(x => x.TransRequestBranch(It.IsAny<TransBase>(), It.IsAny<HttpMethod>(), It.IsAny<object>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()), Times.Once);
184181
}
185182

186183
public class MsgMockHttpMessageHandler : DelegatingHandler
@@ -193,7 +190,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
193190
{
194191
var str = await request.Content?.ReadAsStringAsync() ?? "";
195192

196-
var transBase = System.Text.Json.JsonSerializer.Deserialize<DtmImp.TransBase>(str);
193+
var transBase = System.Text.Json.JsonSerializer.Deserialize<TransBase>(str);
197194

198195
Assert.Equal("TestMsgNormal", transBase.Gid);
199196
Assert.Equal("msg", transBase.TransType);

src/Dtmcli.Tests/SagaTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Moq;
1+
using DtmCommon;
2+
using Moq;
23
using System.Collections.Generic;
34
using System.Net.Http;
45
using System.Threading;
@@ -57,7 +58,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
5758
{
5859
var str = await request.Content?.ReadAsStringAsync() ?? "";
5960

60-
var transBase = System.Text.Json.JsonSerializer.Deserialize<DtmImp.TransBase>(str);
61+
var transBase = System.Text.Json.JsonSerializer.Deserialize<TransBase>(str);
6162

6263
/*
6364
{

src/Dtmcli.Tests/ServiceCollectionExtensionsTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Extensions.Configuration;
1+
using DtmCommon;
2+
using Microsoft.Extensions.Configuration;
23
using Microsoft.Extensions.DependencyInjection;
34
using Microsoft.Extensions.Options;
45
using System.Collections.Generic;

src/Dtmcli.Tests/TccTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Net.Http;
33
using System.Threading;
44
using System.Threading.Tasks;
5+
using DtmCommon;
56
using Microsoft.Extensions.Logging.Abstractions;
67
using Moq;
78
using Xunit;
@@ -47,7 +48,7 @@ public async void Execute_Should_Abort_When_CallBranch_With_Old_Ver_Exception()
4748
});
4849

4950
Assert.Empty(res);
50-
dtmClient.Verify(x => x.TransCallDtm(It.IsAny<DtmImp.TransBase>(), It.IsAny<object>(), Constant.Request.OPERATION_ABORT, It.IsAny<CancellationToken>()), Times.Once);
51+
dtmClient.Verify(x => x.TransCallDtm(It.IsAny<TransBase>(), It.IsAny<object>(), Constant.Request.OPERATION_ABORT, It.IsAny<CancellationToken>()), Times.Once);
5152
}
5253

5354
[Fact]
@@ -68,7 +69,7 @@ public async void Execute_Should_Abort_When_CallBranch_With_New_Ver_Exception()
6869
});
6970

7071
Assert.Empty(res);
71-
dtmClient.Verify(x => x.TransCallDtm(It.IsAny<DtmImp.TransBase>(), It.IsAny<object>(), Constant.Request.OPERATION_ABORT, It.IsAny<CancellationToken>()), Times.Once);
72+
dtmClient.Verify(x => x.TransCallDtm(It.IsAny<TransBase>(), It.IsAny<object>(), Constant.Request.OPERATION_ABORT, It.IsAny<CancellationToken>()), Times.Once);
7273
}
7374

7475
[Fact]

src/Dtmcli.Tests/TestHelper.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Net.Http;
33
using System.Threading;
44
using System.Threading.Tasks;
5+
using DtmCommon;
56
using Microsoft.Extensions.DependencyInjection;
67
using Moq;
78

@@ -12,14 +13,14 @@ public class TestHelper
1213
public static void MockTransCallDtm(Mock<IDtmClient> mock, string op, bool result)
1314
{
1415
mock
15-
.Setup(x => x.TransCallDtm(It.IsAny<DtmImp.TransBase>(), It.IsAny<object>(), op, It.IsAny<CancellationToken>()))
16+
.Setup(x => x.TransCallDtm(It.IsAny<TransBase>(), It.IsAny<object>(), op, It.IsAny<CancellationToken>()))
1617
.Returns(Task.FromResult(result));
1718
}
1819

1920
public static void MockTransRegisterBranch(Mock<IDtmClient> mock, string op, bool result)
2021
{
2122
mock
22-
.Setup(x => x.TransRegisterBranch(It.IsAny<DtmImp.TransBase>(), It.IsAny<Dictionary<string, string>>(), op, It.IsAny<CancellationToken>()))
23+
.Setup(x => x.TransRegisterBranch(It.IsAny<TransBase>(), It.IsAny<Dictionary<string, string>>(), op, It.IsAny<CancellationToken>()))
2324
.Returns(Task.FromResult(result));
2425
}
2526

@@ -29,7 +30,7 @@ public static void MockTransRequestBranch(Mock<IDtmClient> mock, System.Net.Http
2930
httpRspMsg.Content = new StringContent(content);
3031

3132
mock
32-
.Setup(x => x.TransRequestBranch(It.IsAny<DtmImp.TransBase>(), It.IsAny<HttpMethod>(), It.IsAny<object>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
33+
.Setup(x => x.TransRequestBranch(It.IsAny<TransBase>(), It.IsAny<HttpMethod>(), It.IsAny<object>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
3334
.Returns(Task.FromResult(httpRspMsg));
3435
}
3536

0 commit comments

Comments
 (0)