public void _SaveGeneralInfo_ValidRequest_ReturnsJsonResult()
        {
            // Arrange
            var @event = new Event();

            @event.FillWithDefaultValues();
            @event = _context.Events.Add(@event);

            var edition = new Edition();

            edition.FillWithDefaultValues(@event);
            edition = _context.Editions.Add(edition);

            var editionTranslation = new EditionTranslation();

            editionTranslation.FillWithDefaultValues(edition);
            _context.EditionTranslations.Add(editionTranslation);

            var eventDirector = new EventDirector();

            eventDirector.FillWithDefaultValues(@event);
            eventDirector.IsPrimary = true;
            _context.EventDirectors.Add(eventDirector);

            _context.SaveChanges();

            var model = Mapper.Map <Edition, EditionEditGeneralInfoModel>(edition);

            // Act
            var result = _controller._SaveGeneralInfo(model);

            // Assert
            Assert.IsInstanceOf <JsonResult>(result);
            Assert.IsTrue(result.GetValue <bool>("success"));
        }
        public void Edit_ValidRequest_ReturnsEditionEditModel()
        {
            // Arrange
            var @event = new Event();

            @event.FillWithDefaultValues();
            @event = _context.Events.Add(@event);

            var edition = new Edition();

            edition.FillWithDefaultValues(@event);
            edition = _context.Editions.Add(edition);

            var eventDirector = new EventDirector();

            eventDirector.FillWithDefaultValues(@event);
            _context.EventDirectors.Add(eventDirector);

            _context.SaveChanges();

            // Act
            var result = _controller.Edit(edition.EditionId, null);

            // Assert
            Assert.IsInstanceOf <EditionEditModel>(((ViewResult)result).Model);
            Assert.AreEqual(edition.EditionId, ((EditionEditModel)((ViewResult)result).Model).EditionId);
        }
        public void Delete_ValidRequest_RedirectsToIndexAction()
        {
            // Arrange
            var @event = new Event();

            @event.FillWithDefaultValues();
            @event = _context.Events.Add(@event);

            var edition = new Edition();

            edition.FillWithDefaultValues(@event);
            edition.Status = (byte)EditionStatusType.Draft.GetHashCode();
            edition        = _context.Editions.Add(edition);

            var eventDirector = new EventDirector();

            eventDirector.FillWithDefaultValues(@event);
            eventDirector.IsPrimary = true;
            _context.EventDirectors.Add(eventDirector);

            _context.SaveChanges();

            // Act
            var result = _controller.Delete(edition.EditionId);

            // Assert
            Assert.IsInstanceOf <RedirectToRouteResult>(result);
        }
        public void Index_ValidRequest_ReturnsEditionIndexModel()
        {
            // Arrange
            var @event = new Event();

            @event.FillWithDefaultValues();
            @event = _context.Events.Add(@event);

            var edition = new Edition();

            edition.FillWithDefaultValues(@event);
            edition = _context.Editions.Add(edition);

            var eventDirector = new EventDirector();

            eventDirector.FillWithDefaultValues(@event);
            _context.EventDirectors.Add(eventDirector);

            _context.SaveChanges();

            // Act
            var result = _controller.Index(edition.EventId);

            // Assert
            Assert.IsInstanceOf <EditionIndexModel>(result.Model);
            Assert.AreEqual(1, ((EditionIndexModel)result.Model).Editions.Count);
        }
        public void Index_ValidRequest_ReturnsNotifications()
        {
            // Arrange
            var @event = new Event();

            @event.FillWithDefaultValues();
            @event = _context.Events.Add(@event);

            var edition = new Edition();

            edition.FillWithDefaultValues(@event);
            edition = _context.Editions.Add(edition);

            var notification = new Notification();

            notification.FillWithDefaultValues(edition);
            _context.Notifications.Add(notification);

            _context.SaveChanges();

            // Act
            var result = _controller.Index();

            // Assert
            Assert.IsInstanceOf <NotificationListModel>(result.Model);
            Assert.AreEqual(1, ((NotificationListModel)result.Model).Notifications.Count);
        }
        public void _GetNotifications_UserHasTwoNotifications_ReturnsTwoNotifications()
        {
            // Arrange
            var @event = new Event();

            @event.FillWithDefaultValues();
            @event = _context.Events.Add(@event);

            var edition = new Edition();

            edition.FillWithDefaultValues(@event);
            edition = _context.Editions.Add(edition);

            var notification = new Notification();

            notification.FillWithDefaultValues(edition);
            notification.Displayed = false;
            _context.Notifications.Add(notification);
            notification = new Notification();
            notification.FillWithDefaultValues(edition);
            notification.Displayed = false;
            _context.Notifications.Add(notification);

            _context.SaveChanges();

            _controller.ViewEngineResultFunc = delegate { return(""); };

            // Act
            var result = _controller._GetNotifications();

            // Assert
            Assert.IsInstanceOf <JsonResult>(result);
            Assert.AreEqual(2, result.GetValue <int>("count"));
        }
        public void _ReadAllNotifications_OneNotificationExists_ReturnsZero()
        {
            // Arrange
            var @event = new Event();

            @event.FillWithDefaultValues();
            @event = _context.Events.Add(@event);

            var edition = new Edition();

            edition.FillWithDefaultValues(@event);
            edition = _context.Editions.Add(edition);

            var notification = new Notification();

            notification.FillWithDefaultValues(edition);
            notification.Displayed = false;
            _context.Notifications.Add(notification);

            _context.SaveChanges();

            // Act
            var result = _controller._ReadAllNotifications();

            // Assert
            Assert.IsInstanceOf <JsonResult>(result);
            Assert.AreEqual(true, result.GetValue <bool>("success"));
        }
        public void _SearchNotifications_MultiTypeOfNotificationsExist_ReturnsOnlySelectedTypeOfNotifications()
        {
            // Arrange
            var expectedNotificationType   = NotificationType.GeneralInfoCompleteness;
            var unexpectedNotificationType = NotificationType.PostShowMetricsInfoCompleteness;

            var @event = new Event();

            @event.FillWithDefaultValues();
            @event = _context.Events.Add(@event);

            var edition = new Edition();

            edition.FillWithDefaultValues(@event);
            edition = _context.Editions.Add(edition);

            var notification = new Notification();

            notification.FillWithDefaultValues(edition);
            notification.NotificationType = (byte)expectedNotificationType.GetHashCode();
            notification.Displayed        = false;
            _context.Notifications.Add(notification);
            notification = new Notification();
            notification.FillWithDefaultValues(edition);
            notification.NotificationType = (byte)unexpectedNotificationType.GetHashCode();
            notification.Displayed        = false;
            _context.Notifications.Add(notification);

            _context.SaveChanges();

            // Act
            var result = _controller._SearchNotifications(new[] { expectedNotificationType }, null);

            // Assert
            Assert.IsInstanceOf <PartialViewResult>(result);
            Assert.AreEqual(true, ((IList <NotificationListItemModel>)result.Model).Any(x => x.Type == expectedNotificationType));
            Assert.AreEqual(true, ((IList <NotificationListItemModel>)result.Model).All(x => x.Type != unexpectedNotificationType));
        }