mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.7 KiB
52 lines
1.7 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Threading.Tasks;
|
|
using FakeItEasy;
|
|
using Squidex.Infrastructure.Orleans;
|
|
using Xunit;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Contents.Counter
|
|
{
|
|
public class CounterGrainTests
|
|
{
|
|
private readonly IGrainState<CounterGrain.State> grainState = A.Fake<IGrainState<CounterGrain.State>>();
|
|
private readonly CounterGrain sut;
|
|
|
|
public CounterGrainTests()
|
|
{
|
|
sut = new CounterGrain(grainState);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_increment_counters()
|
|
{
|
|
Assert.Equal(1, await sut.IncrementAsync("Counter1"));
|
|
Assert.Equal(2, await sut.IncrementAsync("Counter1"));
|
|
|
|
Assert.Equal(1, await sut.IncrementAsync("Counter2"));
|
|
Assert.Equal(2, await sut.IncrementAsync("Counter2"));
|
|
|
|
A.CallTo(() => grainState.WriteAsync())
|
|
.MustHaveHappened(4, Times.Exactly);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_reset_counter()
|
|
{
|
|
Assert.Equal(1, await sut.IncrementAsync("Counter1"));
|
|
Assert.Equal(2, await sut.IncrementAsync("Counter1"));
|
|
|
|
Assert.Equal(1, await sut.ResetAsync("Counter1", 1));
|
|
|
|
Assert.Equal(2, await sut.IncrementAsync("Counter1"));
|
|
|
|
A.CallTo(() => grainState.WriteAsync())
|
|
.MustHaveHappened(4, Times.Exactly);
|
|
}
|
|
}
|
|
}
|
|
|