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

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

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

            var cts = new CancellationTokenSource(1000);

            await stateManager.AddStateAsync("TestName", new TestState(), cts.Token);

            await state.DeleteStateAsync(cts.Token);

            Assert.False(await stateManager.ContainsStateAsync("TestName", cts.Token), "State was expected to be deleted");
        }
Exemplo n.º 2
0
        public async Task SetAsyncTest()
        {
            var stateManager = new MockActorStateManager();
            var keyMock      = new Mock <IStateKey>();

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

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

            var cts = new CancellationTokenSource(1000);

            var result = await state.SetAsync(new TestState(), cts.Token);

            Assert.NotNull(result);

            var check = await stateManager.TryGetStateAsync <TestState>("TestName", cts.Token);

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

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

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

            var cts = new CancellationTokenSource(1000);

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

            Assert.False(result.HasValue, "State was expected to be missing");

            await stateManager.AddStateAsync("TestName", new TestState(), cts.Token);

            result = await state.TryGetAsync(cts.Token);

            Assert.True(result.HasValue, "State was expected to be found");
        }