V10: fix build warnings in test projects (#12509)
* Run code cleanup * Dotnet format benchmarks project * Fix up Test.Common * Run dotnet format + manual cleanup * Run code cleanup for unit tests * Run dotnet format * Fix up errors * Manual cleanup of Unit test project * Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix according to review * Fix after merge * Fix errors Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
@@ -1,106 +1,103 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Tests.Common.Testing;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Tests covering methods in the KeyValueService class.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class KeyValueServiceTests : UmbracoIntegrationTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests covering methods in the KeyValueService class.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class KeyValueServiceTests : UmbracoIntegrationTest
|
||||
private IKeyValueService KeyValueService => GetRequiredService<IKeyValueService>();
|
||||
|
||||
[Test]
|
||||
public void Can_Query_For_Key_Prefix()
|
||||
{
|
||||
private IKeyValueService KeyValueService => GetRequiredService<IKeyValueService>();
|
||||
// Arrange
|
||||
KeyValueService.SetValue("test1", "hello1");
|
||||
KeyValueService.SetValue("test2", "hello2");
|
||||
KeyValueService.SetValue("test3", "hello3");
|
||||
KeyValueService.SetValue("test4", "hello4");
|
||||
KeyValueService.SetValue("someotherprefix1", "helloagain1");
|
||||
// Act
|
||||
var value = KeyValueService.FindByKeyPrefix("test");
|
||||
|
||||
[Test]
|
||||
public void Can_Query_For_Key_Prefix()
|
||||
{
|
||||
// Arrange
|
||||
KeyValueService.SetValue("test1", "hello1");
|
||||
KeyValueService.SetValue("test2", "hello2");
|
||||
KeyValueService.SetValue("test3", "hello3");
|
||||
KeyValueService.SetValue("test4", "hello4");
|
||||
KeyValueService.SetValue("someotherprefix1", "helloagain1");
|
||||
// Act
|
||||
IReadOnlyDictionary<string, string> value = KeyValueService.FindByKeyPrefix("test");
|
||||
// Assert
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(4, value.Count);
|
||||
Assert.AreEqual("hello1", value["test1"]);
|
||||
Assert.AreEqual("hello2", value["test2"]);
|
||||
Assert.AreEqual("hello3", value["test3"]);
|
||||
Assert.AreEqual("hello4", value["test4"]);
|
||||
}
|
||||
|
||||
Assert.AreEqual(4, value.Count);
|
||||
Assert.AreEqual("hello1", value["test1"]);
|
||||
Assert.AreEqual("hello2", value["test2"]);
|
||||
Assert.AreEqual("hello3", value["test3"]);
|
||||
Assert.AreEqual("hello4", value["test4"]);
|
||||
}
|
||||
[Test]
|
||||
public void GetValue_ForMissingKey_ReturnsNull()
|
||||
{
|
||||
// Act
|
||||
var value = KeyValueService.GetValue("foo");
|
||||
|
||||
[Test]
|
||||
public void GetValue_ForMissingKey_ReturnsNull()
|
||||
{
|
||||
// Act
|
||||
string value = KeyValueService.GetValue("foo");
|
||||
// Assert
|
||||
Assert.IsNull(value);
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.IsNull(value);
|
||||
}
|
||||
[Test]
|
||||
public void GetValue_ForExistingKey_ReturnsValue()
|
||||
{
|
||||
KeyValueService.SetValue("foo", "bar");
|
||||
|
||||
[Test]
|
||||
public void GetValue_ForExistingKey_ReturnsValue()
|
||||
{
|
||||
KeyValueService.SetValue("foo", "bar");
|
||||
// Act
|
||||
var value = KeyValueService.GetValue("foo");
|
||||
|
||||
// Act
|
||||
string value = KeyValueService.GetValue("foo");
|
||||
// Assert
|
||||
Assert.AreEqual("bar", value);
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("bar", value);
|
||||
}
|
||||
[Test]
|
||||
public void SetValue_ForExistingKey_SavesValue()
|
||||
{
|
||||
KeyValueService.SetValue("foo", "bar");
|
||||
|
||||
[Test]
|
||||
public void SetValue_ForExistingKey_SavesValue()
|
||||
{
|
||||
KeyValueService.SetValue("foo", "bar");
|
||||
// Act
|
||||
KeyValueService.SetValue("foo", "buzz");
|
||||
var value = KeyValueService.GetValue("foo");
|
||||
|
||||
// Act
|
||||
KeyValueService.SetValue("foo", "buzz");
|
||||
string value = KeyValueService.GetValue("foo");
|
||||
// Assert
|
||||
Assert.AreEqual("buzz", value);
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("buzz", value);
|
||||
}
|
||||
[Test]
|
||||
public void TrySetValue_ForExistingKeyWithProvidedValue_ReturnsTrueAndSetsValue()
|
||||
{
|
||||
KeyValueService.SetValue("foo", "bar");
|
||||
|
||||
[Test]
|
||||
public void TrySetValue_ForExistingKeyWithProvidedValue_ReturnsTrueAndSetsValue()
|
||||
{
|
||||
KeyValueService.SetValue("foo", "bar");
|
||||
// Act
|
||||
var result = KeyValueService.TrySetValue("foo", "bar", "buzz");
|
||||
var value = KeyValueService.GetValue("foo");
|
||||
|
||||
// Act
|
||||
bool result = KeyValueService.TrySetValue("foo", "bar", "buzz");
|
||||
string value = KeyValueService.GetValue("foo");
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
Assert.AreEqual("buzz", value);
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
Assert.AreEqual("buzz", value);
|
||||
}
|
||||
[Test]
|
||||
public void TrySetValue_ForExistingKeyWithoutProvidedValue_ReturnsFalseAndDoesNotSetValue()
|
||||
{
|
||||
KeyValueService.SetValue("foo", "bar");
|
||||
|
||||
[Test]
|
||||
public void TrySetValue_ForExistingKeyWithoutProvidedValue_ReturnsFalseAndDoesNotSetValue()
|
||||
{
|
||||
KeyValueService.SetValue("foo", "bar");
|
||||
// Act
|
||||
var result = KeyValueService.TrySetValue("foo", "bang", "buzz");
|
||||
var value = KeyValueService.GetValue("foo");
|
||||
|
||||
// Act
|
||||
bool result = KeyValueService.TrySetValue("foo", "bang", "buzz");
|
||||
string value = KeyValueService.GetValue("foo");
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result);
|
||||
Assert.AreEqual("bar", value);
|
||||
}
|
||||
// Assert
|
||||
Assert.IsFalse(result);
|
||||
Assert.AreEqual("bar", value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user