Exemple #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();
        }
Exemple #3
0
        public void Init()
        {
            ILogger logger = A.Fake <ILogger>();

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

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

            IEmailService emailService = A.Fake <IEmailService>();

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

            this.sut = new TicketManager(logger, ticketsRepository, emailService, systemTime);
        }
Exemple #4
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();
        }
Exemple #5
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_WhenTicketRequestIsCreated_ShouldReturnId()
        {
            // Arrange
            int expectedId = 1;

            ILogger       logger       = A.Fake <ILogger>();
            IEmailService emailService = A.Fake <IEmailService>();
            ISystemTime   systemTime   = A.Fake <ISystemTime>();

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

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

            TicketManager sut = new TicketManager(logger, ticketsRepository, emailService, systemTime);

            TicketRequest request = new TicketRequest("foo", "foo", 1);

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

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