public void Redo_NoDestSuppliedMoveAllCharactersFromSourceWithAssignedActor_CharactersGetMovedBackToOriginalGroupAndNewGroupIsRemoved()
        {
            var actor = new Glyssen.VoiceActor.VoiceActor {
                Id = 13
            };

            m_testProject.VoiceActorList.AllActors.Add(actor);
            var charactersToMove = new[] { "Peter (Simon)", "John the Baptist", "rich young ruler", "centurion at crucifixion", "man possessed by evil spirit", "John", "Pharisees" };
            var sourceGroup      = AddCharacterGroup(charactersToMove);

            sourceGroup.AssignVoiceActor(13);
            var action = new MoveCharactersToGroupUndoAction(m_testProject, sourceGroup, null, new List <string>(sourceGroup.CharacterIds));

            Assert.IsTrue(action.Undo());
            var estHoursOfSourceBeforeRedo = sourceGroup.EstimatedHours;

            Assert.IsTrue(action.Redo());

            var newGroup = m_testProject.CharacterGroupList.GroupContainingCharacterId("rich young ruler");

            Assert.IsTrue(action.GroupsAffectedByLastOperation.SequenceEqual(new[] { newGroup, sourceGroup }));
            Assert.AreNotEqual(sourceGroup, newGroup);
            Assert.IsTrue(newGroup.CharacterIds.SetEquals(charactersToMove));
            Assert.AreEqual(0, sourceGroup.CharacterIds.Count);
            Assert.AreEqual(13, sourceGroup.VoiceActorId);
            Assert.IsTrue(estHoursOfSourceBeforeRedo > sourceGroup.EstimatedHours);
        }
        public void Undo_NoDestSuppliedMoveAllCharactersFromSourceWithAssignedActor_CharactersGetMovedBackToOriginalGroupAndNewGroupIsRemoved()
        {
            var originalCharactersInSource = new[] { "Paul", "Jacob", "Micah", "centurion", "man, another", "captain", "Pharisees" };
            var sourceGroup = AddCharacterGroup(originalCharactersInSource);

            sourceGroup.AssignVoiceActor(13);
            var action = new MoveCharactersToGroupUndoAction(m_testProject, sourceGroup, null, new List <string>(sourceGroup.CharacterIds));

            Assert.IsTrue(action.Undo());
            Assert.IsTrue(sourceGroup.CharacterIds.SetEquals(originalCharactersInSource));
            Assert.AreEqual(sourceGroup, action.GroupsAffectedByLastOperation.Single());
            Assert.AreEqual(1, m_testProject.CharacterGroupList.CharacterGroups.Count);
            Assert.AreEqual(sourceGroup, m_testProject.CharacterGroupList.GroupContainingCharacterId("Micah"));
        }
        public void Undo_Split_CharactersGetMovedBackToOriginalGroupAndNewGroupIsRemoved()
        {
            var originalCharactersInSource = new[] { "Peter (Simon)", "John the Baptist", "rich young ruler", "centurion", "man possessed by evil spirit", "John", "Pharisees" };
            var sourceGroup = AddCharacterGroup(originalCharactersInSource);
            var action      = new MoveCharactersToGroupUndoAction(m_testProject, sourceGroup, null, new List <string> {
                "rich young ruler", "man possessed by evil spirit", "John"
            });

            action.IsSplit = true;

            Assert.IsTrue(action.Undo());
            Assert.IsTrue(sourceGroup.CharacterIds.SetEquals(originalCharactersInSource));
            Assert.AreEqual(sourceGroup, action.GroupsAffectedByLastOperation.Single());
            Assert.AreEqual(1, m_testProject.CharacterGroupList.CharacterGroups.Count);
            Assert.AreEqual(sourceGroup, m_testProject.CharacterGroupList.GroupContainingCharacterId("rich young ruler"));
        }
        public void Redo_AllCharactersMovedFromSourceWithNoAssignedActor_GroupRecreatedAndCharactersGetMovedBack()
        {
            var charactersToMove         = new[] { "Paul", "Jacob", "Micah" };
            var originalCharactersInDest = new[] { "centurion", "man, another", "captain", "Pharisees" };
            var sourceGroup = AddCharacterGroup(charactersToMove);
            var destGroup   = AddCharacterGroup(originalCharactersInDest);
            var action      = new MoveCharactersToGroupUndoAction(m_testProject, sourceGroup, destGroup, charactersToMove);

            Assert.AreEqual(1, m_testProject.CharacterGroupList.CharacterGroups.Count);

            Assert.IsTrue(action.Undo());
            Assert.IsTrue(action.Redo());

            Assert.AreEqual(destGroup, action.GroupsAffectedByLastOperation.Single());
            m_testProject.CharacterGroupList.CharacterGroups.SetEquals(new[] { destGroup });
            Assert.IsTrue(destGroup.CharacterIds.SetEquals(new[] { "centurion", "man, another", "captain", "Pharisees", "Paul", "Jacob", "Micah" }));
        }
        public void Undo_SourceAndDestHaveCharactersBeforeAndAfterMove_CharactersGetMovedBackToOriginalGroup()
        {
            var originalCharactersInSource = new[] { "Paul", "Jacob", "Micah", "ear", "centurion", "man, another", "captain", "Pharisees", "Rhoda" };
            var originalCharactersInDest   = new[] { "children", "Martha" };
            var sourceGroup = AddCharacterGroup(originalCharactersInSource);
            var destGroup   = AddCharacterGroup(originalCharactersInDest);
            var action      = new MoveCharactersToGroupUndoAction(m_testProject, sourceGroup, destGroup, new List <string> {
                "Rhoda", "ear"
            });

            Assert.IsTrue(action.Undo());
            Assert.IsTrue(sourceGroup.CharacterIds.SetEquals(originalCharactersInSource));
            Assert.IsTrue(action.GroupsAffectedByLastOperation.SequenceEqual(new [] { sourceGroup, destGroup }));
            Assert.AreEqual(2, m_testProject.CharacterGroupList.CharacterGroups.Count);
            Assert.IsTrue(sourceGroup.CharacterIds.SetEquals(originalCharactersInSource));
            Assert.IsTrue(destGroup.CharacterIds.SetEquals(originalCharactersInDest));
        }
        public void Undo_AssignCameoRole_CameoGroupNotRemoved()
        {
            // list of characters
            var originalCharactersInSource = new[] { "Peter (Simon)", "woman, bleeding for twelve years" };
            var sourceGroup = AddCharacterGroup(originalCharactersInSource);

            // set up cameo actor and group
            var cameoActor = new Glyssen.VoiceActor.VoiceActor {
                Id = 1, Name = "Missy Cameo", IsCameo = true
            };

            m_testProject.VoiceActorList.AllActors.Add(cameoActor);
            var cameoGroup = AddCharacterGroup();

            cameoGroup.AssignVoiceActor(1);

            // should be 2 groups now
            Assert.AreEqual(2, m_testProject.CharacterGroupList.CharacterGroups.Count);

            var estHoursOfSourceBeforeMove = sourceGroup.EstimatedHours;

            Assert.AreEqual(0, cameoGroup.EstimatedHours);

            // assign the character role "woman, bleeding for twelve years" to the cameo actor
            var action = new MoveCharactersToGroupUndoAction(m_testProject, sourceGroup, cameoGroup, new List <string> {
                "woman, bleeding for twelve years"
            });

            // should still be 2 groups
            Assert.AreEqual(2, m_testProject.CharacterGroupList.CharacterGroups.Count);

            // "woman, bleeding for twelve years" should be in the cameo group now
            Assert.IsTrue(m_testProject.CharacterGroupList.GroupContainingCharacterId("woman, bleeding for twelve years").AssignedToCameoActor);

            // undo
            Assert.IsTrue(action.Undo());

            // should still be 2 groups
            Assert.AreEqual(2, m_testProject.CharacterGroupList.CharacterGroups.Count);

            // "woman, bleeding for twelve years" should be back in the original group
            Assert.IsFalse(m_testProject.CharacterGroupList.GroupContainingCharacterId("woman, bleeding for twelve years").AssignedToCameoActor);
            Assert.AreEqual(estHoursOfSourceBeforeMove, sourceGroup.EstimatedHours);
            Assert.AreEqual(0, cameoGroup.EstimatedHours);
        }
        public void Redo_AllCharactersMovedFromSourceWithNoAssignedActor_GroupRecreatedAndCharactersGetMovedBack()
        {
            var charactersToMove         = new[] { "Peter (Simon)", "John the Baptist", "rich young ruler" };
            var originalCharactersInDest = new[] { "centurion at crucifixion", "man possessed by evil spirit", "John", "Pharisees" };
            var sourceGroup = AddCharacterGroup(charactersToMove);
            var destGroup   = AddCharacterGroup(originalCharactersInDest);
            var action      = new MoveCharactersToGroupUndoAction(m_testProject, sourceGroup, destGroup, charactersToMove);

            Assert.AreEqual(1, m_testProject.CharacterGroupList.CharacterGroups.Count);

            Assert.IsTrue(action.Undo());
            var estHoursOfDestBeforeRedo = destGroup.EstimatedHours;

            Assert.IsTrue(action.Redo());

            Assert.AreEqual(destGroup, action.GroupsAffectedByLastOperation.Single());
            m_testProject.CharacterGroupList.CharacterGroups.SetEquals(new[] { destGroup });
            Assert.IsTrue(destGroup.CharacterIds.SetEquals(new[] { "centurion at crucifixion", "man possessed by evil spirit", "John", "Pharisees", "Peter (Simon)", "John the Baptist", "rich young ruler" }));
            Assert.IsTrue(estHoursOfDestBeforeRedo < destGroup.EstimatedHours);
        }
        public void Redo_Split_CharactersGetMovedBackToOriginalGroupAndNewGroupIsRemoved()
        {
            var originalCharactersInSource = new[] { "Paul", "Jacob", "Micah", "centurion", "man, another", "captain", "Pharisees" };
            var charactersToMove           = new List <string> {
                "Micah", "man, another"
            };
            var sourceGroup = AddCharacterGroup(originalCharactersInSource);
            var action      = new MoveCharactersToGroupUndoAction(m_testProject, sourceGroup, null, new List <string>(charactersToMove));

            action.IsSplit = true;

            Assert.IsTrue(action.Undo());
            Assert.IsTrue(action.Redo());

            var newGroup = m_testProject.CharacterGroupList.GroupContainingCharacterId("Micah");

            Assert.IsTrue(action.GroupsAffectedByLastOperation.SequenceEqual(new[] { newGroup, sourceGroup }));
            Assert.AreNotEqual(sourceGroup, newGroup);
            Assert.IsTrue(newGroup.CharacterIds.SetEquals(charactersToMove));
            Assert.IsTrue(sourceGroup.CharacterIds.SetEquals(new[] { "Paul", "Jacob", "centurion", "captain", "Pharisees" }));
        }
        public void Undo_SourceAndDestHaveCharactersBeforeAndAfterMove_CharactersGetMovedBackToOriginalGroup()
        {
            var originalCharactersInSource = new[] { "Peter (Simon)", "John the Baptist", "rich young ruler", "people, some", "Jesus' family", "man possessed by evil spirit", "John", "Pharisees", "woman, bleeding for twelve years" };
            var originalCharactersInDest   = new[] { "crowd", "Herodias' daughter" };
            var sourceGroup = AddCharacterGroup(originalCharactersInSource);
            var destGroup   = AddCharacterGroup(originalCharactersInDest);
            var estHoursOfSourceBeforeMove = sourceGroup.EstimatedHours;
            var estHoursOfDestBeforeMove   = destGroup.EstimatedHours;

            var action = new MoveCharactersToGroupUndoAction(m_testProject, sourceGroup, destGroup, new List <string> {
                "woman, bleeding for twelve years", "people, some"
            });

            Assert.IsTrue(action.Undo());
            Assert.IsTrue(sourceGroup.CharacterIds.SetEquals(originalCharactersInSource));
            Assert.IsTrue(action.GroupsAffectedByLastOperation.SequenceEqual(new [] { sourceGroup, destGroup }));
            Assert.AreEqual(2, m_testProject.CharacterGroupList.CharacterGroups.Count);
            Assert.IsTrue(sourceGroup.CharacterIds.SetEquals(originalCharactersInSource));
            Assert.IsTrue(destGroup.CharacterIds.SetEquals(originalCharactersInDest));
            Assert.AreEqual(estHoursOfDestBeforeMove, destGroup.EstimatedHours);
            Assert.AreEqual(estHoursOfSourceBeforeMove, sourceGroup.EstimatedHours);
        }
        public void Redo_Split_CharactersGetMovedBackToOriginalGroupAndNewGroupIsRemoved()
        {
            var originalCharactersInSource = new[] { "Peter (Simon)", "John the Baptist", "rich young ruler", "Jesus' family", "man possessed by evil spirit", "John", "Pharisees" };
            var charactersToMove           = new List <string> {
                "rich young ruler", "man possessed by evil spirit"
            };
            var sourceGroup = AddCharacterGroup(originalCharactersInSource);
            var action      = new MoveCharactersToGroupUndoAction(m_testProject, sourceGroup, null, new List <string>(charactersToMove));

            action.IsSplit = true;

            Assert.IsTrue(action.Undo());
            var estHoursOfSourceBeforeRedo = sourceGroup.EstimatedHours;

            Assert.IsTrue(action.Redo());

            var newGroup = m_testProject.CharacterGroupList.GroupContainingCharacterId("rich young ruler");

            Assert.IsTrue(action.GroupsAffectedByLastOperation.SequenceEqual(new[] { newGroup, sourceGroup }));
            Assert.AreNotEqual(sourceGroup, newGroup);
            Assert.IsTrue(newGroup.CharacterIds.SetEquals(charactersToMove));
            Assert.IsTrue(sourceGroup.CharacterIds.SetEquals(new[] { "Peter (Simon)", "John the Baptist", "Jesus' family", "John", "Pharisees" }));
            Assert.IsTrue(estHoursOfSourceBeforeRedo > sourceGroup.EstimatedHours);
        }