Exemplo n.º 1
0
    public async Task DeleteActorCommandHandle_WithoutActor_DoesNothing()
    {
        // Arrange
        var repository = new Mock <IActorRepository>();
        var target     = new ActorUpdatedHandler(repository.Object, new Mock <ILogger>().Object);

        var actorId = new ActorId(Guid.NewGuid());

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

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

        // Act + Assert
        await target.Handle(deleteActorCommand, CancellationToken.None).ConfigureAwait(false);
    }
Exemplo n.º 2
0
    public async Task UpdateActorCommandHandle_WithActor_SavesActor()
    {
        // Arrange
        var repository = new Mock <IActorRepository>();
        var target     = new ActorUpdatedHandler(repository.Object, new Mock <ILogger>().Object);

        var actorId    = Guid.NewGuid();
        var externalId = Guid.NewGuid();

        var updateActorCommand = new UpdateActorCommand(actorId, externalId);

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

        // Assert
        repository.Verify(
            r => r.AddOrUpdateAsync(It.Is <Actor>(actor => actor.Id.Value == actorId.ToString() && actor.ExternalId.Value == externalId)),
            Times.Once);
    }
Exemplo n.º 3
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);
    }