Skip to content

Commit 61746ef

Browse files
committed
fix(connectors): sweep of fixes across providers
1 parent 977352b commit 61746ef

28 files changed

+1512
-1183
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<img src="https://github.com/engineering87/SharpConnector/blob/main/sharpconnector_logo.jpg" width="300">
1111

12-
SharpConnector is a .NET library designed to streamline integration with NoSQL databases. It provides a unified interface that simplifies database operations, eliminating the need to develop custom logic for each specific database connector. Since each NoSQL database has its own unique characteristicssuch as being document-oriented or key-value-basedSharpConnector abstracts these differences, providing a consistent and simplified access layer to accelerate development.
12+
SharpConnector is a .NET library designed to streamline integration with NoSQL databases. It provides a unified interface that simplifies database operations, eliminating the need to develop custom logic for each specific database connector. Since each NoSQL database has its own unique characteristics, such as being document-oriented or key-value-based, SharpConnector abstracts these differences, providing a consistent and simplified access layer to accelerate development.
1313

1414
## Features
1515

@@ -169,7 +169,7 @@ If you want to add new connectors, please follow these three rules:
169169
* [Fork the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo)
170170
* [Open an issue](https://github.com/engineering87/SharpConnector/issues) if you encounter a bug or have a suggestion for improvements/features
171171

172-
### Licensee
172+
### License
173173
SharpConnector source code is available under MIT License, see license in the source.
174174

175175
#### External References

src/SharpConnector.Tests/ConnectorTests.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Moq;
55
using SharpConnector.Interfaces;
66
using System.Collections.Generic;
7+
using System.Threading;
78
using System.Threading.Tasks;
89

910
namespace SharpConnector.Tests
@@ -18,17 +19,25 @@ public ConnectorTests()
1819
{
1920
_mockClient = new Mock<ISharpConnectorClient<string>>();
2021

22+
// Sync setups (nessun token qui)
2123
_mockClient.Setup(client => client.Insert(It.IsAny<string>(), It.IsAny<string>()))
2224
.Returns(true);
2325

24-
_mockClient.Setup(client => client.InsertAsync(It.IsAny<string>(), It.IsAny<string>()))
25-
.ReturnsAsync(true);
26-
2726
_mockClient.Setup(client => client.Get(It.IsAny<string>()))
2827
.Returns((string key) => key == "testKey" ? "payload" : null);
2928

30-
_mockClient.Setup(client => client.GetAsync(It.IsAny<string>()))
31-
.ReturnsAsync((string key) => key == "testKey" ? "payload" : null);
29+
// Async setups: SPECIFICA SEMPRE IL CancellationToken
30+
_mockClient.Setup(client => client.InsertAsync(
31+
It.IsAny<string>(),
32+
It.IsAny<string>(),
33+
It.IsAny<CancellationToken>()))
34+
.ReturnsAsync(true);
35+
36+
_mockClient.Setup(client => client.GetAsync(
37+
It.IsAny<string>(),
38+
It.IsAny<CancellationToken>()))
39+
.ReturnsAsync((string key, CancellationToken _) =>
40+
key == "testKey" ? "payload" : null);
3241

3342
_sharpConnectorClient = _mockClient.Object;
3443
}
@@ -72,7 +81,7 @@ public void Get()
7281
var insert = _sharpConnectorClient.Insert(key, "payload");
7382
Assert.IsTrue(insert);
7483
var obj = _sharpConnectorClient.Get(key);
75-
Assert.AreEqual(obj, "payload");
84+
Assert.AreEqual("payload", obj);
7685
}
7786

7887
[TestMethod]
@@ -82,7 +91,7 @@ public async Task GetAsync()
8291
var insert = _sharpConnectorClient.Insert(key, "payload");
8392
Assert.IsTrue(insert);
8493
var obj = await _sharpConnectorClient.GetAsync(key);
85-
Assert.AreEqual(obj, "payload");
94+
Assert.AreEqual("payload", obj);
8695
}
8796

8897
[TestMethod]
@@ -92,9 +101,8 @@ public void Update()
92101
var insert = _sharpConnectorClient.Insert(key, "payload");
93102
Assert.IsTrue(insert);
94103
var obj = _sharpConnectorClient.Get(key);
95-
Assert.AreEqual(obj, "payload");
104+
Assert.AreEqual("payload", obj);
96105

97-
// Set up mock for update method
98106
_mockClient.Setup(client => client.Update(key, "modPayload")).Returns(true);
99107
var update = _sharpConnectorClient.Update(key, "modPayload");
100108
Assert.IsTrue(update);
@@ -107,10 +115,14 @@ public async Task UpdateAsync()
107115
var insert = await _sharpConnectorClient.InsertAsync(key, "payload");
108116
Assert.IsTrue(insert);
109117
var obj = await _sharpConnectorClient.GetAsync(key);
110-
Assert.AreEqual(obj, "payload");
118+
Assert.AreEqual("payload", obj);
119+
120+
_mockClient.Setup(client => client.UpdateAsync(
121+
key,
122+
"modPayload",
123+
It.IsAny<CancellationToken>()))
124+
.ReturnsAsync(true);
111125

112-
// Mock async update behavior
113-
_mockClient.Setup(client => client.UpdateAsync(key, "modPayload")).ReturnsAsync(true);
114126
var update = await _sharpConnectorClient.UpdateAsync(key, "modPayload");
115127
Assert.IsTrue(update);
116128
}
@@ -122,9 +134,8 @@ public void Delete()
122134
var insert = _sharpConnectorClient.Insert(key, "payload");
123135
Assert.IsTrue(insert);
124136
var obj = _sharpConnectorClient.Get(key);
125-
Assert.AreEqual(obj, "payload");
137+
Assert.AreEqual("payload", obj);
126138

127-
// Mock delete behavior
128139
_mockClient.Setup(client => client.Delete(key)).Returns(true);
129140
var delete = _sharpConnectorClient.Delete(key);
130141
Assert.IsTrue(delete);
@@ -137,12 +148,15 @@ public async Task DeleteAsync()
137148
var insert = await _sharpConnectorClient.InsertAsync(key, "payload");
138149
Assert.IsTrue(insert);
139150
var obj = await _sharpConnectorClient.GetAsync(key);
140-
Assert.AreEqual(obj, "payload");
151+
Assert.AreEqual("payload", obj);
152+
153+
_mockClient.Setup(client => client.DeleteAsync(
154+
key,
155+
It.IsAny<CancellationToken>()))
156+
.ReturnsAsync(true);
141157

142-
// Mock async delete behavior
143-
_mockClient.Setup(client => client.DeleteAsync(key)).ReturnsAsync(true);
144158
var delete = await _sharpConnectorClient.DeleteAsync(key);
145159
Assert.IsTrue(delete);
146160
}
147161
}
148-
}
162+
}

src/SharpConnector.Tests/SharpConnector.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
<ItemGroup>
2828
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
2929
<PackageReference Include="Moq" Version="4.20.72" />
30-
<PackageReference Include="MSTest.TestAdapter" Version="3.10.0" />
31-
<PackageReference Include="MSTest.TestFramework" Version="3.10.0" />
30+
<PackageReference Include="MSTest.TestAdapter" Version="3.10.2" />
31+
<PackageReference Include="MSTest.TestFramework" Version="3.10.2" />
3232
<PackageReference Include="coverlet.collector" Version="6.0.4">
3333
<PrivateAssets>all</PrivateAssets>
3434
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

0 commit comments

Comments
 (0)