public async Task AssignRequestsToTheItinerary()
        {
            var mockMediator   = new Mock <IMediator>();
            var dateTimeUtcNow = DateTime.UtcNow;

            var handler = new AddRequestsToItineraryCommandHandler(Context, mockMediator.Object)
            {
                DateTimeUtcNow = () => dateTimeUtcNow
            };
            var succeded = await handler.Handle(new AddRequestsToItineraryCommand
            {
                ItineraryId     = _theItinerary.Id,
                RequestIdsToAdd = new List <string> {
                    _notAssignedRequest.RequestId.ToString()
                }
            });

            Assert.True(succeded);
            Assert.Equal(RequestStatus.Assigned, _notAssignedRequest.Status);
            Assert.Equal(1, Context.ItineraryRequests.Count());
            Assert.Equal(_theItinerary.Id, Context.ItineraryRequests.First().ItineraryId);
            Assert.Equal(1, Context.ItineraryRequests.First().OrderIndex);
            Assert.Equal(_notAssignedRequest.RequestId, Context.ItineraryRequests.First().RequestId);
            Assert.Equal(dateTimeUtcNow, Context.ItineraryRequests.First().DateAssigned);
        }
        public async Task AbortOnNotFoundRequests()
        {
            var mockMediator = new Mock<IMediator>();

            var handler = new AddRequestsToItineraryCommandHandler(Context, mockMediator.Object);
            var succeded = await handler.Handle(new AddRequestsToItineraryCommand { ItineraryId = _theItinerary.Id, RequestIdsToAdd = new List<string> { "7" } });

            Assert.False(succeded);
            Assert.Empty(Context.ItineraryRequests);
        }
        public async Task AbortOnNotFoundItinerary()
        {
            var mockMediator = new Mock<IMediator>();

            var handler = new AddRequestsToItineraryCommandHandler(Context, mockMediator.Object);
            var succeded = await handler.Handle(new AddRequestsToItineraryCommand { ItineraryId = 7 });

            Assert.False(succeded);
            Assert.Empty(Context.ItineraryRequests);
        }
Esempio n. 4
0
        public async Task AbortOnNotFoundItinerary()
        {
            var mockMediator = new Mock <IMediator>();

            var handler  = new AddRequestsToItineraryCommandHandler(Context, mockMediator.Object);
            var succeded = await handler.Handle(new AddRequestsToItineraryCommand { ItineraryId = 7 });

            Assert.False(succeded);
            Assert.Empty(Context.ItineraryRequests);
        }
Esempio n. 5
0
        public async Task AbortOnNotFoundRequests()
        {
            var mockMediator = new Mock <IMediator>();

            var handler  = new AddRequestsToItineraryCommandHandler(Context, mockMediator.Object);
            var succeded = await handler.Handle(new AddRequestsToItineraryCommand { ItineraryId = _theItinerary.Id, RequestIdsToAdd = new List <string> {
                                                                                        "7"
                                                                                    } });

            Assert.False(succeded);
            Assert.Empty(Context.ItineraryRequests);
        }
        public async Task NotAlterTheAlreadyAssignedRequests()
        {
            var mockMediator = new Mock<IMediator>();

            var handler = new AddRequestsToItineraryCommandHandler(Context, mockMediator.Object);
            var succeded = await handler.Handle(new AddRequestsToItineraryCommand
            {
                ItineraryId = _theItinerary.Id,
                RequestIdsToAdd = new List<string> { _assignedRequest.RequestId.ToString() }
            });

            Assert.True(succeded);
            Assert.Empty(Context.ItineraryRequests);
        }
Esempio n. 7
0
        public async Task NotAlterTheAlreadyAssignedRequests()
        {
            var mockMediator = new Mock <IMediator>();

            var handler  = new AddRequestsToItineraryCommandHandler(Context, mockMediator.Object);
            var succeded = await handler.Handle(new AddRequestsToItineraryCommand
            {
                ItineraryId     = _theItinerary.Id,
                RequestIdsToAdd = new List <string> {
                    _assignedRequest.RequestId.ToString()
                }
            });

            Assert.True(succeded);
            Assert.Empty(Context.ItineraryRequests);
        }
Esempio n. 8
0
        public async Task PublishRequestsAssignedToItinerary_WithTheCorrectParameters()
        {
            var mockMediator = new Mock <IMediator>();
            var message      = new AddRequestsToItineraryCommand
            {
                ItineraryId     = _theItinerary.Id,
                RequestIdsToAdd = new List <string> {
                    _notAssignedRequest.RequestId.ToString()
                }
            };

            var handler = new AddRequestsToItineraryCommandHandler(Context, mockMediator.Object);
            await handler.Handle(message);

            mockMediator.Verify(x => x.PublishAsync(It.Is <RequestsAssignedToItinerary>(y => y.ItineraryId == message.ItineraryId)));
        }
Esempio n. 9
0
        public async Task MaintainTheOrderingOfTheItineraryRequests()
        {
            var mockMediator = new Mock <IMediator>();

            Context.ItineraryRequests.Add(new ItineraryRequest {
                OrderIndex = 1, ItineraryId = _theItinerary.Id
            });
            Context.SaveChanges();

            var handler  = new AddRequestsToItineraryCommandHandler(Context, mockMediator.Object);
            var succeded = await handler.Handle(new AddRequestsToItineraryCommand
            {
                ItineraryId     = _theItinerary.Id,
                RequestIdsToAdd = new List <string> {
                    _notAssignedRequest.RequestId.ToString()
                }
            });

            Assert.True(succeded);
            Assert.Equal(2, Context.ItineraryRequests.Count());
            Assert.True(Context.ItineraryRequests.Any(ir => ir.OrderIndex == 2));
        }
        public async Task AssignRequestsToTheItinerary()
        {
            var mockMediator = new Mock<IMediator>();

            var handler = new AddRequestsToItineraryCommandHandler(Context, mockMediator.Object);
            var succeded = await handler.Handle(new AddRequestsToItineraryCommand
            {
                ItineraryId = _theItinerary.Id,
                RequestIdsToAdd = new List<string> { _notAssignedRequest.RequestId.ToString() }
            });

            Assert.True(succeded);
            Assert.Equal(RequestStatus.Assigned, _notAssignedRequest.Status);
            Assert.Equal(1, Context.ItineraryRequests.Count());
            Assert.Equal(1, Context.ItineraryRequests.First().OrderIndex);
            Assert.Equal(_theItinerary.Id, Context.ItineraryRequests.First().ItineraryId);
            Assert.Equal(_notAssignedRequest.RequestId, Context.ItineraryRequests.First().RequestId);
        }
        public async Task MaintainTheOrderingOfTheItineraryRequests()
        {
            var mockMediator = new Mock<IMediator>();
            Context.ItineraryRequests.Add(new ItineraryRequest { OrderIndex = 1, ItineraryId = _theItinerary.Id });
            Context.SaveChanges();

            var handler = new AddRequestsToItineraryCommandHandler(Context, mockMediator.Object);
            var succeded = await handler.Handle(new AddRequestsToItineraryCommand
            {
                ItineraryId = _theItinerary.Id,
                RequestIdsToAdd = new List<string> { _notAssignedRequest.RequestId.ToString() }
            });

            Assert.True(succeded);
            Assert.Equal(2, Context.ItineraryRequests.Count());
            Assert.True(Context.ItineraryRequests.Any(ir => ir.OrderIndex == 2));
        }
        public async Task PublishRequestsAssignedToItinerary_WithTheCorrectParameters()
        {
            var mockMediator = new Mock<IMediator>();
            var message = new AddRequestsToItineraryCommand
            {
                ItineraryId = _theItinerary.Id,
                RequestIdsToAdd = new List<string> {_notAssignedRequest.RequestId.ToString()}
            };

            var handler = new AddRequestsToItineraryCommandHandler(Context, mockMediator.Object);
            await handler.Handle(message);

            mockMediator.Verify(x => x.PublishAsync(It.Is<RequestsAssignedToItinerary>(y => y.ItineraryId == message.ItineraryId)));
        }