예제 #1
0
        public async void Given_A_Non_Existing_Job_The_Handler_Should_Return_Null()
        {
            // arrange
            DateTime             date = DateTime.Today;
            string               workshopPlanningId = date.ToString("yyyy-MM-dd");
            Guid                 jobId           = Guid.NewGuid();
            DateTime             actualStartTime = date.AddHours(9);
            DateTime             actualEndTime   = date.AddHours(12);
            FinishMaintenanceJob command         = new FinishMaintenanceJobCommandBuilder()
                                                   .WithJobId(jobId)
                                                   .WithActualStartTime(actualStartTime)
                                                   .WithActualEndTime(actualEndTime)
                                                   .Build();

            Mock <IMessagePublisher> messagePublisherMock = new Mock <IMessagePublisher>();
            Mock <IEventSourceRepository <WorkshopPlanning> > repoMock =
                new Mock <IEventSourceRepository <WorkshopPlanning> >();

            repoMock
            .Setup(m => m.GetByIdAsync(It.Is <string>(p => p == workshopPlanningId)))
            .Returns(Task.FromResult <WorkshopPlanning>(null));

            FinishMaintenanceJobCommandHandler sut =
                new FinishMaintenanceJobCommandHandler(messagePublisherMock.Object, repoMock.Object);

            // act
            var result = await sut.HandleCommandAsync(date, command);

            // assert
            messagePublisherMock.VerifyAll();
            messagePublisherMock.VerifyNoOtherCalls();
            repoMock.VerifyAll();
            repoMock.VerifyNoOtherCalls();
            Assert.Null(result);
        }
        public async void Given_A_Non_Existing_Job_The_Handler_Should_Return_Null()
        {
            // arrange
            DateTime             date            = DateTime.Today;
            Guid                 jobId           = Guid.NewGuid();
            DateTime             actualStartTime = date.AddHours(9);
            DateTime             actualEndTime   = date.AddHours(12);
            FinishMaintenanceJob command         = new FinishMaintenanceJob(Guid.NewGuid(), jobId,
                                                                            actualStartTime, actualEndTime, "Notes");

            Mock <IMessagePublisher>           messagePublisherMock = new Mock <IMessagePublisher>(MockBehavior.Strict);
            Mock <IWorkshopPlanningRepository> repoMock             = new Mock <IWorkshopPlanningRepository>(MockBehavior.Strict);

            repoMock
            .Setup(m => m.GetWorkshopPlanningAsync(It.Is <DateTime>(p => p == date)))
            .Returns(Task.FromResult <WorkshopPlanning>(null));

            FinishMaintenanceJobCommandHandler sut =
                new FinishMaintenanceJobCommandHandler(messagePublisherMock.Object, repoMock.Object);

            // act
            var result = await sut.HandleCommandAsync(date, command);

            // assert
            messagePublisherMock.VerifyAll();
            repoMock.VerifyAll();
            Assert.Null(result);
        }
예제 #3
0
        public async void FinishMaintenanceJob_Handler_Should_Handle_Command()
        {
            // arrange
            DateTime date               = DateTime.Today;
            Guid     jobId              = Guid.NewGuid();
            DateTime startTime          = date.AddHours(8);
            DateTime endTime            = date.AddHours(11);
            DateTime actualStartTime    = date.AddHours(9);
            DateTime actualEndTime      = date.AddHours(12);
            var      initializingEvents = new Event[] {
                new WorkshopPlanningCreatedEventBuilder()
                .WithDate(date)
                .Build(),
                new MaintenanceJobPlannedEventBuilder()
                .WithStartTime(startTime)
                .WithEndTime(endTime)
                .WithJobId(jobId)
                .Build()
            };
            WorkshopPlanning planning = new WorkshopPlanning(initializingEvents);

            FinishMaintenanceJob command = new FinishMaintenanceJobCommandBuilder()
                                           .WithJobId(jobId)
                                           .WithActualStartTime(actualStartTime)
                                           .WithActualEndTime(actualEndTime)
                                           .Build();

            Mock <IMessagePublisher>           messagePublisherMock = new Mock <IMessagePublisher>(MockBehavior.Strict);
            Mock <IWorkshopPlanningRepository> repoMock             = new Mock <IWorkshopPlanningRepository>(MockBehavior.Strict);

            repoMock
            .Setup(m => m.GetWorkshopPlanningAsync(It.Is <DateTime>(p => p == date)))
            .Returns(Task.FromResult(planning));

            repoMock
            .Setup(m => m.SaveWorkshopPlanningAsync(
                       It.Is <string>(p => p == planning.Id),
                       It.Is <int>(p => p == 2),
                       It.Is <int>(p => p == 3),
                       It.IsAny <IEnumerable <Event> >()
                       ))
            .Returns(Task.CompletedTask);

            messagePublisherMock
            .Setup(m => m.PublishMessageAsync(
                       It.Is <string>(p => p == "MaintenanceJobFinished"),
                       It.IsAny <object>(),
                       ""))
            .Returns(Task.CompletedTask);

            FinishMaintenanceJobCommandHandler sut =
                new FinishMaintenanceJobCommandHandler(messagePublisherMock.Object, repoMock.Object);

            // act
            await sut.HandleCommandAsync(date, command);

            // assert
            messagePublisherMock.VerifyAll();
            repoMock.VerifyAll();
        }
        public async void FinishMaintenanceJob_Handler_Should_Handle_Command()
        {
            // arrange
            DateTime date               = DateTime.Today;
            Guid     jobId              = Guid.NewGuid();
            DateTime startTime          = date.AddHours(8);
            DateTime endTime            = date.AddHours(11);
            DateTime actualStartTime    = date.AddHours(9);
            DateTime actualEndTime      = date.AddHours(12);
            var      customerInfo       = ("customer id", "customer name", "123456780");
            var      vehicleInfo        = ("AB-123-C", "Volkswagen", "Tiguan");
            string   description        = "Job description";
            var      initializingEvents = new Event[] {
                new WorkshopPlanningCreated(Guid.NewGuid(), date),
                new MaintenanceJobPlanned(Guid.NewGuid(), jobId, startTime, endTime,
                                          customerInfo, vehicleInfo, description)
            };
            WorkshopPlanning planning = new WorkshopPlanning(initializingEvents);

            FinishMaintenanceJob command = new FinishMaintenanceJob(Guid.NewGuid(), jobId,
                                                                    actualStartTime, actualEndTime, "Notes");

            Mock <IMessagePublisher>           messagePublisherMock = new Mock <IMessagePublisher>(MockBehavior.Strict);
            Mock <IWorkshopPlanningRepository> repoMock             = new Mock <IWorkshopPlanningRepository>(MockBehavior.Strict);

            repoMock
            .Setup(m => m.GetWorkshopPlanningAsync(It.Is <DateTime>(p => p == date)))
            .Returns(Task.FromResult(planning));

            repoMock
            .Setup(m => m.SaveWorkshopPlanningAsync(
                       It.Is <string>(p => p == planning.Id),
                       It.Is <int>(p => p == 2),
                       It.Is <int>(p => p == 3),
                       It.IsAny <IEnumerable <Event> >()
                       ))
            .Returns(Task.CompletedTask);

            messagePublisherMock
            .Setup(m => m.PublishMessageAsync(
                       It.Is <string>(p => p == "MaintenanceJobFinished"),
                       It.IsAny <object>(),
                       ""))
            .Returns(Task.CompletedTask);

            FinishMaintenanceJobCommandHandler sut =
                new FinishMaintenanceJobCommandHandler(messagePublisherMock.Object, repoMock.Object);

            // act
            await sut.HandleCommandAsync(date, command);

            // assert
            messagePublisherMock.VerifyAll();
            repoMock.VerifyAll();
        }