public static Actor Map(CosmosActor actor)
    {
        var actorId    = new ActorId(Guid.Parse(actor.Id));
        var externalId = new ExternalActorId(Guid.Parse(actor.ExternalId));

        return(new Actor(actorId, externalId));
    }
    public async Task <Unit> Handle(UpdateActorCommand request, CancellationToken cancellationToken)
    {
        ArgumentNullException.ThrowIfNull(request, nameof(request));

        _logger.LogInformation("Updating actor with ActorId: {ActorId}.", request.ActorId);

        var actorId    = new ActorId(request.ActorId);
        var externalId = new ExternalActorId(request.ExternalActorId);

        var actor = new Actor(actorId, externalId);
        await _actorRepository.AddOrUpdateAsync(actor).ConfigureAwait(false);

        return(Unit.Value);
    }
예제 #3
0
        public async Task <Actor?> GetActorAsync(ExternalActorId externalActorId)
        {
            ArgumentNullException.ThrowIfNull(externalActorId, nameof(externalActorId));

            var query =
                from actor in _repositoryContainer.Container.GetItemLinqQueryable <CosmosActor>()
                where actor.ExternalId == externalActorId.Value.ToString()
                select actor;

            var actorDocument = await query
                                .AsCosmosIteratorAsync()
                                .SingleOrDefaultAsync()
                                .ConfigureAwait(false);

            return(actorDocument != null?ActorMapper.Map(actorDocument) : null);
        }
예제 #4
0
    public async Task DeleteActorCommandHandle_WithActor_DeletesActor()
    {
        // Arrange
        var repository = new Mock <IActorRepository>();
        var target     = new ActorUpdatedHandler(repository.Object, new Mock <ILogger>().Object);

        var actorId    = new ActorId(Guid.NewGuid());
        var externalId = new ExternalActorId(Guid.NewGuid());
        var actor      = new Actor(actorId, externalId);

        repository
        .Setup(r => r.GetActorAsync(It.Is <ActorId>(id => id == actorId)))
        .ReturnsAsync(actor);

        var deleteActorCommand = new DeleteActorCommand(Guid.Parse(actorId.Value));

        // Act
        await target.Handle(deleteActorCommand, CancellationToken.None).ConfigureAwait(false);

        // Assert
        repository.Verify(r => r.DeleteAsync(actor), Times.Once);
    }
예제 #5
0
 public Actor(ActorId id, ExternalActorId externalId)
 {
     Id         = id;
     ExternalId = externalId;
 }