Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Jan 8, 2025
1 parent 26f0abb commit 8573033
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
1 change: 1 addition & 0 deletions tests/Speckle.Sdk.Tests.Unit/Credentials/Accounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public CredentialInfrastructure()

public void Dispose()
{
_accountManager.Dispose();
Fixtures.DeleteLocalAccount(s_testAccount1.id);
Fixtures.DeleteLocalAccount(s_testAccount2.id);
Fixtures.DeleteLocalAccount(s_testAccount3.id);
Expand Down
53 changes: 25 additions & 28 deletions tests/Speckle.Sdk.Tests.Unit/SQLite/SQLiteJsonCacheManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
using Microsoft.Data.Sqlite;
using NUnit.Framework;
using Shouldly;
using FluentAssertions;
using Microsoft.Data.Sqlite;
using Speckle.Sdk.Common;
using Speckle.Sdk.SQLite;
using Xunit;

namespace Speckle.Sdk.Tests.Unit.SQLite;

[TestFixture]
public class SQLiteJsonCacheManagerTests
public class SQLiteJsonCacheManagerTests : IDisposable
{
private readonly string _basePath = $"{Guid.NewGuid()}.db";
private string? _connectionString;
private readonly string? _connectionString;

[SetUp]
public void Setup() => _connectionString = $"Data Source={_basePath};";
public SQLiteJsonCacheManagerTests() => _connectionString = $"Data Source={_basePath};";

[TearDown]
public void TearDown()
public void Dispose()
{
if (File.Exists(_basePath))
{
Expand All @@ -27,23 +24,23 @@ public void TearDown()
}
}

[Test]
[Fact]
public void TestGetAll()
{
var data = new List<(string id, string json)>() { ("id1", "1"), ("id2", "2") };
using var manager = new SqLiteJsonCacheManager(_connectionString.NotNull(), 2);
manager.SaveObjects(data);
var items = manager.GetAllObjects();
items.Count.ShouldBe(data.Count);
items.Count.Should().Be(data.Count);
var i = items.ToDictionary();
foreach (var (id, json) in data)
{
i.TryGetValue(id, out var j).ShouldBeTrue();
j.ShouldBe(json);
i.TryGetValue(id, out var j).Should().BeTrue();
j.Should().Be(json);
}
}

[Test]
[Fact]
public void TestGet()
{
var data = new List<(string id, string json)>() { ("id1", "1"), ("id2", "2") };
Expand All @@ -57,35 +54,35 @@ public void TestGet()
manager.SaveObject(d.id, d.json);
}
var items = manager.GetAllObjects();
items.Count.ShouldBe(data.Count);
items.Count.Should().Be(data.Count);

var id1 = data[0].id;
var json1 = manager.GetObject(id1);
json1.ShouldBe(data[0].json);
manager.HasObject(id1).ShouldBeTrue();
json1.Should().Be(data[0].json);
manager.HasObject(id1).Should().BeTrue();

manager.UpdateObject(id1, "3");
json1 = manager.GetObject(id1);
json1.ShouldBe("3");
manager.HasObject(id1).ShouldBeTrue();
json1.Should().Be("3");
manager.HasObject(id1).Should().BeTrue();

manager.DeleteObject(id1);
json1 = manager.GetObject(id1);
json1.ShouldBeNull();
manager.HasObject(id1).ShouldBeFalse();
json1.Should().BeNull();
manager.HasObject(id1).Should().BeFalse();

manager.UpdateObject(id1, "3");
json1 = manager.GetObject(id1);
json1.ShouldBe("3");
manager.HasObject(id1).ShouldBeTrue();
json1.Should().Be("3");
manager.HasObject(id1).Should().BeTrue();

var id2 = data[1].id;
var json2 = manager.GetObject(id2);
json2.ShouldBe(data[1].json);
manager.HasObject(id2).ShouldBeTrue();
json2.Should().Be(data[1].json);
manager.HasObject(id2).Should().BeTrue();
manager.DeleteObject(id2);
json2 = manager.GetObject(id2);
json2.ShouldBeNull();
manager.HasObject(id2).ShouldBeFalse();
json2.Should().BeNull();
manager.HasObject(id2).Should().BeFalse();
}
}
3 changes: 2 additions & 1 deletion tests/Speckle.Sdk.Tests.Unit/Serialisation/BatchTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentAssertions;
using Speckle.Sdk.Dependencies;
using Speckle.Sdk.Serialisation.V2.Send;
using Xunit;

Expand Down Expand Up @@ -34,7 +35,7 @@ public void TestBatchSize_Trim()
batch.Add(new BatchItem(2));
batch.Size.Should().Be(3);

batch.Items.Capacity.ShouldBe(Pools.DefaultCapacity);
batch.Items.Capacity.Should().Be(Pools.DefaultCapacity);
batch.TrimExcess();

batch.Items.Capacity.Should().Be(2);
Expand Down

0 comments on commit 8573033

Please sign in to comment.