public async Task HandleGetInvitationsForExportQuery_ShouldFilterOnStatusCompleted()
        {
            var filter = new Filter {
                IpoStatuses = new List <IpoStatus> {
                    IpoStatus.Completed
                }
            };

            using (var context =
                       new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var invitation  = context.Invitations.Include(inv => inv.Participants).Single(inv => inv.Id == _invitation2.Id);
                var participant = invitation.Participants.Single(p => p.Id == _participantId1);
                invitation.CompleteIpo(participant, participant.RowVersion.ConvertToString(), _currentPerson, DateTime.Now);
                context.SaveChangesAsync().Wait();
            }

            using (var context =
                       new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetInvitationsForExportQuery(_projectName2, null, filter);
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);

                var result = await dut.Handle(query, default);

                AssertCount(result.Data, 1);
                var data = result.Data.Invitations.First();
                Assert.AreEqual(1, data.Participants.Where(p => p.SignedAtUtc != null).ToList().Count);
                var participant = data.Participants.Where(p => p.SignedBy != null).ToList();
                Assert.AreEqual(1, participant.Count);
                Assert.AreEqual("testusername", participant.First().SignedBy);
            }
        }
        public async Task HandleGetInvitationsForExportQuery_ShouldReturnCorrectNumberOfInvitations_NoFilter()
        {
            using (var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetInvitationsForExportQuery(_projectName);
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);

                var result = await dut.Handle(query, default);

                AssertCount(result.Data, 1);
            }
        }
        public async Task HandleGetInvitationsForExportQuery_MultipleInvitations_ShouldReturnEmptyHistory()
        {
            using (var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetInvitationsForExportQuery(_projectName2);
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);

                var result = await dut.Handle(query, default);

                AssertCount(result.Data, 2);
                Assert.IsTrue(result.Data.Invitations.All(inv => inv.History.Count == 0));
            }
        }
        public async Task HandleGetInvitationsForExportQuery_ShouldReturnOkResult()
        {
            using (var context =
                       new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);
                var query = new GetInvitationsForExportQuery(_projectName);

                var result = await dut.Handle(query, default);

                Assert.AreEqual(ResultType.Ok, result.ResultType);
            }
        }
        public async Task HandleGetInvitationsForExportQuery_ShouldReturnInvitationsByStartTime_WhenSortingDesc()
        {
            using (var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetInvitationsForExportQuery(_projectName2, new Sorting(SortingDirection.Desc, SortingProperty.PunchOutDateUtc));
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);

                var result = await dut.Handle(query, default);

                AssertCount(result.Data, 2);
                Assert.AreEqual(_invitation3.Id, result.Data.Invitations.First().Id);
                Assert.AreEqual(_invitation2.Id, result.Data.Invitations.Last().Id);
            }
        }
        public async Task HandleGetInvitationsForExportQuery_ShouldReturnCorrectDto()
        {
            using (var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetInvitationsForExportQuery(_projectName);
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);

                var result = await dut.Handle(query, default);

                var invitationDto = result.Data.Invitations.First();
                var invitation    = _invitation1;
                AssertInvitation(invitation, invitationDto);
                AssertUsedFilter(result.Data.UsedFilter);
                Assert.AreEqual(4, invitationDto.Participants.Count);
                Assert.AreEqual(1, invitationDto.History.Count);
            }
        }
        public async Task HandleGetInvitationsForExportQuery_ShouldSortOnType_Asc()
        {
            var sorting = new Sorting(SortingDirection.Asc, SortingProperty.Type);

            using (var context =
                       new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetInvitationsForExportQuery(_projectName2, sorting);
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);

                var result = await dut.Handle(query, default);

                Assert.AreEqual(_invitation3.Id, result.Data.Invitations.First().Id);
                Assert.AreEqual(_invitation2.Id, result.Data.Invitations.Last().Id);
                AssertCount(result.Data, 2);
            }
        }
        public async Task HandleGetInvitationsForExportQuery_ShouldFilterOnLastChangedAtToThreeWeeks_TwoInvitations()
        {
            var filter = new Filter {
                LastChangedAtToUtc = _timeProvider.UtcNow.AddWeeks(3)
            };

            using (var context =
                       new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetInvitationsForExportQuery(_projectName2, null, filter);
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);

                var result = await dut.Handle(query, default);

                AssertCount(result.Data, 2);
            }
        }
        public async Task HandleGetInvitationsForExportQuery_ShouldFilterOnMcPkgNoStartWith()
        {
            var filter = new Filter {
                McPkgNoStartsWith = _mcPkgNo
            };

            using (var context =
                       new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetInvitationsForExportQuery(_projectName2, null, filter);
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);

                var result = await dut.Handle(query, default);

                AssertCount(result.Data, 1);
            }
        }
        public async Task HandleGetInvitationsForExportQuery_ShouldFilterOnPunchOutDate_FromTwoWeeksInFuture()
        {
            var filter = new Filter {
                PunchOutDateFromUtc = _timeProvider.UtcNow.AddWeeks(2)
            };

            using (var context =
                       new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetInvitationsForExportQuery(_projectName2, null, filter);
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);

                var result = await dut.Handle(query, default);

                AssertCount(result.Data, 1);
            }
        }
        public async Task HandleGetInvitationsForExportQuery_ShouldFilterOnPunchOutInThisWeek_NoInvitation()
        {
            var filter = new Filter {
                PunchOutDates = new List <PunchOutDateFilterType> {
                    PunchOutDateFilterType.ThisWeek
                }
            };

            using (var context =
                       new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetInvitationsForExportQuery(_projectName2, null, filter);
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);

                var result = await dut.Handle(query, default);

                AssertCount(result.Data, 0);
            }
        }
        public async Task HandleGetInvitationsForExportQuery_ShouldFilterOnStatusAccepted()
        {
            var filter = new Filter {
                IpoStatuses = new List <IpoStatus> {
                    IpoStatus.Accepted
                }
            };

            using (var context =
                       new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetInvitationsForExportQuery(_projectName2, null, filter);
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);

                var result = await dut.Handle(query, default);

                AssertCount(result.Data, 0);
            }
        }
        public async Task HandleGetInvitationsForExportQuery_ShouldFilterOnStatusPlanned()
        {
            var filter = new Filter {
                IpoStatuses = new List <IpoStatus> {
                    IpoStatus.Planned
                }
            };

            using (var context =
                       new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetInvitationsForExportQuery(_projectName2, null, filter);
                var dut   = new GetInvitationsForExportQueryHandler(context, _plantProvider, _personRepositoryMock.Object);

                var result = await dut.Handle(query, default);

                AssertCount(result.Data, 2);
                var data = result.Data.Invitations.First();
                Assert.IsTrue(data.Participants.Count > 1);
                Assert.AreEqual(0, data.Participants.Where(p => p.SignedBy != null).ToList().Count);
                Assert.AreEqual(0, data.Participants.Where(p => p.SignedAtUtc != null).ToList().Count);
            }
        }