public void MusicPlayer_Set_PlayList_Change_Track()
        {
            //arrange
            IMusicFactory imf = Substitute.For<IMusicFactory>();
            IInternalPlayer iip = Substitute.For<IInternalPlayer>();
            imf.GetInternalPlayer().Returns(iip);

            MusicPlayer target = new MusicPlayer(imf);

            IReadOnlyPlayList irop = Substitute.For<IReadOnlyPlayList>();
            IInternalTrack it = Substitute.For<IInternalTrack>();
            it.Path.Returns("MyPath");
            irop.CurrentTrack = it;

            target.PlayList = irop;

            IInternalTrack it2 = Substitute.For<IInternalTrack>();
            it2.Path.Returns("MyPath2");

            target.MonitorEvents();

            //act

            irop.ChangeCurrent(it2);

            //assert
            iip.FileSource.Should().Be("MyPath2");
            iip.Received().Play();
            target.ShouldRaisePropertyChangeFor(t => t.MusicTrackSource);

            target.Mode.Should().Be(PlayMode.Play);
            target.MusicTrackSource.Should().Be(it2);

            //clean
            target.Dispose();
        }
        public void MusicPlayer_Set_PlayList_CurrentTrack_Null()
        {
            //arrange
            IMusicFactory imf = Substitute.For<IMusicFactory>();
            IInternalPlayer iip = Substitute.For<IInternalPlayer>();
            imf.GetInternalPlayer().Returns(iip);

            MusicPlayer target = new MusicPlayer(imf);

            IReadOnlyPlayList irop = Substitute.For<IReadOnlyPlayList>();
            irop.CurrentTrack = null;

            target.MonitorEvents();           
            
            //act
            target.PlayList = irop;

            //assert
            target.PlayList.Should().Be(irop);
            target.ShouldRaisePropertyChangeFor(t => t.PlayList);
            target.Mode.Should().Be( PlayMode.Stopped);

            target.Dispose();
        }
        public void MusicPlayer_Play_Do_NotPlay_Broken()
        {
            //arrange
            IMusicFactory imf = Substitute.For<IMusicFactory>();
            IInternalPlayer iip = Substitute.For<IInternalPlayer>();
            imf.GetInternalPlayer().Returns(iip);
            iip.FileSource = null;

            IReadOnlyPlayList irop = Substitute.For<IReadOnlyPlayList>();
            IInternalTrack it = Substitute.For<IInternalTrack>();
            it.Path.Returns("MyPath");
            it.IsBroken.Returns(true);
            irop.CurrentTrack.Returns(it);


            // act
            MusicPlayer target = new MusicPlayer(imf);
            target.MonitorEvents();
            target.PlayList = irop;
          

            //assert
            target.PlayList.Should().Be(irop);
            target.MusicTrackSource.Should().Be(it);
            target.Mode.Should().Be(PlayMode.Stopped);
            target.ShouldRaisePropertyChangeFor(t => t.PlayList);
            target.ShouldRaisePropertyChangeFor(t => t.MusicTrackSource);
            iip.FileSource.Should().Be("MyPath");
            iip.DidNotReceive().Play();
            irop.DidNotReceive().Init();
            iip.Listener.Should().Be(target);

            //act2 
            target.Pause();

            //assert2
            target.Mode.Should().Be(PlayMode.Stopped);
            iip.DidNotReceive().Pause();

            //act2 
            target.Stop();

            //assert2
            target.Mode.Should().Be(PlayMode.Stopped);

        }
        public void MusicPlayer_Play_Do_NotPlay_UnderEdit()
        {
            //arrange
            IMusicFactory imf = Substitute.For<IMusicFactory>();
            IInternalPlayer iip = Substitute.For<IInternalPlayer>();
            imf.GetInternalPlayer().Returns(iip);
            iip.FileSource = null;

            IReadOnlyPlayList irop = Substitute.For<IReadOnlyPlayList>();
            IInternalTrack it = Substitute.For<IInternalTrack>();
            it.Path.Returns("MyPath");
            it.InternalState.Returns(ObjectState.UnderEdit);
            irop.CurrentTrack.Returns(it);


            // act
            MusicPlayer target = new MusicPlayer(imf);
            target.MonitorEvents();
            target.PlayList = irop;


            //assert
            target.PlayList.Should().Be(irop);
            target.MusicTrackSource.Should().Be(it);
            target.Mode.Should().Be(PlayMode.Stopped);
            target.ShouldRaisePropertyChangeFor(t => t.PlayList);
            target.ShouldRaisePropertyChangeFor(t => t.MusicTrackSource);
            iip.FileSource.Should().Be("MyPath");
            iip.DidNotReceive().Play();
            irop.DidNotReceive().Init();
            iip.Listener.Should().Be(target);

            //act2
            target.Pause();

            //assert2 
            target.Mode.Should().Be(PlayMode.Stopped);
            iip.DidNotReceive().Pause();

            //act3
            target.Stop();

            //assert3
            target.Mode.Should().Be(PlayMode.Stopped);
            iip.DidNotReceive().Play();


            //act4
            IInternalMusicPlayer iimp = target;
            it.UpdatedState.Returns(ObjectState.Available);
            it.InternalState.Returns(ObjectState.Available);
            iimp.OnLockEvent(it, new ObjectStateChangeArgs(it, ObjectState.UnderEdit, ObjectState.Available));

            target.Play();

            //assert4
            target.Mode.Should().Be(PlayMode.Play);

        }
        public void MusicPlayer_Play_Play_Do_No_Change()
        {
            //arrange
            IMusicFactory imf = Substitute.For<IMusicFactory>();
            IInternalPlayer iip = Substitute.For<IInternalPlayer>();
            imf.GetInternalPlayer().Returns(iip);

            IReadOnlyPlayList irop = Substitute.For<IReadOnlyPlayList>();
            IInternalTrack it = Substitute.For<IInternalTrack>();
            it.Path.Returns("MyPath");
            irop.CurrentTrack.Returns(it);
            irop.When(x => x.Init()).Do(x => irop.CurrentTrack.Returns(it));

            // act
            MusicPlayer target = new MusicPlayer(imf);
           
            target.PlayList = irop; 
            
            target.Mode.Should().Be(PlayMode.Play);
            target.MonitorEvents();
            target.Mode = PlayMode.Play;

            //assert
            target.ShouldNotRaisePropertyChangeFor(t => t.Mode);
            target.Mode.Should().Be(PlayMode.Play);
        }
        public void MusicPlayer_Play_List_Current_Null_Init_OnPLay()
        {
            //arrange
            IMusicFactory imf = Substitute.For<IMusicFactory>();
            IInternalPlayer iip = Substitute.For<IInternalPlayer>();
            imf.GetInternalPlayer().Returns(iip);

            IReadOnlyPlayList irop = Substitute.For<IReadOnlyPlayList>();
            IInternalTrack it = Substitute.For<IInternalTrack>();
            it.Path.Returns("MyPath");
            irop.CurrentTrack.Returns((IInternalTrack)null);

            irop.When(x => x.Init()).Do(x=> irop.CurrentTrack.Returns(it));

            // act
            MusicPlayer target = new MusicPlayer(imf);
            target.MonitorEvents();
            target.PlayList = irop;
            target.Play();

            //assert
            target.PlayList.Should().Be(irop);
            target.MusicTrackSource.Should().Be(it);          
            target.ShouldRaisePropertyChangeFor(t => t.PlayList);
            target.ShouldRaisePropertyChangeFor(t => t.MusicTrackSource);
            iip.FileSource.Should().Be("MyPath");
            iip.Received().Play();
            irop.Received().Init();

            iip.Listener.Should().Be(target);

            target.Mode.Should().Be(PlayMode.Play);
        }
        public void MusicPlayer_Position_Change()
        {
            //arrange
            IMusicFactory imf = Substitute.For<IMusicFactory>();
            IInternalPlayer iip = Substitute.For<IInternalPlayer>();
            imf.GetInternalPlayer().Returns(iip);
            iip.Position.Returns(TimeSpan.FromSeconds(9));

            MusicPlayer target = new MusicPlayer(imf);

            //act-assert 1
            target.Position.Should().Be(TimeSpan.FromSeconds(9));

            //act-assert 2
            target.MonitorEvents();
            target.Position = TimeSpan.FromSeconds(90);
            target.Position.Should().Be(TimeSpan.FromSeconds(90));
            iip.Position.Should().Be(TimeSpan.FromSeconds(90));

            //clean
            target.Dispose();
        }
        public void MusicPlayer_Volume_Change()
        {
            //arrange
            IMusicFactory imf = Substitute.For<IMusicFactory>();
            IInternalPlayer iip = Substitute.For<IInternalPlayer>();
            imf.GetInternalPlayer().Returns(iip);
            iip.Volume.Returns(0.5d);

            MusicPlayer target = new MusicPlayer(imf);
               
            //act-assert 1
            target.Volume.Should().Be(0.5d); 

            //act-assert 2
            target.MonitorEvents();
            target.Volume = 0.2;
            target.Volume.Should().Be(0.2d);
            iip.Volume.Should().Be(0.2d);
            //iip.Listener.OnVolumeChange();
            target.ShouldRaisePropertyChangeFor(t => t.Volume);

            //act-assert 3
            target.Volume = -1;
            target.Volume.Should().Be(0d);
            iip.Volume.Should().Be(0d);

            //act-assert 4
            target.Volume = 5;
            target.Volume.Should().Be(1d);
            iip.Volume.Should().Be(1d);

            //assert
            
            target.PlayList.Should().BeNull();

            target.Mode.Should().Be(PlayMode.Stopped);
            target.MusicTrackSource.Should().Be(null);

            //clean
            target.Dispose();
        }
        public void MusicPlayer_Set_PlayList_CurrentTrack_NotNull_ChangePlayList()
        {
            //arrange
            IMusicFactory imf = Substitute.For<IMusicFactory>();
            IInternalPlayer iip = Substitute.For<IInternalPlayer>();
            imf.GetInternalPlayer().Returns(iip);

            MusicPlayer target = new MusicPlayer(imf);

            IReadOnlyPlayList irop = Substitute.For<IReadOnlyPlayList>();
            IInternalTrack it = Substitute.For<IInternalTrack>();
            it.Path.Returns("MyPath");
            irop.CurrentTrack = it;

            target.PlayList = irop;

            //act
            target.MonitorEvents();
            target.PlayList = null;

            //assert
            target.ShouldRaisePropertyChangeFor(t => t.PlayList);
            target.PlayList.Should().BeNull();
            iip.Received().Stop();

            target.Mode.Should().Be(PlayMode.Stopped);
            target.MusicTrackSource.Should().Be(null);

            //clean
            target.Dispose();
        }