public void ScenarioPlayTest()
        {
            using (RecorderManager.NewRecordingSession("test"))
            {
                // Make a callee, not really used but needed to record a constructor call:
                MockingProxy callee = new MockingProxy(typeof(Sample.Account), null, "m1");

                // Push some calls in the recorder:
                MockableCall lastcall;
                CurrentRecorder.RecordCall(lastcall = new MockableCall(callee, typeof(Sample.Account).GetConstructor(new Type[] { typeof(Sample.CurrencyUnit) }), null));
                lastcall.SetConstructionResult("acc");
                CurrentRecorder.RecordCall(lastcall = new MockableCall(callee, typeof(Sample.Account).GetMethod("Deposit"), null));
                lastcall.SetCallResult();
                CurrentRecorder.RecordCall(lastcall = new MockableCall(callee, typeof(Sample.Account).GetMethod("Withdraw"), null));
                lastcall.SetCallResult();
                CurrentRecorder.RecordCall(lastcall = new MockableCall(callee, typeof(Sample.Account).GetProperty("Balance").GetGetMethod(), null));
                lastcall.SetCallResult(10m);
            }

            using (RecorderManager.NewPlayBackSession("test", true))
            {
                // Register types to mock:
                MockService.AddTypeToMock(typeof(Sample.Account));

                // Play scenario:
                Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
                acc.Deposit(100m);
                acc.Withdraw(25m);
                Decimal balance = acc.Balance;

                // Checks:
                Assert.AreEqual(10m, balance);                 // Does not match the scenario, but the mocking result !
            }
        }
Exemplo n.º 2
0
        //***********************************************************************************************************************************************************************************************************

        private async void PlayerApp_OnPlayerConnectionTokenExpired(object sender, PlayerConnectionTokenExpiredEventArgs e)
        {
            _logHandle.Report(new LogEventWarning("Connection token expired (was valid for " + e.ConnectionTokenExpirationTime.TotalSeconds.ToString() + " s)."));
            CurrentRecorder?.StopRecord();

            bool wasMinimized = (ProcessHelper.GetProcessWindowState(PlayerApp.PlayerName).showCmd == WindowTheme.WindowPlacement.ShowWindowStates.Minimized);

            await((App)Application.Current).StartAndConnectToPlayer(wasMinimized);
            PlayerApp.IsConnectionTokenExpired = false;
        }
Exemplo n.º 3
0
        //***********************************************************************************************************************************************************************************************************

        private void PlayerApp_OnPlayStateChange(object sender, PlayerPlayStateEventArgs e)
        {
            _logHandle.Report(new LogEventInfo(PlayerApp.PlayerName + " playback " + (e.Playing ? "started" : "paused")));

            PlayerPlaybackStatus status = PlayerApp.CurrentPlaybackStatus;

            if (e.Playing && status.Progress.TotalSeconds <= 2 && PlayerApp.CurrentTrack != null && !status.IsAd)
            {
                StartRecord();
            }
            else if (e.Playing && status.Progress.TotalSeconds > 2 && PlayerApp.CurrentTrack != null && !status.IsAd)
            {
                CurrentRecorder?.ResumeRecord();
            }
            else if (!e.Playing && PlayerApp.CurrentTrack != null && !status.IsAd)
            {
                CurrentRecorder?.PauseRecord();
            }
        }
Exemplo n.º 4
0
        //***********************************************************************************************************************************************************************************************************

        private void StartRecord()
        {
            PlayerApp.ListenForEvents = false;

            bool isPlaying = PlayerApp.CurrentPlaybackStatus.IsPlaying;

            OnPropertyChanged("AreRecorderSettingsChanged");

            CurrentRecorder?.StopRecord();

            if (!isPlaying || !IsRecorderArmed)     //Only start a new record if music is playing and the recorder is armed
            {
                PlayerApp.ListenForEvents = true;
                return;
            }

            //if (Recorders.Count > 0 && Recorders.Select(r => r.TrackInfo.TrackID).Contains(PlayerApp.CurrentTrack.TrackID))
            //{
            //    PlayerApp.ListenForEvents = true;
            //    return;
            //}

            Recorder tmpRecorder = new SpotifyRecorderImplementierung((RecorderSettings)RecSettings.Clone(), PlayerApp.CurrentTrack, _logHandle);

            tmpRecorder.OnRecorderPostStepsFinished += TmpRecorder_OnRecorderPostStepsFinished;
            Recorders.Add(tmpRecorder);

            if (PlayerApp.CurrentTrack != null && !PlayerApp.CurrentPlaybackStatus.IsAd)
            {
                tmpRecorder?.StartRecord();
            }

            CleanupRecordersList();

            PlayerApp.ListenForEvents = true;
        }
Exemplo n.º 5
0
        //##############################################################################################################################################################################################

        private async void PlayerApp_OnTrackChange(object sender, PlayerTrackChangeEventArgs e)
        {
            //#warning TESTCODE
            //PlayerApp.CurrentPlaybackStatus.IsAd = true;      //Use this for ad blocker testing

            if (PlayerApp.CurrentPlaybackStatus.IsAd)
            {
                _logHandle.Report(new LogEventInfo("Advertisement is playing"));
            }
            else
            {
                _logHandle.Report(new LogEventInfo("Track changed to \"" + e.NewTrack?.TrackName + "\" (" + e.NewTrack?.CombinedArtistsString + ")"));
            }

            bool blockAd = PlayerApp.CurrentPlaybackStatus.IsAd && IsPlayerAdblockerEnabled;

            if (blockAd)
            {
                CurrentRecorder?.StopRecord();
                bool wasPlaying   = PlayerApp.CurrentPlaybackStatus.IsPlaying;
                bool wasMinimized = (ProcessHelper.GetProcessWindowState(PlayerApp.PlayerName).showCmd == WindowTheme.WindowPlacement.ShowWindowStates.Minimized);
                if (wasPlaying)
                {
                    PlayerApp.PausePlayback();
                }

                if (blockAd)
                {
                    await Task.Delay(300);

                    await PlayerApp.ClosePlayerApplication();

                    await Task.Delay(1000);
                }

                await((App)Application.Current).StartAndConnectToPlayer(wasMinimized);
                await Task.Delay(1500);

                if (wasPlaying)
                {
                    PlayerApp.ListenForEvents = false;

                    if (blockAd)
                    {
                        PlayerApp.NextTrack();
                    }                                           // after closing and reopening spotify opens with the last played track. So skip to the next track. Skipping already starts the playback.
                    else
                    {
                        PlayerApp.StartPlayback();
                    }

                    await Task.Delay(500);

                    PlayerApp.ListenForEvents = true;
                    PlayerApp.UpdateCurrentPlaybackStatus();

                    _logHandle.Report(new LogEventInfo("Track \"" + PlayerApp.CurrentTrack?.TrackName + "\" (" + PlayerApp.CurrentTrack?.CombinedArtistsString + ")"));
                    StartRecord();
                }
                else
                {
                    PlayerApp.UpdateCurrentPlaybackStatus();
                }
            }
            else
            {
                StartRecord();
            }
        }