public void StartScrobble(TraktPluginSettings settings, MediaItem mediaItem, ITraktClient traktClient, ITraktNotification notification)
        {
            // Arrange
            IMediaPortalServices mediaPortalServices = Substitute.For <IMediaPortalServices>();

            mediaPortalServices.GetTraktUserHomePath().Returns(DataPath);
            SetSettings(mediaPortalServices, settings);
            SetPlayerAndContentDirForMovie(mediaPortalServices, mediaItem);

            IAsynchronousMessageQueue messageQueue = GetMockedMsgQueue(mediaPortalServices);

            IFileOperations fileOperations = Substitute.For <IFileOperations>();

            fileOperations.FileExists(Path.Combine(DataPath, FileName.Authorization.Value)).Returns(true);

            TraktScrobbleHandlerManager      traktScrobbleHandler = new TraktScrobbleHandlerManager(mediaPortalServices, traktClient, fileOperations);
            TraktScrobbleStartedNotification expectedNotification = (TraktScrobbleStartedNotification)notification;

            // Act
            // start the player
            messageQueue.MessageReceivedProxy += Raise.Event <MessageReceivedHandler>(new AsynchronousMessageQueue(new object(), new[] { "PlayerManager" }),
                                                                                      GetSystemMessageForMessageType(PlayerManagerMessaging.MessageType.PlayerStarted));

            // Assert
            mediaPortalServices.GetTraktNotificationModel().Received()
            .ShowNotification(Arg.Is <TraktScrobbleStartedNotification>(x => x.IsSuccess == expectedNotification.IsSuccess &&
                                                                        x.Message == expectedNotification.Message &&
                                                                        x.ActionType == expectedNotification.ActionType &&
                                                                        x.Progress == expectedNotification.Progress &&
                                                                        x.SuperLayerScreenName == expectedNotification.SuperLayerScreenName),
                              Arg.Any <TimeSpan>());
        }
Example #2
0
        public void ShouldSyncLibraryWhenShareImportCompletedIsWithSuccess()
        {
            // Arrange
            IMediaPortalServices mediaPortalServices = Substitute.For <IMediaPortalServices>();

            mediaPortalServices.GetTraktUserHomePath().Returns(DataPath);
            SetSettings(mediaPortalServices, new TraktPluginSettings {
                IsAutomaticLibrarySyncEnabled = true, ShowAutomaticSyncNotifications = true
            });

            IAsynchronousMessageQueue messageQueue = GetMockedMsgQueue(mediaPortalServices);

            IFileOperations fileOperations = Substitute.For <IFileOperations>();

            fileOperations.FileExists(Path.Combine(DataPath, FileName.Authorization.Value)).Returns(true);

            ILibrarySynchronization librarySynchronization = Substitute.For <ILibrarySynchronization>();

            librarySynchronization.SyncMovies().Returns(new TraktSyncMoviesResult());
            librarySynchronization.SyncSeries().Returns(new TraktSyncEpisodesResult());

            TraktSyncHandlerManager traktScrobbleHandler = new TraktSyncHandlerManager(mediaPortalServices, librarySynchronization, fileOperations);

            // Act
            // send share import completed message
            messageQueue.MessageReceivedProxy += Raise.Event <MessageReceivedHandler>(new AsynchronousMessageQueue(new object(), new[] { "ContentDirectory" }),
                                                                                      GetSystemMessageForMessageType(ContentDirectoryMessaging.MessageType.ShareImportCompleted));

            // Assert
            mediaPortalServices.GetTraktNotificationModel().Received().ShowNotification(Arg.Any <TraktSyncLibrarySuccessNotification>(), Arg.Any <TimeSpan>());
        }
Example #3
0
 private void UnsubscribeFromMessages()
 {
     if (_messageQueue != null)
     {
         _messageQueue.ShutdownProxy();
         _messageQueue = null;
     }
 }
        private IAsynchronousMessageQueue GetMockedMsgQueue(IMediaPortalServices mediaPortalServices)
        {
            IAsynchronousMessageQueue messageQueue = Substitute.For <IAsynchronousMessageQueue>();

            messageQueue.When(x => x.StartProxy()).Do(x => { /*nothing*/ });
            mediaPortalServices.GetMessageQueue(Arg.Any <object>(), Arg.Any <string[]>()).Returns(messageQueue);
            return(messageQueue);
        }
Example #5
0
 private void SubscribeToMessages()
 {
     if (_messageQueue == null)
     {
         _messageQueue = _mediaPortalServices.GetMessageQueue(this, new string[]
         {
             PlayerManagerMessaging.CHANNEL
         });
         _messageQueue.MessageReceivedProxy += OnMessageReceived;
         _messageQueue.StartProxy();
     }
 }