Skip to content

Commit 00eaee0

Browse files
committed
Switch to memory storage for improved resilience
1 parent b01a8bc commit 00eaee0

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/Tests/ConversationStorageTests.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
namespace Devlooped.WhatsApp;
22

3+
class TestConversationStorage : ConversationStorage
4+
{
5+
public TestConversationStorage(CloudStorageAccount storage) : base(storage) { }
6+
7+
protected override IDocumentRepository<IMessage> CreateMessagesRepository()
8+
=> new MemoryRepository<IMessage>("WhatsAppMessages", x => x.UserNumber, x => x.Id);
9+
protected override ITableStorage<Conversation> CreateConversationsRepository()
10+
=> new MemoryRepository<Conversation>("WhatsAppConversations");
11+
protected override IDocumentRepository<Conversation> CreateActiveConversationRepository()
12+
=> new MemoryRepository<Conversation>("WhatsAppActiveConversations", partitionKey: null, rowKey: _ => "active");
13+
}
14+
315
public class ConversationStorageTests
416
{
517
readonly static Service service = new("1234", "1234");
@@ -8,12 +20,7 @@ public class ConversationStorageTests
820
[Fact]
921
public async Task StoreAndLoadAdditionalProperties()
1022
{
11-
CloudStorageAccount.DevelopmentStorageAccount.CreateTableServiceClient()
12-
.CreateTableIfNotExists("WhatsAppMessages");
13-
CloudStorageAccount.DevelopmentStorageAccount.CreateTableServiceClient()
14-
.CreateTableIfNotExists("WhatsAppConversations");
15-
16-
var storage = new ConversationStorage(CloudStorageAccount.DevelopmentStorageAccount);
23+
var storage = new TestConversationStorage(CloudStorageAccount.DevelopmentStorageAccount);
1724
var messageId = Ulid.NewUlid().ToString();
1825
var conversationId = Ulid.NewUlid().ToString();
1926

src/Tests/IntegrationTests.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,10 @@ public async Task RunConversationAsync()
3333
{ "Meta:Numbers:1234567890", "test-access-token" }
3434
})
3535
.Build();
36-
var services = new ServiceCollection()
37-
.AddSingleton(CloudStorageAccount.DevelopmentStorageAccount)
38-
.AddSingleton<IConfiguration>(configuration);
3936

40-
CloudStorageAccount.DevelopmentStorageAccount.CreateTableServiceClient()
41-
.CreateTableIfNotExists("WhatsAppMessages");
42-
CloudStorageAccount.DevelopmentStorageAccount.CreateTableServiceClient()
43-
.CreateTableIfNotExists("WhatsAppConversations");
37+
var services = new ServiceCollection()
38+
.AddSingleton<IConfiguration>(configuration)
39+
.AddSingleton<IConversationStorage>(new TestConversationStorage(CloudStorageAccount.DevelopmentStorageAccount));
4440

4541
IEnumerable<IMessage>? messages = null;
4642

src/Tests/Tests.csproj

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

1313
<ItemGroup>
1414
<PackageReference Include="coverlet.collector" Version="6.0.4" />
15-
<PackageReference Include="Devlooped.TableStorage.Memory" Version="5.3.1" />
15+
<PackageReference Include="Devlooped.TableStorage.Memory" Version="5.4.0" />
1616
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />
1717
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.13.0" />
1818
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.7" />
@@ -42,7 +42,7 @@
4242

4343
<ItemGroup>
4444
<Content Include="Content\**\*.*" CopyToOutputDirectory="PreserveNewest" />
45-
<ProjectProperty Include="BundledNETCoreAppPackageVersion"/>
45+
<ProjectProperty Include="BundledNETCoreAppPackageVersion" />
4646
</ItemGroup>
4747

4848
</Project>

0 commit comments

Comments
 (0)