elsa-core/test/unit/Elsa.MongoDb.UnitTests/MongoKeyValueStoreTests.cs
Sipke Schoorstra dd812645c7 Refactor imports to reduce use of Elsa.Common.Contracts
Consolidate imports by replacing Elsa.Common.Contracts with Elsa.Common and Elsa.Common.Multitenancy. This update streamlines import statements across various modules, improving code readability and maintainability.
2024-10-05 18:30:45 +02:00

38 lines
1.4 KiB
C#

using Elsa.Common.Multitenancy;
using Elsa.KeyValues.Entities;
using Elsa.MongoDb.Common;
using Elsa.MongoDb.Modules.Runtime;
using MongoDB.Driver;
using NSubstitute;
namespace Elsa.MongoDb.UnitTests;
public class MongoKeyValueStoreTests
{
private readonly MongoDbStore<SerializedKeyValuePair> _mongoDbStore;
public MongoKeyValueStoreTests()
{
var mongoCollectionMock = Substitute.For<IMongoCollection<SerializedKeyValuePair>>();
var tenantResolverMock = Substitute.For<ITenantResolver>();
mongoCollectionMock.FindOneAndReplaceAsync(
Arg.Any<FilterDefinition<SerializedKeyValuePair>>(),
Arg.Any<SerializedKeyValuePair>(),
Arg.Any<FindOneAndReplaceOptions<SerializedKeyValuePair>>()
)
.Returns(new SerializedKeyValuePair());
_mongoDbStore = new MongoDbStore<SerializedKeyValuePair>(mongoCollectionMock, tenantResolverMock);
}
[Fact(DisplayName = "When saving a SerializedKeyValuePair document, don't throw an exception of missing ID property")]
public async Task SaveAsync_WithSerializedKeyValuePairDocument_DoesNotThrowException()
{
var mongoKeyValueStore = new MongoKeyValueStore(_mongoDbStore);
var keyValuePair = new SerializedKeyValuePair();
var exception = await Record.ExceptionAsync(
async () => await mongoKeyValueStore.SaveAsync(keyValuePair, default));
Assert.Null(exception);
}
}