Esempio n. 1
0
        public async Task HandleAsync_WhenPollDoesNotExist_ShouldCallNotFound()
        {
            // Arrange
            const int    pollId = 1;
            const string expectedResultMessage = "Poll not found";

            ILoggerService <DeletePollUseCase> loggerServiceStub = A.Fake <ILoggerService <DeletePollUseCase> >();
            IPollGateway pollGatewayStub = A.Fake <IPollGateway>();

            A.CallTo(() => pollGatewayStub.GetAsync(pollId))
            .Returns((Poll)null);

            IDeletePollOutputPort OutputPortMock = A.Fake <IDeletePollOutputPort>();

            var useCase = new DeletePollUseCase(loggerServiceStub, pollGatewayStub);

            // Act
            await useCase.HandleAsync(pollId, OutputPortMock);

            // Assert
            A.CallTo(
                () => OutputPortMock.NotFound(
                    A <string> .That.Contains(expectedResultMessage)))
            .MustHaveHappenedOnceExactly();
        }
Esempio n. 2
0
        public async Task HandleAsync_WhenPollDoesNotExist_ShouldLogInformation()
        {
            // Arrange
            const int    pollId             = 1;
            const string expectedLogMessage = "Cannot retrieve a poll with {@id}";

            IPollGateway pollGatewayStub = A.Fake <IPollGateway>();

            A.CallTo(() => pollGatewayStub.GetAsync(pollId))
            .Returns((Poll)null);

            IDeletePollOutputPort OutputPortStub = A.Fake <IDeletePollOutputPort>();
            ILoggerService <DeletePollUseCase> loggerServiceMock = A.Fake <ILoggerService <DeletePollUseCase> >();

            var useCase = new DeletePollUseCase(loggerServiceMock, pollGatewayStub);

            // Act
            await useCase.HandleAsync(pollId, OutputPortStub);

            // Assert
            A.CallTo(
                () => loggerServiceMock.LogInformation(
                    A <string> .That.Contains(expectedLogMessage),
                    A <int> .That.IsEqualTo(pollId)))
            .MustHaveHappenedOnceExactly();
        }
        public async Task HandleAsync(int id, IDeletePollOutputPort output)
        {
            Poll poll = await this.pollGateway.GetAsync(id);

            if (poll is null)
            {
                output.NotFound("Poll not found");
                this.loggerService.LogInformation("Cannot retrieve a poll with {@id}", id);
                return;
            }

            await this.pollGateway.DeleteAsync(poll);

            output.Success();
        }
Esempio n. 4
0
        public async Task HandleAsync_WhenPollExists_ShouldDeleteIt()
        {
            // Arrange
            const int pollId = 1;
            Poll      poll   = this.GetFakePoll();

            IPollGateway pollGatewayMock = A.Fake <IPollGateway>();

            A.CallTo(() => pollGatewayMock.GetAsync(pollId))
            .Returns(poll);

            IDeletePollOutputPort OutputPortStub = A.Fake <IDeletePollOutputPort>();

            var useCase = new DeletePollUseCase(null, pollGatewayMock);

            // Act
            await useCase.HandleAsync(pollId, OutputPortStub);

            // Assert
            A.CallTo(() => pollGatewayMock.DeleteAsync(poll)).MustHaveHappenedOnceExactly();
        }