<commit_before>﻿using System;
using System.Collections.Generic;
using Glyssen;
using Glyssen.Character;
using Glyssen.Dialogs;
using GlyssenTests.Properties;
using NUnit.Framework;

namespace GlyssenTests.Dialogs
{
	[TestFixture]
	class VoiceActorAssignmentViewModelTests
	{
		private Project m_testProject;
		private VoiceActorAssignmentViewModel m_model;

		[TestFixtureSetUp]
		public void TestFixtureSetUp()
		{
			// Use a test version of the file so the tests won't break every time we fix a problem in the production control file.
			ControlCharacterVerseData.TabDelimitedCharacterVerseData = Resources.TestCharacterVerse;
			m_testProject = TestProject.CreateTestProject(TestProject.TestBook.MRK);
		}

		[SetUp]
		public void SetUp()
		{
			m_testProject.VoiceActorList.Actors.Clear();
			m_testProject.CharacterGroupList.CharacterGroups.Clear();
			// Adding one group here prevents the constructor from generating groups
			m_testProject.CharacterGroupList.CharacterGroups.Add(new CharacterGroup(1));
			m_model = new VoiceActorAssignmentViewModel(m_testProject);
		}

		[Test]
		public void AddNewGroup()
		{
			Assert.AreEqual(1, m_testProject.CharacterGroupList.CharacterGroups.Count);
			var newGroup = m_model.AddNewGroup();
			Assert.AreEqual(2, m_testProject.CharacterGroupList.CharacterGroups.Count);
			Assert.AreEqual(newGroup, m_testProject.CharacterGroupList.CharacterGroups[1]);
		}

		[Test]
		public void MoveActorFromGroupToGroup_SwapTrue()
		{
			var actor1 = new Glyssen.VoiceActor.VoiceActor { Id = 1 };
			var actor2 = new Glyssen.VoiceActor.VoiceActor { Id = 2 };
			var sourceGroup = m_model.CharacterGroups[0];
			sourceGroup.AssignVoiceActor(actor1);
			var destGroup = m_model.AddNewGroup();
			destGroup.AssignVoiceActor(actor2);

			Assert.AreEqual(actor1, sourceGroup.VoiceActorAssigned);
			Assert.AreEqual(actor2, destGroup.VoiceActorAssigned);
			m_model.MoveActorFromGroupToGroup(sourceGroup, destGroup, true);
			Assert.AreEqual(actor2, sourceGroup.VoiceActorAssigned);
			Assert.AreEqual(actor1, destGroup.VoiceActorAssigned);
		}

		[Test]
		public void MoveActorFromGroupToGroup_SwapFalse()
		{
			var actor1 = new Glyssen.VoiceActor.VoiceActor { Id = 1 };
			var actor2 = new Glyssen.VoiceActor.VoiceActor { Id = 2 };
			var sourceGroup = m_model.CharacterGroups[0];
			sourceGroup.AssignVoiceActor(actor1);
			var destGroup = m_model.AddNewGroup();
			destGroup.AssignVoiceActor(actor2);

			Assert.AreEqual(actor1, sourceGroup.VoiceActorAssigned);
			Assert.AreEqual(actor2, destGroup.VoiceActorAssigned);
			m_model.MoveActorFromGroupToGroup(sourceGroup, destGroup, false);
			Assert.False(sourceGroup.IsVoiceActorAssigned);
			Assert.AreEqual(actor1, destGroup.VoiceActorAssigned);
		}

		[Test]
		public void AssignActorToGroup_CanAssignTrue_ActorAssigned()
		{
			var actor1 = new Glyssen.VoiceActor.VoiceActor { Id = 1 };
			var group = m_model.CharacterGroups[0];
			m_model.AssignActorToGroup(actor1, group);
			Assert.AreEqual(actor1, group.VoiceActorAssigned);
		}

		[Test]
		public void AssignActorToGroup_CanAssignFalse_ActorNotAssigned()
		{
			m_model.CanAssign = false;
			var actor1 = new Glyssen.VoiceActor.VoiceActor { Id = 1 };
			var group = m_model.CharacterGroups[0];
			m_model.AssignActorToGroup(actor1, group);
			Assert.False(group.IsVoiceActorAssigned);
			m_model.CanAssign = true;
		}

		[Test]
		public void UnassignActorFromGroup()
		{
			var actor1 = new Glyssen.VoiceActor.VoiceActor { Id = 1 };
			var group = m_model.CharacterGroups[0];
			m_model.AssignActorToGroup(actor1, group);
			Assert.True(group.IsVoiceActorAssigned);

			m_model.UnAssignActorFromGroup(group);
			Assert.False(group.IsVoiceActorAssigned);
		}

		[Test]
		public void MoveCharactersToGroup_DestinationContainsNoCharacters()
		{
			var characterIds = new List<string> { "John", "Andrew" };
			var sourceGroup = m_model.CharacterGroups[0];
			sourceGroup.CharacterIds = new CharacterIdHashSet(characterIds);
			var destGroup = m_model.AddNewGroup();

			Assert.True(m_model.MoveCharactersToGroup(characterIds, destGroup));

			var destGroupCharacterIds = destGroup.CharacterIds;
			Assert.AreEqual(2, destGroup.CharacterIds.Count);
			Assert.True(destGroupCharacterIds.Contains("John"));
			Assert.True(destGroupCharacterIds.Contains("Andrew"));
		}

		[Test]
		public void MoveCharactersToGroup_DestinationContainsCharacters()
		{
			var characterIds = new List<string> { "John", "Andrew" };
			var sourceGroup = m_model.CharacterGroups[0];
			sourceGroup.CharacterIds = new CharacterIdHashSet(characterIds);
			var destGroup = m_model.AddNewGroup();
			destGroup.CharacterIds = new CharacterIdHashSet { "ear", "mouth" };

			Assert.True(m_model.MoveCharactersToGroup(characterIds, destGroup));

			var destGroupCharacterIds = destGroup.CharacterIds;<commit_msg>Add unit test for previous commit (PG-395)<commit_after>﻿using System;
using System.Collections.Generic;
using Glyssen;
using Glyssen.Character;
using Glyssen.Dialogs;
using GlyssenTests.Properties;
using NUnit.Framework;

namespace GlyssenTests.Dialogs
{
	[TestFixture]
	class VoiceActorAssignmentViewModelTests
	{
		private Project m_testProject;
		private VoiceActorAssignmentViewModel m_model;

		[TestFixtureSetUp]
		public void TestFixtureSetUp()
		{
			// Use a test version of the file so the tests won't break every time we fix a problem in the production control file.
			ControlCharacterVerseData.TabDelimitedCharacterVerseData = Resources.TestCharacterVerse;
			m_testProject = TestProject.CreateTestProject(TestProject.TestBook.MRK);
		}

		[SetUp]
		public void SetUp()
		{
			m_testProject.VoiceActorList.Actors.Clear();
			m_testProject.CharacterGroupList.CharacterGroups.Clear();
			// Adding one group here prevents the constructor from generating groups
			m_testProject.CharacterGroupList.CharacterGroups.Add(new CharacterGroup(1));
			m_model = new VoiceActorAssignmentViewModel(m_testProject);
		}

		[Test]
		public void AddNewGroup()
		{
			Assert.AreEqual(1, m_testProject.CharacterGroupList.CharacterGroups.Count);
			var newGroup = m_model.AddNewGroup();
			Assert.AreEqual(2, m_testProject.CharacterGroupList.CharacterGroups.Count);
			Assert.AreEqual(newGroup, m_testProject.CharacterGroupList.CharacterGroups[1]);
		}

		[Test]
		public void MoveActorFromGroupToGroup_SwapTrue()
		{
			var actor1 = new Glyssen.VoiceActor.VoiceActor { Id = 1 };
			var actor2 = new Glyssen.VoiceActor.VoiceActor { Id = 2 };
			var sourceGroup = m_model.CharacterGroups[0];
			sourceGroup.AssignVoiceActor(actor1);
			var destGroup = m_model.AddNewGroup();
			destGroup.AssignVoiceActor(actor2);

			Assert.AreEqual(actor1, sourceGroup.VoiceActorAssigned);
			Assert.AreEqual(actor2, destGroup.VoiceActorAssigned);
			m_model.MoveActorFromGroupToGroup(sourceGroup, destGroup, true);
			Assert.AreEqual(actor2, sourceGroup.VoiceActorAssigned);
			Assert.AreEqual(actor1, destGroup.VoiceActorAssigned);
		}

		[Test]
		public void MoveActorFromGroupToGroup_SwapFalse()
		{
			var actor1 = new Glyssen.VoiceActor.VoiceActor { Id = 1 };
			var actor2 = new Glyssen.VoiceActor.VoiceActor { Id = 2 };
			var sourceGroup = m_model.CharacterGroups[0];
			sourceGroup.AssignVoiceActor(actor1);
			var destGroup = m_model.AddNewGroup();
			destGroup.AssignVoiceActor(actor2);

			Assert.AreEqual(actor1, sourceGroup.VoiceActorAssigned);
			Assert.AreEqual(actor2, destGroup.VoiceActorAssigned);
			m_model.MoveActorFromGroupToGroup(sourceGroup, destGroup, false);
			Assert.False(sourceGroup.IsVoiceActorAssigned);
			Assert.AreEqual(actor1, destGroup.VoiceActorAssigned);
		}

		[Test]
		public void AssignActorToGroup_CanAssignTrue_ActorAssigned()
		{
			var actor1 = new Glyssen.VoiceActor.VoiceActor { Id = 1 };
			var group = m_model.CharacterGroups[0];
			m_model.AssignActorToGroup(actor1, group);
			Assert.AreEqual(actor1, group.VoiceActorAssigned);
		}

		[Test]
		public void AssignActorToGroup_CanAssignFalse_ActorNotAssigned()
		{
			m_model.CanAssign = false;
			var actor1 = new Glyssen.VoiceActor.VoiceActor { Id = 1 };
			var group = m_model.CharacterGroups[0];
			m_model.AssignActorToGroup(actor1, group);
			Assert.False(group.IsVoiceActorAssigned);
			m_model.CanAssign = true;
		}

		[Test]
		public void UnAssignActorFromGroup_ByGroup()
		{
			var actor1 = new Glyssen.VoiceActor.VoiceActor { Id = 1 };
			var group = m_model.CharacterGroups[0];
			m_model.AssignActorToGroup(actor1, group);
			Assert.True(group.IsVoiceActorAssigned);

			m_model.UnAssignActorFromGroup(group);
			Assert.False(group.IsVoiceActorAssigned);
		}

		[Test]
		public void UnAssignActorFromGroup_ByActor()
		{
			var actor1 = new Glyssen.VoiceActor.VoiceActor { Id = 1 };
			var group = m_model.CharacterGroups[0];
			m_model.AssignActorToGroup(actor1, group);
			Assert.True(group.IsVoiceActorAssigned);

			m_model.UnAssignActorFromGroup(actor1);
			Assert.False(group.IsVoiceActorAssigned);
		}

		[Test]
		public void MoveCharactersToGroup_DestinationContainsNoCharacters()
		{
			var characterIds = new List<string> { "John", "Andrew" };
			var sourceGroup = m_model.CharacterGroups[0];
			sourceGroup.CharacterIds = new CharacterIdHashSet(characterIds);
			var destGroup = m_model.AddNewGroup();

			Assert.True(m_model.MoveCharactersToGroup(characterIds, destGroup));

			var destGroupCharacterIds = destGroup.CharacterIds;
			Assert.AreEqual(2, destGroup.CharacterIds.Count);
			Assert.True(destGroupCharacterIds.Contains("John"));
			Assert.True(destGroupCharacterIds.Contains("Andrew"));
		}

		[Test]
		public void MoveCharactersToGroup_DestinationContainsCharacters()
		{
			var characterIds = new List<string> { "John", "Andrew" };
			var sourceGroup = m_model.CharacterGroups[0];
			sourceGroup.CharacterIds = new CharacterIdHashSet(characterIds);
			var destGroup = m_model.AddNewGroup();
			destGroup.CharacterIds = new CharacterIdHashSet { "ear", "mouth" };

			Assert.True(m_model.MoveCharactersToGroup(characterIds, destGroup));

			var destGroupCharacterIds = destGroup.CharacterIds;
{'fraction_non_alphanumeric': 0.09732748304746709, 'fraction_numerical': 0.008974870362983646, 'mean_word_length': 5.252493765586035, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3016708', 'n_tokens_mistral': 3630, 'n_tokens_neox': 3115, 'n_words': 565}