public void Current_WithLocalScope_ShouldUseScopedGenerator()
        {
            var invocationDetector = new InvocationDetector();

            using var scope = new IdGeneratorScope(CreateIdGenerator(invocationDetector));

            Assert.True(invocationDetector.WasInvoked);
        }
        public void CurrentGenerator_WithLocalScopeWhenUsed_ShouldUseScopedGenerator()
        {
            var invocationDetector = new InvocationDetector();

            using var scope = new IdGeneratorScope(CreateIdGenerator(invocationDetector));
            invocationDetector.WasInvoked = false;

            IdGeneratorScope.CurrentGenerator.CreateId();

            Assert.True(invocationDetector.WasInvoked);
        }
        private static IIdGenerator CreateIdGenerator(InvocationDetector invocationDetector)
        {
            return(new FluidIdGenerator(isProduction: false, utcClock: GetUtcNow, applicationInstanceId: 1));

            // Local function that acts as the UTC clock and also toggles a ref bool
            DateTime GetUtcNow()
            {
                invocationDetector.WasInvoked = true;
                return(FluidIdGenerator.GetUtcNow());
            }
        }
        public void CurrentGenerator_WithNestedScopesWhenUsed_ShouldUseNearestScopedGenerator()
        {
            var outerInvocationDetector = new InvocationDetector();

            using var outerScope = new IdGeneratorScope(CreateIdGenerator(outerInvocationDetector));
            outerInvocationDetector.WasInvoked = false;

            var innerInvocationDetector = new InvocationDetector();

            using var innerScope = new IdGeneratorScope(CreateIdGenerator(innerInvocationDetector));
            innerInvocationDetector.WasInvoked = false;

            IdGeneratorScope.CurrentGenerator.CreateId();

            Assert.True(innerInvocationDetector.WasInvoked);
            Assert.False(outerInvocationDetector.WasInvoked);
        }