public void add_empty_event_to_approve_and_event_to_update()
        {
            //setup
            var request = new UpdatePendingEventRequest();

            //act
            var response = UpdateEvent(request);
        }
        public void add_new_event_with_documents_attached()
        {
            //setup
            int approvalEventId = -1;
            var updateRequest = new UpdatePendingEventRequest();
            updateRequest.IsEventApprovalEnabled = true;
            updateRequest.EventToAdd = CreatePendingRequest(approvalEventId);
            List<string> documents = new List<string>();
            documents.AddRange(new string[] { "C:\newdocument.pdf" });
            updateRequest.EventToAdd.DocumentsPath = documents;

            //act
            var updateResponse = UpdateEvent(updateRequest);

            //assert
            using (var context = _objectContextFactory.CreateObjectContext())
            {
                var addEvent = context.CreateObjectSet<Event>().SingleOrDefault(e => e.Id == updateResponse.EventToAddId);

                Assert.IsNotNull(addEvent);
                Assert.IsNotNull(addEvent.EventDocuments);
                Assert.AreEqual(addEvent.EventDocuments.Select(ed => ed.DocumentPath).First(), updateRequest.EventToAdd.DocumentsPath.First());
            }
        }
        public void add_new_event_with_event_approval_enabled()
        {
            //setup
            int approvalEventId = -1;
            var updateRequest = new UpdatePendingEventRequest();
            updateRequest.IsEventApprovalEnabled = true;
            updateRequest.EventToAdd = CreatePendingRequest(approvalEventId);

            //act
            var updateResponse = UpdateEvent(updateRequest);

            //assert
            using (var context = _objectContextFactory.CreateObjectContext())
            {
                var updateEvent = context.CreateObjectSet<Event>().SingleOrDefault(e => e.Id == updateResponse.EventToAddId);
                Assert.AreEqual(updateRequest.EventToAdd.PublishDate, updateEvent.PublishDate);
                Assert.AreEqual(updateRequest.EventToAdd.UnpublishDate, updateEvent.UnpublishDate);

                var eventTopicsIds = updateEvent.EventTopicAssociations.Select(e => e.EventTopicId).ToList();
                Assert.That(eventTopicsIds.All(e => updateRequest.EventToAdd.EventTopicIds.Contains(e)));

                var eventTypesIds = updateEvent.EventTypeAssociations.Select(e => e.EventTypeId).ToList();
                Assert.That(eventTypesIds.All(e => updateRequest.EventToAdd.EventTopicIds.Contains(e)));
                Assert.AreEqual(updateRequest.EventToAdd.Cost, updateEvent.Cost);
                Assert.AreEqual(updateRequest.EventToAdd.IsEnabled, updateEvent.IsEnabled);

                Assert.AreEqual(updateRequest.EventToAdd.Title, updateEvent.Title);
                Assert.AreEqual(updateRequest.EventToAdd.SummaryDescription, updateEvent.SummaryDescription);
                Assert.AreEqual(updateRequest.EventToAdd.DirectUrl.ToLowerInvariant(), updateEvent.DirectUrl.ToLowerInvariant());

                Assert.AreEqual(approvalEventId, updateRequest.EventToAdd.ApprovalEventId.Value);
                Assert.AreEqual(updateRequest.EventToAdd.ApprovalStatus, updateEvent.ApprovalStatus);

                Assert.AreEqual(updateEvent.Id, updateResponse.EventToAddId);
                Assert.AreEqual(updateEvent.Id, updateResponse.EventRedirectId);
                Assert.AreEqual(updateEvent.Title, updateResponse.EventRedirectTitle);
            }
        }
 private UpdatePendingEventResponse UpdateEvent(UpdatePendingEventRequest request)
 {
     var handler = CreateUpdatePendingEventHandler();
     var response = HandleRequest<UpdatePendingEventResponse>(handler, request);
     return response;
 }
        public void update_new_pending_event_with_event_approval_enabled()
        {
            //eventtoadd = the new pending event
            //eventtoupdate = the approved event
            //setup
            var addRequest = CreateApprovedRequest();
            var addResponse = AddEvent(addRequest);
            int addedEventId = 0;
            using (var context = _objectContextFactory.CreateObjectContext())
            {
                var addedEvent = context.CreateObjectSet<Event>().SingleOrDefault(e => e.Id == addResponse.Id);
                addedEventId = addedEvent.Id;
            }

            var updateRequest = new UpdatePendingEventRequest();
            updateRequest.IsEventApprovalEnabled = true;
            updateRequest.EventToAdd = CreatePendingRequest(addedEventId);
            updateRequest.EventToUpdate = CreateUpdateRequest(addedEventId);

            //act
            var updateResponse = UpdateEvent(updateRequest);

            //assert
            using (var context = _objectContextFactory.CreateObjectContext())
            {
                var updateEvent = context.CreateObjectSet<Event>().SingleOrDefault(e => e.Id == updateResponse.EventToUpdateId);
                var addedEvent = context.CreateObjectSet<Event>().SingleOrDefault(e => e.Id == updateResponse.EventToAddId);

                Assert.IsNotNull(addedEvent);
                Assert.IsNotNull(updateEvent);

                Assert.AreEqual(updateRequest.EventToAdd.ApprovalEventId, addedEvent.ApprovalEventId);
                Assert.AreEqual(addedEventId, updateRequest.EventToUpdate.Id);
                Assert.AreEqual(updateResponse.EventToUpdateId, updateEvent.Id);
                Assert.AreEqual(updateResponse.EventToAddId, addedEvent.Id);

                Assert.AreNotEqual(_testUpdateEventTitle, updateEvent.Title);
                Assert.AreNotEqual(_testUpdateEventDescription, updateEvent.SummaryDescription);
                Assert.AreNotEqual(_testUpdateDirectUrl, updateEvent.DirectUrl);

                Assert.AreEqual(_testEventTitle, addedEvent.Title);
                Assert.AreEqual(_testEventDescription, addedEvent.SummaryDescription);
                Assert.AreEqual(_testDirectUrlPending.ToLowerInvariant(), addedEvent.DirectUrl.ToLowerInvariant());
            }
        }
        public void update_event_with_event_approval_not_enabled()
        {
            //setup
            var addRequest = CreateApprovedRequest();
            var addResponse = AddEvent(addRequest);
            int addedEventId = 0;
            using (var context = _objectContextFactory.CreateObjectContext())
            {
                var addedEvent = context.CreateObjectSet<Event>().SingleOrDefault(e => e.Id == addResponse.Id);
                addedEventId = addedEvent.Id;
            }
            var updateRequest = new UpdatePendingEventRequest();
            updateRequest.IsEventApprovalEnabled = false;
            updateRequest.EventToUpdate = CreateUpdateApprovedRequest(addedEventId);
            int approvalEventId = -1;

            //act
            var updateResponse = UpdateEvent(updateRequest);

            //assert
            using (var context = _objectContextFactory.CreateObjectContext())
            {
                var updateEvent = context.CreateObjectSet<Event>().SingleOrDefault(e => e.Id == updateResponse.EventToUpdateId);
                Assert.AreEqual(updateRequest.EventToUpdate.PublishDate, updateEvent.PublishDate);
                Assert.AreEqual(updateRequest.EventToUpdate.UnpublishDate, updateEvent.UnpublishDate);

                var eventTopicsIds = updateRequest.EventToUpdate.EventTopicIds.ToList();
                Assert.That(eventTopicsIds.All(e => updateEvent.EventTopicAssociations.Select(a=>a.EventTopicId).ToList().Contains(e)));
                var eventTypesIds = updateRequest.EventToUpdate.EventTypeIds.ToList();
                Assert.That(eventTypesIds.All(e => updateEvent.EventTypeAssociations.Select(a=>a.EventTypeId).ToList().Contains(e)));

                Assert.AreEqual(updateRequest.EventToUpdate.Cost, updateEvent.Cost);
                Assert.AreEqual(updateRequest.EventToUpdate.IsEnabled, updateEvent.IsEnabled);

                Assert.AreEqual(updateRequest.EventToUpdate.Title, updateEvent.Title);
                Assert.AreEqual(updateRequest.EventToUpdate.SummaryDescription, updateEvent.SummaryDescription);
                Assert.AreEqual(updateRequest.EventToUpdate.DirectUrl.ToLowerInvariant(), updateEvent.DirectUrl.ToLowerInvariant());

                Assert.AreEqual(approvalEventId, updateRequest.EventToUpdate.ApprovalEventId.Value);
                Assert.AreEqual(updateRequest.EventToUpdate.ApprovalStatus, updateEvent.ApprovalStatus);

                Assert.AreEqual(updateEvent.Id, updateResponse.EventToUpdateId);
                Assert.AreEqual(updateEvent.Id, updateResponse.EventRedirectId);
                Assert.AreEqual(updateEvent.Title, updateResponse.EventRedirectTitle);
            }
        }