Пример #1
0
        public void HandlerTests(string message, object initialState)
        {
            using var context = new LockState(new Key("", "", TimeSpan.FromSeconds(1)), "key", CancellationToken.None);
            switch (initialState)
            {
            case State.WithKey:
                context.SetWithKey();
                break;

            case State.Done:
                context.SetDone();
                break;
            }

            context.Handler(new StackExchange.Redis.RedisChannel(), message);

            switch (initialState)
            {
            case State.WaitingForKey:
                if (context.Identifier == message)
                {
                    Assert.Equal(State.WithKey, context.State);
                }
                break;

            case State.WithKey:
                if (context.Identifier == message)
                {
                    Assert.Equal(State.WithKey, context.State);
                }
                else
                {
                    Assert.Equal(State.Done, context.State);
                }
                break;

            case State.Done:
                Assert.Equal(State.Done, context.State);
                break;
            }
        }