Beispiel #1
0
        public async Task RaiseTicketAsync_WhenTicketRequestIsCreated_ShouldBeSetUtcNowToRaisedAt()
        {
            // Arrange
            DateTime utcNow = new DateTime(2021, 01, 01);

            ISystemTime systemTimeStub = A.Fake <ISystemTime>();

            A.CallTo(() => systemTimeStub.UtcNow)
            .Returns(utcNow);

            ITicketsRepository ticketsRepositoryMock = A.Fake <ITicketsRepository>();

            TicketRequest ticketRequest = new TicketRequestBuilder().Build();

            TicketManager sut = new TicketManagerBuilder()
                                .WithISystemTime(systemTimeStub)
                                .WithITicketsRepository(ticketsRepositoryMock)
                                .Build();

            // Act
            await sut.RaiseTicketAsync(ticketRequest);

            // Assert
            A.CallTo(
                () => ticketsRepositoryMock.CreateAsync(
                    A <TicketRequest> .That.Matches(x => x.CreatedAt == utcNow))).MustHaveHappenedOnceExactly();
        }
        public async Task RaiseTicketAsync_WithValidTicketRequest_ShouldLogInformationAndReturnTicketRequestId()
        {
            // Arrange
            int expectedId = 1;

            ITicketsRepository ticketsRepository = A.Fake <ITicketsRepository>();

            A.CallTo(() => ticketsRepository.CreateAsync(A <TicketRequest> .Ignored))
            .Returns(expectedId);

            ILogger logger = A.Fake <ILogger>();

            TicketManager sut = new TicketManagerBuilder()
                                .WithITicketsRepository(ticketsRepository)
                                .WithILogger(logger)
                                .Build();

            TicketRequest request = new TicketRequestBuilder().Build();

            // Act
            int actualId = await sut.RaiseTicketAsync(request);

            // Assert
            actualId.Should().Be(expectedId);
            A.CallTo(() => logger.Information(A <string> .Ignored, A <object[]> .Ignored)).MustHaveHappened();
        }
Beispiel #3
0
        public async Task RaiseTicketAsync_WithNullTicketRequest_ShouldThrowArgumentNullException()
        {
            // Arrange
            TicketManager sut = new TicketManagerBuilder().Build();

            // Act
            Func <Task> act = () => sut.RaiseTicketAsync(null);

            // Assert
            ArgumentNullException exception = await Assert.ThrowsAsync <ArgumentNullException>(act);

            exception.ParamName.Should().NotBeNullOrEmpty();
        }
        public async Task RaiseTicketAsync_WithValidTicketRequest_ShouldLogInformation()
        {
            // Arrange
            Mock <ILogger> loggerMock = new Mock <ILogger>();

            TicketRequest ticketRequest = new TicketRequestBuilder().Build();
            TicketManager sut           = new TicketManagerBuilder()
                                          .WithILogger(loggerMock.Object)
                                          .Build();

            // Act
            await sut.RaiseTicketAsync(ticketRequest);

            // Assert
            loggerMock.Verify(t => t.Information(
                                  It.IsNotNull <string>(),
                                  It.IsAny <object[]>()), Times.Once);
        }
Beispiel #5
0
        public async Task RaiseTicketAsync_WithValidTicketRequest_ShouldBeCreatedInRepository()
        {
            // Arrange
            ITicketsRepository ticketsRepositoryMock = A.Fake <ITicketsRepository>();

            TicketRequest ticketRequest = new TicketRequestBuilder().Build();

            TicketManager sut = new TicketManagerBuilder()
                                .WithITicketsRepository(ticketsRepositoryMock)
                                .Build();

            // Act
            await sut.RaiseTicketAsync(ticketRequest);

            // Assert
            A.CallTo(
                () => ticketsRepositoryMock.CreateAsync(
                    A <TicketRequest> .That.Matches(x => x == ticketRequest))).MustHaveHappenedOnceExactly();
        }
Beispiel #6
0
        public async Task RaiseTicketAsync_WithValidTicketRequest_ShouldLogInformation()
        {
            // Arrange
            ILogger loggerMock = A.Fake <ILogger>();

            TicketRequest ticketRequest = new TicketRequestBuilder().Build();

            TicketManager sut = new TicketManagerBuilder()
                                .WithILogger(loggerMock)
                                .Build();

            // Act
            await sut.RaiseTicketAsync(ticketRequest);

            // Assert
            A.CallTo(
                () => loggerMock.Information(
                    A <string> .That.Matches(x => !string.IsNullOrEmpty(x)),
                    A <object[]> .Ignored)).MustHaveHappenedOnceExactly();
        }
Beispiel #7
0
        public async Task RaiseTicketAsync_WithValidTicketRequest_ShouldSendEmail()
        {
            // Arrange
            IEmailService emailServiceMock = A.Fake <IEmailService>();

            TicketRequest ticketRequest = new TicketRequestBuilder().Build();

            TicketManager sut = new TicketManagerBuilder()
                                .WithIEmailService(emailServiceMock)
                                .Build();

            // Act
            await sut.RaiseTicketAsync(ticketRequest);

            // Assert
            A.CallTo(
                () => emailServiceMock.SendEmailAsync(
                    A <string> .That.Matches(htmlContent => !string.IsNullOrEmpty(htmlContent)),
                    A <string> .That.Matches(toEmail => !string.IsNullOrEmpty(toEmail))))
            .MustHaveHappenedOnceExactly();
        }
Beispiel #8
0
        public async Task RaiseTicketAsync_WhenTicketRequestIsCreated_ReturnTicketRequestId()
        {
            // Arrange
            int expectedId = 1;

            ITicketsRepository ticketsRepositoryStub = A.Fake <ITicketsRepository>();

            A.CallTo(() => ticketsRepositoryStub.CreateAsync(A <TicketRequest> .Ignored))
            .Returns(expectedId);

            TicketManager sut = new TicketManagerBuilder()
                                .WithITicketsRepository(ticketsRepositoryStub)
                                .Build();

            TicketRequest request = new TicketRequestBuilder().Build();

            // Act
            int actualId = await sut.RaiseTicketAsync(request);

            // Assert
            actualId.Should().Be(expectedId);
        }
        public async Task RaiseTicketAsync_WithValidTicketRequest_ReturnTicketRequestId()
        {
            // Arrange
            int expectedId = 1;

            Mock <ITicketsRepository> ticketsRepositoryMock = new Mock <ITicketsRepository>();

            ticketsRepositoryMock
            .Setup(x => x.CreateAsync(It.IsAny <TicketRequest>()))
            .ReturnsAsync(expectedId);

            TicketManager sut = new TicketManagerBuilder()
                                .WithITicketsRepository(ticketsRepositoryMock.Object)
                                .Build();

            TicketRequest request = new TicketRequestBuilder().Build();

            // Act
            int actualId = await sut.RaiseTicketAsync(request);

            // Assert
            actualId.Should().Be(expectedId);
        }