public Task SaveStateAsync(ActorId actorId, IReadOnlyCollection <ActorStateChange> stateChanges,
                                   CancellationToken cancellationToken = new CancellationToken())
        {
            ActionsPerformed.Add(nameof(SaveStateAsync));
            MockedInternalActorState mockedInternalActorState;

            if (_trackedActors.ContainsKey(actorId))
            {
                mockedInternalActorState = _trackedActors[actorId];
            }
            else
            {
                mockedInternalActorState = new MockedInternalActorState();
                _trackedActors.Add(actorId, mockedInternalActorState);
            }

            foreach (var actorStateChange in stateChanges)
            {
                if (actorStateChange.ChangeKind == StateChangeKind.Add)
                {
                    mockedInternalActorState.State.Add(actorStateChange.StateName, actorStateChange.Value);
                }
                else if (actorStateChange.ChangeKind == StateChangeKind.Update)
                {
                    mockedInternalActorState.State[actorStateChange.StateName] = actorStateChange.Value;
                }
                else if (actorStateChange.ChangeKind == StateChangeKind.Remove)
                {
                    mockedInternalActorState.State.Remove(actorStateChange.StateName);
                }
            }

            return(Task.FromResult(true));
        }
        public Task <IEnumerable <string> > EnumerateStateNamesAsync(ActorId actorId, CancellationToken cancellationToken = new CancellationToken())
        {
            ActionsPerformed.Add(nameof(EnumerateStateNamesAsync));
            var stateNames = _trackedActors[actorId].State.Select(actorState => actorState.Key);

            return(Task.FromResult(stateNames));
        }
        public Task ActorActivatedAsync(ActorId actorId, CancellationToken cancellationToken = new CancellationToken())
        {
            ActionsPerformed.Add(nameof(ActorActivatedAsync));
            if (!_trackedActors.ContainsKey(actorId))
            {
                _trackedActors.Add(actorId, new MockedInternalActorState()
                {
                });
            }

            return(Task.FromResult(true));
        }
 public Task <T> LoadStateAsync <T>(ActorId actorId, string stateName, CancellationToken cancellationToken = new CancellationToken())
 {
     ActionsPerformed.Add(nameof(LoadStateAsync));
     if (_trackedActors.ContainsKey(actorId))
     {
         var trackedActor = _trackedActors[actorId];
         if (trackedActor.State.ContainsKey(stateName))
         {
             return(Task.FromResult((T)trackedActor.State[stateName]));
         }
     }
     return(Task.FromResult(default(T)));
 }
        public Task <bool> ContainsStateAsync(ActorId actorId, string stateName, CancellationToken cancellationToken = new CancellationToken())
        {
            ActionsPerformed.Add(nameof(ContainsStateAsync));
            if (_trackedActors.ContainsKey(actorId))
            {
                var actorState = _trackedActors[actorId];
                if (actorState.State.ContainsKey(stateName))
                {
                    return(Task.FromResult(true));
                }
            }

            return(Task.FromResult(false));
        }
        public Task <PagedResult <ActorId> > GetActorsAsync(int numItemsToReturn, ContinuationToken continuationToken, CancellationToken cancellationToken)
        {
            ActionsPerformed.Add(nameof(GetActorsAsync));

            var continueAt        = continuationToken == null ? 0 : int.Parse((string)continuationToken.Marker);
            var actorsLeft        = _trackedActors.Keys.Count - continueAt;
            var actualNumToReturn = Math.Min(numItemsToReturn, actorsLeft);

            var result = new PagedResult <ActorId>
            {
                Items             = _trackedActors.Keys.Skip(continueAt).Take(actualNumToReturn).ToList(),
                ContinuationToken = actorsLeft - actualNumToReturn == 0 ? null : new ContinuationToken((continueAt + actualNumToReturn).ToString())
            };

            return(Task.FromResult(result));
        }
        public Task SaveReminderAsync(ActorId actorId, IActorReminder reminder,
                                      CancellationToken cancellationToken = new CancellationToken())
        {
            ActionsPerformed.Add(nameof(SaveReminderAsync));

            if (_trackedActors.ContainsKey(actorId))
            {
                var actorState = _trackedActors[actorId];
                actorState.Reminders.Add(reminder.Name, reminder);
            }
            else
            {
                var actorState = new MockedInternalActorState();
                actorState.Reminders.Add(reminder.Name, reminder);
                _trackedActors.Add(actorId, actorState);
            }
            return(Task.FromResult(true));
        }
 public Task RemoveActorAsync(ActorId actorId, CancellationToken cancellationToken = new CancellationToken())
 {
     ActionsPerformed.Add(nameof(RemoveActorAsync));
     _trackedActors.Remove(actorId);
     return(Task.FromResult(true));
 }
 public Task ReminderCallbackCompletedAsync(ActorId actorId, IActorReminder reminder, CancellationToken cancellationToken = new CancellationToken())
 {
     ActionsPerformed.Add(nameof(ReminderCallbackCompletedAsync));
     return(Task.FromResult(true));
 }