public async Task PushAsyncTest() { 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 state.PushAsync(new TestState { Value = "A" }, cts.Token); await state.PushAsync(new TestState { Value = "B" }, cts.Token); await state.PushAsync(new TestState { Value = "C" }, cts.Token); var manifest = await stateManager.GetStateAsync <LinkedManifest>("TestName", cts.Token); Assert.Equal(3, manifest.Count); Assert.Equal(2, manifest.First); Assert.Equal(0, manifest.Last); Assert.Equal(3, manifest.Next); var value0 = await stateManager.TryGetStateAsync <LinkedNode <TestState> >("TestName:2", cts.Token); Assert.True(value0.HasValue); Assert.Null(value0.Value.Previous); Assert.Equal(1, value0.Value.Next); Assert.NotNull(value0.Value.Value); Assert.Equal("C", value0.Value.Value.Value); var value1 = await stateManager.TryGetStateAsync <LinkedNode <TestState> >("TestName:1", cts.Token); Assert.True(value1.HasValue); Assert.Equal(2, value1.Value.Previous); Assert.Equal(0, value1.Value.Next); Assert.NotNull(value1.Value.Value); Assert.Equal("B", value1.Value.Value.Value); var value2 = await stateManager.TryGetStateAsync <LinkedNode <TestState> >("TestName:0", cts.Token); Assert.True(value2.HasValue); Assert.Equal(1, value2.Value.Previous); Assert.Null(value2.Value.Next); Assert.NotNull(value2.Value.Value); Assert.Equal("A", value2.Value.Value.Value); }
public async Task Int_Empty_TryGetStateAsyncTest() { var instance = new MockActorStateManager(); var result = await instance.TryGetStateAsync <int>("not existing"); Assert.IsInstanceOfType(result, typeof(ConditionalValue <int>)); Assert.AreEqual(default(int), result.Value); Assert.IsFalse(result.HasValue); }
public async Task Nullable_Int_Empty_TryGetStateAsyncTest() { var instance = new MockActorStateManager(); var result = await instance.TryGetStateAsync <int?>("not existing"); Assert.IsInstanceOfType(result, typeof(ConditionalValue <int?>)); Assert.IsNull(result.Value); Assert.IsFalse(result.HasValue); }
public async Task Int_AddStateAsyncTest() { var instance = new MockActorStateManager(); await instance.AddStateAsync("existing", 6); var result = await instance.TryGetStateAsync <int>("existing"); Assert.IsInstanceOfType(result, typeof(ConditionalValue <int>)); Assert.IsNotNull(result.Value); Assert.IsTrue(result.HasValue); Assert.AreEqual(6, result.Value); }
public async Task MultiType_SetStateAsyncTest() { var instance = new MockActorStateManager(); string stateName = "stateName"; await instance.SetStateAsync(stateName, string.Empty); await instance.SetStateAsync(stateName, 5); DateTimeOffset utcNow = DateTimeOffset.UtcNow; await instance.SetStateAsync(stateName, utcNow); var result = await instance.TryGetStateAsync <DateTimeOffset>(stateName); Assert.IsInstanceOfType(result, typeof(ConditionalValue <DateTimeOffset>)); Assert.IsNotNull(result.Value); Assert.IsTrue(result.HasValue); Assert.AreEqual(utcNow, result.Value); }
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); }
public async Task RemoveAsyncTest() { var stateManager = new MockActorStateManager(); var keyMock = new Mock <IStateKey>(); keyMock.Setup(x => x.ToString()).Returns("TestName"); var state = new ActorListState <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 i = 0; await state.RemoveAsync(s => i++ == 1, cts.Token); Assert.False(await stateManager.ContainsStateAsync("TestName:1", cts.Token), "State was expected to be deleted"); var node = await stateManager.TryGetStateAsync <LinkedNode <TestState> >("TestName:0", cts.Token); Assert.True(node.HasValue, "State was expected to exist"); Assert.NotNull(node.Value.Value); Assert.Null(node.Value.Previous); Assert.Null(node.Value.Next); var manifest = await stateManager.TryGetStateAsync <LinkedManifest>("TestName", cts.Token); Assert.True(manifest.HasValue, "Manifest was expected to exist"); Assert.Equal(1, manifest.Value.Count); Assert.Equal(2, manifest.Value.Next); Assert.Equal(0, manifest.Value.First); Assert.Equal(0, manifest.Value.Last); i = 0; await state.RemoveAsync(s => i++ == 0, cts.Token); Assert.False(await stateManager.ContainsStateAsync("TestName:0", cts.Token), "State was expected to be deleted"); manifest = await stateManager.TryGetStateAsync <LinkedManifest>("TestName", cts.Token); Assert.True(manifest.HasValue, "Manifest was expected to exist"); Assert.Equal(0, manifest.Value.Count); Assert.Equal(0, manifest.Value.Next); Assert.Null(manifest.Value.First); Assert.Null(manifest.Value.Last); }
public async Task InsertAtAsync_EndTest() { var stateManager = new MockActorStateManager(); var keyMock = new Mock <IStateKey>(); keyMock.Setup(x => x.ToString()).Returns("TestName"); var cts = new CancellationTokenSource(1000); await stateManager.SetStateAsync("TestName", new LinkedManifest { Count = 2, First = 0, Last = 1, Next = 2 }, cts.Token); await stateManager.AddStateAsync("TestName:0", new LinkedNode <TestState> { Next = 1, Value = new TestState { Value = "A" } }, cts.Token); await stateManager.AddStateAsync("TestName:1", new LinkedNode <TestState> { Previous = 0, Value = new TestState { Value = "B" } }, cts.Token); var state = new TestLinkedCollectionState(stateManager, keyMock.Object); var values = new List <TestState> { new TestState { Value = "I1" }, new TestState { Value = "I2" }, }; await state.TestInsertAtAsync(2, values, cts.Token); var manifest = await stateManager.GetStateAsync <LinkedManifest>("TestName", cts.Token); Assert.Equal(4, manifest.Count); Assert.Equal(0, manifest.First); Assert.Equal(3, manifest.Last); Assert.Equal(4, manifest.Next); var value0 = await stateManager.TryGetStateAsync <LinkedNode <TestState> >("TestName:0", cts.Token); Assert.True(value0.HasValue); Assert.Null(value0.Value.Previous); Assert.Equal(1, value0.Value.Next); Assert.NotNull(value0.Value.Value); Assert.Equal("A", value0.Value.Value.Value); var value1 = await stateManager.TryGetStateAsync <LinkedNode <TestState> >("TestName:1", cts.Token); Assert.True(value1.HasValue); Assert.Equal(0, value1.Value.Previous); Assert.Equal(2, value1.Value.Next); Assert.NotNull(value1.Value.Value); Assert.Equal("B", value1.Value.Value.Value); var value2 = await stateManager.TryGetStateAsync <LinkedNode <TestState> >("TestName:2", cts.Token); Assert.True(value2.HasValue); Assert.Equal(1, value2.Value.Previous); Assert.Equal(3, value2.Value.Next); Assert.NotNull(value2.Value.Value); Assert.Equal("I1", value2.Value.Value.Value); var value3 = await stateManager.TryGetStateAsync <LinkedNode <TestState> >("TestName:3", cts.Token); Assert.True(value3.HasValue); Assert.Equal(2, value3.Value.Previous); Assert.Null(value3.Value.Next); Assert.NotNull(value3.Value.Value); Assert.Equal("I2", value3.Value.Value.Value); }