Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

SingletonTests.cs

using FluentAssertions;
using Nop.Core.Infrastructure;
using NUnit.Framework;

namespace Nop.Tests.Nop.Core.Tests.Infrastructure;

[TestFixture]
public class SingletonTests
{
    [Test]
    public void SingletonIsNullByDefault()
    {
        var instance = Singleton.Instance;
        instance.Should().BeNull();
    }

    [Test]
    public void SingletonsShareSameSingletonsDictionary()
    {
        Singleton.Instance = 1;
        Singleton.Instance = 2.0;

        Singleton.AllSingletons.Should().BeSameAs(Singleton.AllSingletons);
        BaseSingleton.AllSingletons[typeof(int)].Should().Be(1);
        BaseSingleton.AllSingletons[typeof(double)].Should().Be(2.0M);
    }

    [Test]
    public void SingletonDictionaryIsCreatedByDefault()
    {
        var instance = SingletonDictionary.Instance;
        instance.Should().NotBeNull();
    }

    [Test]
    public void SingletonDictionaryCanStoreStuff()
    {
        var instance = SingletonDictionary.Instance;
        instance[typeof(SingletonTests)] = this;
        instance[typeof(SingletonTests)].Should().BeSameAs(this);
    }

    [Test]
    public void SingletonListIsCreatedByDefault()
    {
        var instance = SingletonList.Instance;
        instance.Should().NotBeNull();
    }

    [Test]
    public void SingletonListCanStoreItems()
    {
        var instance = SingletonList.Instance;
        instance.Insert(0, this);
        instance[0].Should().BeSameAs(this);
    }
}