Attempting to right unit testing using IScopeProvi...
# package-development
m
Attempting to right unit testing using IScopeProvider found this nice little class form HQ - https://github.com/umbraco/Umbraco-CMS/blob/64e7933d57bbd17c40138623a1a0b96de3a36160/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs Added the UmbracoTest Attribute - [UmbracoTest(Database = UmbracoTestOptions.Database.NewEmptyPerTest)] But getting:
System.ApplicationException : Unsupported test database provider
Shorten code sample:
Copy code
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewEmptyPerTest)]
public class CspServiceTests : UmbracoIntegrationTest
{
    [Test]
    [TestCase(false)]
    [TestCase(true)]
    public void GetCspDefinition_ReturnsDefaultDefinitionIfNoneIsStored(bool isBackOffice)
    {
        var _sud = new CspService(GetRequiredService<IEventAggregator>(),
            GetRequiredService<IHostingEnvironment>(),
            ScopeProvider,
            AppCaches);

        var definition = _sud.GetCspDefinition(isBackOffice);        
        definition.Should().NotBeNull();
        definition.IsBackOffice.Should().Be(isBackOffice);
        definition.Enabled.Should().BeFalse();
        definition.Id.Should().Be(isBackOffice ? CspConstants.DefaultBackofficeId : CspConstants.DefaultFrontEndId);
    }
}
b
m
When adding the nuget package as a dependency it adds a reference to a default one in the package, I am just trying a a tests.local.json one now
Looks like the GlobalSetupTeardown.TestConfiguration is null :S
Sorted!!! You need an
appsettings.Tests.json
file in your project having the linked one wont work. You also need a class with no namespace that inheirts from
GlobalSetupTeardown
to get GlobalSetupTeardown to run
b
interesting. is the inheirtied GlobalSetupTeardown just empty
m
Yep
New problems now 😄