예제 #1
0
        public async Task OnActivateAsync_WithDefaultState_DoesNotMutateState()
        {
            // Arrange
            var state = new ColorGrainState();

            Silo.AddPersistentState(stateName: "State", state: state);

            // Act
            var grain = await Silo.CreateGrainAsync <ColorGrain>(GrainId);

            // Assert
            state.Color.Should().Be(Color.Unknown);
            state.Id.Should().Be(Guid.Empty);
        }
예제 #2
0
        public async Task GetFavouriteColor_WithState_ReturnsColor()
        {
            Silo.AddPersistentState("Default", state: new ColorGrainState
            {
                Id    = GrainId,
                Color = Color.Blue
            });

            var grain = await Silo.CreateGrainAsync <ColorRankingGrain>(GrainId);

            // Act
            var color = await grain.GetFavouriteColor();

            color.Should().Be(Color.Blue);
        }
예제 #3
0
        public async Task SetColor_WithDefaultState_SetsState()
        {
            // Arrange
            var state = new ColorGrainState();

            Silo.AddPersistentState(stateName: "State", state: state);

            var grain = await Silo.CreateGrainAsync <ColorGrain>(GrainId);

            // Act
            await grain.SetColor(Color.Blue);

            // Assert
            state.Color.Should().Be(Color.Blue);
            state.Id.Should().Be(GrainId);
        }
예제 #4
0
        public async Task SetColor_WithMutatedState_ThrowsInconsistentStateException()
        {
            // Arrange
            var mock = new Mock <IStorage <ColorGrainState> >();

            mock.SetupAllProperties();
            mock.Setup(o => o.WriteStateAsync()).Throws <InconsistentStateException>();

            Silo.AddPersistentState(stateName: "State", storage: mock.Object);

            var grain = await Silo.CreateGrainAsync <ColorGrain>(GrainId);

            Action action = () => grain.SetColor(Color.Green);

            // Act+Assert
            action.Should().Throw <InconsistentStateException>();
        }
예제 #5
0
        public async Task SetFavouriteColor_WithState_SetsState()
        {
            var persistentState = Silo.AddPersistentState("Default", state: new ColorGrainState
            {
                Id    = GrainId,
                Color = Color.Red
            });

            var grain = await Silo.CreateGrainAsync <ColorRankingGrain>(GrainId);

            // Act
            await grain.SetFavouriteColor(Color.Blue);

            var state = persistentState.State;

            state.Color.Should().Be(Color.Blue);
            state.Id.Should().Be(GrainId);
        }
예제 #6
0
        public async Task GetColor_WithState_ReturnsColor()
        {
            // Arrange
            var state = new ColorGrainState
            {
                Color = Color.Red,
                Id    = GrainId,
            };

            Silo.AddPersistentState(stateName: "State", state: state);

            var grain = await Silo.CreateGrainAsync <ColorGrain>(GrainId);

            // Act
            var color = await grain.GetColor();

            // Assert
            color.Should().Be(Color.Red);
        }
예제 #7
0
        public async Task ResetColor_WithState_ClearsState()
        {
            // Arrange
            var state = new ColorGrainState
            {
                Color = Color.Red,
                Id    = GrainId,
            };

            Silo.AddPersistentState(stateName: "State", state: state);

            var grain = await Silo.CreateGrainAsync <ColorGrain>(GrainId);

            // Act
            await grain.ResetColor();

            // Assert
            var storageStats = Silo.StorageManager.GetStorageStats(stateName: "State");

            storageStats.Clears.Should().Be(1);
        }
예제 #8
0
        public async Task ResetColor_WithDefaultState_DoesNotClearState()
        {
            // Arrange
            var state = new ColorGrainState();

            Silo.AddPersistentState(stateName: "State", state: state);

            var grain = await Silo.CreateGrainAsync <ColorGrain>(GrainId);

            // Act
            await grain.ResetColor();

            // Assert
            state.Color.Should().Be(Color.Unknown);
            state.Id.Should().Be(Guid.Empty);

            // Note that the following assert ties this test to the _implementation_ details. Generally, one should try
            // to avoid tying the test to the implementation details. It can lead to more brittle tests. However, one may
            // choose to accept this as a trade-off when the implementation detail represents an important behavior.
            var storageStats = Silo.StorageManager.GetStorageStats(stateName: "State");

            storageStats.Clears.Should().Be(0);
        }