Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/KeyValueRepositoryTests.cs
Paul Johnson 00133e880d Move test projects from src/ to tests/ (#11357)
* Update gitignore

* Move csproj

* Update project references

* Update solutions

* Update build scripts

* Tests used to share editorconfig with projects in src

* Fix broken tests.

* Stop copying around .editorconfig

merged root one with linting

* csharp_style_expression_bodied -> suggestion

* Move StyleCop rulesets to matching directories and update shared build properties

* Remove legacy build files, update NuGet.cofig and solution files

* Restore myget source

* Clean up .gitignore

* Update .gitignore

* Move new test classes to tests after merge

* Gitignore + nuget config

* Move new test

Co-authored-by: Ronald Barendse <ronald@barend.se>
2021-10-18 08:14:04 +01:00

74 lines
2.5 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories
{
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class KeyValueRepositoryTests : UmbracoIntegrationTest
{
[Test]
public void CanSetAndGet()
{
IScopeProvider provider = ScopeProvider;
// Insert new key/value
using (IScope scope = provider.CreateScope())
{
var keyValue = new KeyValue
{
Identifier = "foo",
Value = "bar",
UpdateDate = DateTime.Now,
};
IKeyValueRepository repo = CreateRepository(provider);
repo.Save(keyValue);
scope.Complete();
}
// Retrieve key/value
using (IScope scope = provider.CreateScope())
{
IKeyValueRepository repo = CreateRepository(provider);
IKeyValue keyValue = repo.Get("foo");
scope.Complete();
Assert.AreEqual("bar", keyValue.Value);
}
// Update value
using (IScope scope = provider.CreateScope())
{
IKeyValueRepository repo = CreateRepository(provider);
IKeyValue keyValue = repo.Get("foo");
keyValue.Value = "buzz";
keyValue.UpdateDate = DateTime.Now;
repo.Save(keyValue);
scope.Complete();
}
// Retrieve key/value again
using (IScope scope = provider.CreateScope())
{
IKeyValueRepository repo = CreateRepository(provider);
IKeyValue keyValue = repo.Get("foo");
scope.Complete();
Assert.AreEqual("buzz", keyValue.Value);
}
}
private IKeyValueRepository CreateRepository(IScopeProvider provider) => new KeyValueRepository((IScopeAccessor)provider, LoggerFactory.CreateLogger<KeyValueRepository>());
}
}