// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------
namespace Dapr.Actors.Test
{
using System.Threading;
using System.Threading.Tasks;
using Dapr.Actors.Runtime;
///
/// Interface for test actor.
///
public interface ITestActor : IActor
{
///
/// GetCount method for TestActor.
///
/// Cancellation token to cancel the operation.
/// The current count as stored in actor.
Task GetCountAsync(CancellationToken cancellationToken);
///
/// SetCoutn method for test actor.
///
/// Count to set for the actor.
/// Cancellation token to cancel the operation.
/// Task.
Task SetCountAsync(int count, CancellationToken cancellationToken);
}
///
/// Test Actor Class.
///
public class TestActor : Actor, ITestActor
{
public TestActor(ActorService actorService, ActorId actorId, IActorStateManager actorStateManager)
: base(actorService, actorId, actorStateManager)
{
}
///
public Task GetCountAsync(CancellationToken cancellationToken)
{
return Task.FromResult(5);
}
///
public Task SetCountAsync(int count, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
public void SaveTestState()
{
this.SaveStateAsync().GetAwaiter().GetResult();
}
public void ResetTestStateAsync()
{
this.ResetStateAsync().GetAwaiter().GetResult();
}
}
}