Added unit tests for new KeyValueRepository.

This commit is contained in:
Andy Butland
2020-02-15 12:17:48 +01:00
parent ac91b9ef5e
commit f92b43260a
2 changed files with 62 additions and 0 deletions
@@ -0,0 +1,61 @@
using NUnit.Framework;
using Umbraco.Core.Persistence.Repositories.Implement;
using Umbraco.Core.Scoping;
using Umbraco.Infrastructure.Persistence.Repositories;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
namespace Umbraco.Tests.Persistence.Repositories
{
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class KeyValueRepositoryTests : TestWithDatabaseBase
{
[Test]
public void CanSetAndGet()
{
var provider = TestObjects.GetScopeProvider(Logger);
// Insert new key/value
using (var scope = provider.CreateScope())
{
var repo = CreateRepository(provider);
repo.SetValue("foo", "bar");
scope.Complete();
}
// Retrieve key/value
using (var scope = provider.CreateScope())
{
var repo = CreateRepository(provider);
var value = repo.GetValue("foo");
scope.Complete();
Assert.AreEqual("bar", value);
}
// Update new key/value
using (var scope = provider.CreateScope())
{
var repo = CreateRepository(provider);
repo.SetValue("foo", "buzz");
scope.Complete();
}
// Retrieve key/value again
using (var scope = provider.CreateScope())
{
var repo = CreateRepository(provider);
var value = repo.GetValue("foo");
scope.Complete();
Assert.AreEqual("buzz", value);
}
}
private IKeyValueRepository CreateRepository(IScopeProvider provider)
{
return new KeyValueRepository((IScopeAccessor) provider, Logger);
}
}
}
+1
View File
@@ -148,6 +148,7 @@
<Compile Include="Persistence\Mappers\MapperTestBase.cs" />
<Compile Include="Persistence\Repositories\DocumentRepositoryTest.cs" />
<Compile Include="Persistence\Repositories\EntityRepositoryTest.cs" />
<Compile Include="Persistence\Repositories\KeyValueRepositoryTests.cs" />
<Compile Include="UmbracoExamine\ExamineExtensions.cs" />
<Compile Include="PublishedContent\NuCacheChildrenTests.cs" />
<Compile Include="PublishedContent\PublishedContentLanguageVariantTests.cs" />