Esempio n. 1
0
        public void Drop_EffectIsCopyAndTargetCollectionIsActiveSoundsAndDataIsAnEnumerableOfISounds_AddsAllSoundsToSoundService()
        {
            //Arrange
            Target = CreateTarget();

            ICollection <ISound> targetCollection = Target.SoundService.ActiveSounds;
            IEnumerable <ISound> droppedSounds    = new ISound[]
            {
                CommonStubsFactory.StubClonableSoundWithRandomName(),
                                 CommonStubsFactory.StubClonableSoundWithRandomName(),
                                 CommonStubsFactory.StubClonableSoundWithRandomName()
            };

            IDropInfo dropInfo = MockRepository.GenerateStub <IDropInfo>();

            dropInfo.Effects = DragDropEffects.Copy;
            dropInfo.Stub(info => info.TargetCollection).Return(targetCollection);
            dropInfo.Stub(info => info.Data).Return(droppedSounds);

            //Act
            Target.Drop(dropInfo);

            //Assert
            targetCollection.ShouldBeEquivalentTo(droppedSounds);
        }
Esempio n. 2
0
        public void DragOver_DataIsAnEnumerableOfISoundsAndTargetCollectionContainsThoseSoundsAndIsReadOnly_SetsEffectsToNone()
        {
            //Arrange
            Target = CreateTarget();

            IEnumerable <ISound> droppedSounds = new ISound[]
            {
                CommonStubsFactory.StubClonableSoundWithRandomName(),
                                 CommonStubsFactory.StubClonableSoundWithRandomName(),
                                 CommonStubsFactory.StubClonableSoundWithRandomName()
            };
            ReadOnlyObservableCollection <ISound> targetCollection =
                new ReadOnlyObservableCollection <ISound>(
                    new ObservableCollection <ISound>(droppedSounds));

            IDropInfo dropInfo = MockRepository.GenerateStub <IDropInfo>();

            dropInfo.Stub(info => info.TargetCollection).Return(targetCollection);
            dropInfo.Stub(info => info.Data).Return(droppedSounds);

            //Act
            Target.DragOver(dropInfo);

            //Assert
            dropInfo.Effects.ShouldBeEquivalentTo(DragDropEffects.None);
        }
Esempio n. 3
0
        public void Drop_EffectIsCopyAndDataIsASingleISound_InsertsSoundIntoTargetCollection()
        {
            //Arrange
            Target = CreateTarget();

            ISound droppedSound = CommonStubsFactory.StubClonableSoundWithRandomName();
            ObservableCollection <ISound> targetCollection = new ObservableCollection <ISound>
            {
                CommonStubsFactory.StubClonableSoundWithRandomName(),
                                          CommonStubsFactory.StubClonableSoundWithRandomName(),
                                          CommonStubsFactory.StubClonableSoundWithRandomName(),
            };

            ISound[] expectedCollection =
            {
                targetCollection[0],
                droppedSound,
                targetCollection[1],
                targetCollection[2],
            };


            IDropInfo dropInfo = MockRepository.GenerateStub <IDropInfo>();

            dropInfo.Effects = DragDropEffects.Copy;
            dropInfo.Stub(info => info.TargetCollection).Return(targetCollection);
            dropInfo.Stub(info => info.Data).Return(droppedSound);
            dropInfo.Stub(info => info.InsertIndex).Return(1);

            //Act
            Target.Drop(dropInfo);

            //Assert
            targetCollection.ShouldBeEquivalentTo(expectedCollection);
        }
Esempio n. 4
0
        public void AddSoundCommandExecute__CallsDialogServiceOpenFileDialogWithCorrectArguments()
        {
            //Arrange
            IDialogService dialogServiceMock = MockRepository.GenerateMock <IDialogService>();

            string[] supportedExtensions = { "*.a", "*.b", "*.c" };

            Dictionary <string, string> expectedFilters = new Dictionary <string, string>
            {
                {
                    Properties.Resources.MainWindowViewModel_AddSounds_Supported_Files,
                    string.Join(Properties.Resources.MainWindowViewModel_AddSounds__Supported_Files_Separator, supportedExtensions)
                }
            };

            Target = CreateTarget(dialogService: dialogServiceMock, soundFactory: CommonStubsFactory.StubSoundFactory(supportedExtensions));
            Target.SelectedSoundBoard = new SoundBoard.Model.SoundBoard();

            dialogServiceMock.Expect(
                service =>
                service.OpenFileDialog(Properties.Resources.MainWindowViewModel_AddSounds_Choose_sound_files_to_add,
                                       expectedFilters))
            .Return(Enumerable.Empty <string>());

            //Act
            Target.Commands.AddSoundCommand.Execute(null);

            //Assert
            dialogServiceMock.VerifyAllExpectations();
        }
Esempio n. 5
0
        public void ToggleSoundIsLoopedCommandExecute_IsLoopedWasFalse_IsLoopedIsNowTrue()
        {
            ISound sound = CommonStubsFactory.StubClonableSoundWithRandomName();

            sound.IsLooped = false;
            Target         = CreateTarget();

            Target.Commands.ToggleSoundIsLoopedCommand.Execute(sound);

            sound.IsLooped.Should().BeTrue();
        }
Esempio n. 6
0
        public void ActivateSingleSoundCommand_SelectedSoundIsNotNull_AddedSoundIsSelected()
        {
            //Arrange
            Target = CreateTarget();
            ISound sound = CommonStubsFactory.StubClonableSoundWithRandomName();

            //Act
            Target.Commands.ActivateSingleSoundCommand.Execute(sound);

            //Assert
            Target.SelectedActiveSound.ShouldBeEquivalentTo(sound);
        }
Esempio n. 7
0
        public void ActivateSingleSoundCommand_ParameterIsNotNull_AddsCloneOfSoundToActiveSounds()
        {
            //Arrange
            ObservableCollection <ISound> activeSounds           = new ObservableCollection <ISound>();
            IObservableSoundService       observableSoundService = CommonStubsFactory.StubObservableSoundService(activeSounds);

            Target = CreateTarget(soundService: observableSoundService);
            ISound sound = CommonStubsFactory.StubClonableSoundWithRandomName();

            //Act
            Target.Commands.ActivateSingleSoundCommand.Execute(sound);

            //Assert
            activeSounds.Should().NotContain(s => ReferenceEquals(s, sound));
            activeSounds.Single().ShouldBeEquivalentTo(sound);
        }
Esempio n. 8
0
        public void DragOver_TargetCollectionIsNull_SetsEffectsToNone()
        {
            //Arrange
            Target = CreateTarget();

            IDropInfo dropInfo = MockRepository.GenerateStub <IDropInfo>();

            dropInfo.Effects = DragDropEffects.All;
            dropInfo.Stub(info => info.Data).Return(CommonStubsFactory.StubClonableSoundWithRandomName());
            dropInfo.Stub(info => info.TargetCollection).Return(null);

            //Act
            Target.DragOver(dropInfo);

            //Assert
            dropInfo.Effects.ShouldBeEquivalentTo(DragDropEffects.None);
        }
Esempio n. 9
0
        private static MainWindowViewModel CreateTarget(ISoundBoardRepository soundBoardRepository = null,
                                                        IDialogService dialogService = null, IKernel container = null, IObservableSoundService soundService = null,
                                                        ISoundFactory soundFactory   = null)
        {
            if (container == null)
            {
                container = new StandardKernel();
                container.Bind <MainWindow>().ToMethod(context => new MainWindow());
            }

            return(new MainWindowViewModel(
                       soundBoardRepository ?? MockRepository.GenerateStub <ISoundBoardRepository>(),
                       dialogService ?? MockRepository.GenerateStub <IDialogService>(),
                       soundService ?? CommonStubsFactory.StubObservableSoundService(),
                       container,
                       soundFactory ?? CommonStubsFactory.StubSoundFactory(new string[] { "*.a", "*.b" })));
        }
Esempio n. 10
0
        public void Drop_EffectIsMoveAndDataIsAnEnumerableOfISounds_MovesAllSoundsToCorrectPositionInExistingOrder()
        {
            //Arrange
            Target = CreateTarget();

            ISound[] droppedSounds =
            {
                CommonStubsFactory.StubClonableSound("FirstMovedSound"),
                CommonStubsFactory.StubClonableSound("SecondMovedSound"),
                CommonStubsFactory.StubClonableSound("ThirdMovedSound"),
            };

            ObservableCollection <ISound> targetCollection = new ObservableCollection <ISound>
            {
                CommonStubsFactory.StubClonableSoundWithRandomName(),
                                          CommonStubsFactory.StubClonableSoundWithRandomName(),
                                          CommonStubsFactory.StubClonableSoundWithRandomName(),
                                          droppedSounds[0],
                                          droppedSounds[1],
                                          droppedSounds[2],
            };

            ISound[] expectedCollection =
            {
                targetCollection[0],
                droppedSounds[0],
                droppedSounds[1],
                droppedSounds[2],
                targetCollection[1],
                targetCollection[2]
            };

            IDropInfo dropInfo = MockRepository.GenerateStub <IDropInfo>();

            dropInfo.Effects = DragDropEffects.Move;
            dropInfo.Stub(info => info.TargetCollection).Return(targetCollection);
            dropInfo.Stub(info => info.Data).Return(droppedSounds);
            dropInfo.Stub(info => info.InsertIndex).Return(1);

            //Act
            Target.Drop(dropInfo);

            //Assert
            targetCollection.ShouldBeEquivalentTo(expectedCollection, options => options.WithStrictOrdering());
        }
Esempio n. 11
0
        public void Drop_EffectIsCopyAndTargetCollectionIsActiveSoundsDataIsADataObjectContainingMultipleFiles_AddsASoundForEachSupportedFileToSoundService()
        {
            //Arrange
            ISoundFactory soundFactory = CommonStubsFactory.StubSoundFactory(new string[]
            {
                "*.mp3",
                "*.m4a",
                "*.ogg"
            });

            Target = CreateTarget(soundFactory: soundFactory);

            ICollection <ISound> targetCollection = Target.SoundService.ActiveSounds;
            DataObject           droppeDataObject = new DataObject();

            string[] supportedFiles =
            {
                "Taking the hobbits to isengard.mp3",
                "The way i tend to be.m4a",
                "-Human.ogg"
            };

            StringCollection fileDropList = new StringCollection
            {
                "Unsupported File.wav",
                "Unsupported File2.agg",
                "Unsupported File2.bleurrg",
                "Unsupported File2.idk"
            };

            fileDropList.AddRange(supportedFiles);
            droppeDataObject.SetFileDropList(fileDropList);

            IDropInfo dropInfo = MockRepository.GenerateStub <IDropInfo>();

            dropInfo.Effects = DragDropEffects.Copy;
            dropInfo.Stub(info => info.TargetCollection).Return(targetCollection);
            dropInfo.Stub(info => info.Data).Return(droppeDataObject);

            //Act
            Target.Drop(dropInfo);

            //Assert
            targetCollection.Should().OnlyContain(sound => supportedFiles.Any(s => s == sound.FileName));
        }
Esempio n. 12
0
        public void DragOver_DataIsASingleSoundAndTargetCollectionDoesNotContainSound_SetsEffectsToCopy()
        {
            //Arrange
            Target = CreateTarget();

            ISound droppedSound = CommonStubsFactory.StubClonableSoundWithRandomName();
            ObservableCollection <ISound> targetCollection = new ObservableCollection <ISound>();
            IDropInfo dropInfo = MockRepository.GenerateStub <IDropInfo>();

            dropInfo.Stub(info => info.TargetCollection).Return(targetCollection);
            dropInfo.Stub(info => info.Data).Return(droppedSound);

            //Act
            Target.DragOver(dropInfo);

            //Assert
            dropInfo.Effects.ShouldBeEquivalentTo(DragDropEffects.Copy);
        }
        public void RenameSoundCommandExecute_DialogReturnsNull_OldNameIsRetained()
        {
            //Arrange
            const string expected = "Old Name";

            ISound         selectedSound = CommonStubsFactory.StubClonableSound("Old Name");
            IDialogService stub          = MockRepository.GenerateStub <IDialogService>();

            Target = CreateTargetWithDefaultStubs(dialogService: stub);

            stub.Stub(service => service.NameDialog(null, null, null, null)).IgnoreArguments().Return(null);

            //Act
            Target.RenameSoundCommand.Execute(new Collection <ISound> {
                selectedSound
            });

            //Assert
            selectedSound.Name.Should().Be(expected);
        }
        public void RenameSoundCommandExecute__NameDialogIsCalledWithTitlePromptAndInitialName()
        {
            ISound         selectedSound = CommonStubsFactory.StubClonableSound("Old Name");
            IDialogService mock          = MockRepository.GenerateMock <IDialogService>();

            Target = CreateTargetWithDefaultStubs(dialogService: mock);

            mock.Expect(service => service.NameDialog(
                            Arg <Window> .Is.Anything,
                            Arg <string> .Is.Anything,
                            Arg <string> .Is.Anything,
                            Arg <string> .Is.Equal(selectedSound.Name)))
            .Return(null);

            //Act
            Target.RenameSoundCommand.Execute(new Collection <ISound> {
                selectedSound
            });

            //Assert
            mock.VerifyAllExpectations();
        }
Esempio n. 15
0
        public void Drop_EffectIsMoveAndDataIsASingleISound_MovesSoundToCorrectPosition()
        {
            //Arrange
            const int moveTargetIndex = 2;

            Target = CreateTarget();

            ISound movedSound = CommonStubsFactory.StubClonableSound("Index2");
            ObservableCollection <ISound> targetCollection = new ObservableCollection <ISound>
            {
                CommonStubsFactory.StubClonableSoundWithRandomName(),
                                          movedSound,
                                          CommonStubsFactory.StubClonableSoundWithRandomName(),
                                          CommonStubsFactory.StubClonableSoundWithRandomName()
            };

            IEnumerable <ISound> expectedCollection = new ObservableCollection <ISound>
            {
                targetCollection[0],
                targetCollection[2],
                movedSound,                 // index 2
                targetCollection[3]
            };

            IDropInfo dropInfo = MockRepository.GenerateStub <IDropInfo>();

            dropInfo.Effects = DragDropEffects.Move;
            dropInfo.Stub(info => info.TargetCollection).Return(targetCollection);
            dropInfo.Stub(info => info.Data).Return(movedSound);
            dropInfo.Stub(info => info.InsertIndex).Return(moveTargetIndex);

            //Act
            Target.Drop(dropInfo);

            //Assert
            targetCollection.ShouldBeEquivalentTo(expectedCollection);
        }
        public void ActivateSoundsCommandExecute_ParameterContainsIListWith3Sounds_Adds3EquivalentClonesToActiveSounds()
        {
            //Arrange
            List <ISound> selectedSounds = new List <ISound>
            {
                CommonStubsFactory.StubClonableSoundWithRandomName(),
                          CommonStubsFactory.StubClonableSoundWithRandomName(),
                          CommonStubsFactory.StubClonableSoundWithRandomName()
            };
            IMainWindowViewModel mainWindowViewModel = CommonStubsFactory.StubMainWindowViewModel();

            Target = CreateTargetWithDefaultStubs(mainWindowViewModel);

            //Act
            Target.ActivateSoundsCommand.Execute(selectedSounds);

            //Assert
            for (var i = 0; i < selectedSounds.Count; i++)
            {
                mainWindowViewModel.SoundService.ActiveSounds[i].ShouldBeEquivalentTo(selectedSounds[i],
                                                                                      "for each selected sound there must be an identical active sound");
                mainWindowViewModel.SoundService.ActiveSounds[i].Should().NotBeSameAs(selectedSounds[i], "it must be a clone, not the same reference");
            }
        }