Exemplo n.º 1
0
        public async Task TryPeekAsync_When_NoStateTest()
        {
            var stateManager = new MockActorStateManager();
            var keyMock      = new Mock <IStateKey>();

            keyMock.Setup(x => x.ToString()).Returns("TestName");

            var state = new ActorStackState <TestState>(stateManager, keyMock.Object);

            var cts = new CancellationTokenSource(1000);

            var result = await state.TryPeekAsync(cts.Token);

            Assert.False(result.HasValue);
        }
Exemplo n.º 2
0
        public async Task TryPeekAsync_MultipleValuesTest()
        {
            var stateManager = new MockActorStateManager();
            var keyMock      = new Mock <IStateKey>();

            keyMock.Setup(x => x.ToString()).Returns("TestName");

            var state = new ActorStackState <TestState>(stateManager, keyMock.Object);

            var cts = new CancellationTokenSource(1000);

            var values = new List <TestState>
            {
                new TestState
                {
                    Value = "A"
                },
                new TestState
                {
                    Value = "B"
                }
            };

            await stateManager.SetStateAsync("TestName", new LinkedManifest
            {
                Count = 2,
                First = 0,
                Last  = 1,
                Next  = 2
            }, cts.Token);

            await stateManager.SetStateAsync("TestName:0", new LinkedNode <TestState>
            {
                Next  = 1,
                Value = values[0]
            }, cts.Token);

            await stateManager.AddStateAsync("TestName:1", new LinkedNode <TestState>
            {
                Previous = 0,
                Value    = values[1]
            }, cts.Token);

            var result = await state.TryPeekAsync(cts.Token);

            Assert.True(result.HasValue);
            Assert.Equal("A", result.Value.Value);
        }
Exemplo n.º 3
0
        public async Task TryPeekAsync_When_NoValuesTest()
        {
            var stateManager = new MockActorStateManager();
            var keyMock      = new Mock <IStateKey>();

            keyMock.Setup(x => x.ToString()).Returns("TestName");

            var state = new ActorStackState <TestState>(stateManager, keyMock.Object);

            var cts = new CancellationTokenSource(1000);

            await stateManager.SetStateAsync("TestName", new LinkedManifest
            {
                Count = 0,
                First = null,
                Last  = null,
                Next  = 0
            }, cts.Token);

            var result = await state.TryPeekAsync(cts.Token);

            Assert.False(result.HasValue);
        }