Inheritance: Tp.Integration.Common.DataTransferObject, IAssignableDTO, ICustomFieldHolderDTO
		public EntityDocument CreateAssignable(AssignableDTO assignable)
		{
			var name = EntityDocument.CreateName(assignable.AssignableID);
			var text = _textOperations.Prepare(string.Format("{0} {1} ", assignable.Name, assignable.Description ?? string.Empty));
			return new EntityDocument(name, text)
			{
				ProjectId = _documentIdFactory.CreateProjectId(assignable.ProjectID.GetValueOrDefault()),
				EntityTypeId = _documentIdFactory.CreateEntityTypeId(assignable.EntityTypeID.GetValueOrDefault()),
				SquadId = _documentIdFactory.CreateSquadId(assignable.SquadID.GetValueOrDefault()),
				DocNumber = -1
			};
		}
        public void SearchUserStoryByTeamAfterTeamUpdateToNull()
        {
            var indexer = GetInstance<IEntityIndexer>();
            const int targetTeamId = 1;
            const int assignableIdWithNullSquad = 5;
            var expectedAssignablesIds = new[] { 1, 4 };
            int userStoryTypeId = QueryEntityTypeProvider.USERSTORY_TYPE_ID;
            var target = new AssignableDTO
            {
                ID = expectedAssignablesIds[0],
                Name = "zagzag",
                Description = "",
                EntityTypeID = userStoryTypeId,
                SquadID = targetTeamId
            };
            indexer.AddAssignableIndex(target);
            indexer.AddAssignableIndex(new AssignableDTO
            {
                ID = 2,
                Name = "zagzag",
                Description = "",
                EntityTypeID = userStoryTypeId,
                SquadID = 2
            });
            indexer.AddAssignableIndex(new AssignableDTO
            {
                ID = 3,
                Name = "qqqqq",
                Description = "wwww",
                EntityTypeID = userStoryTypeId,
                SquadID = targetTeamId
            });
            indexer.AddAssignableIndex(new AssignableDTO
            {
                ID = expectedAssignablesIds[1],
                Name = "zagzag qwerty",
                Description = "",
                EntityTypeID = userStoryTypeId,
                SquadID = targetTeamId
            });
            indexer.AddAssignableIndex(new AssignableDTO
            {
                ID = assignableIdWithNullSquad,
                Name = "zagzag qwerty blabla",
                Description = "",
                EntityTypeID = userStoryTypeId,
            });
            var queryRunner = GetInstance<QueryRunner>();
            var result = queryRunner.Run(new QueryData
            {
                Query = "zagzag",
                TeamIds = new[] { targetTeamId }
            });
            result.Total.Should(Be.EqualTo(2));
            result.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Select(s => s.ToString()).ToArray()));
            target.SquadID = null;
            indexer.UpdateAssignableIndex(target, new[] { AssignableField.SquadID }, isIndexing: false);
            var newResult = queryRunner.Run(new QueryData
            {
                Query = "zagzag",
                TeamIds = new[] { targetTeamId }
            });
            newResult.Total.Should(Be.EqualTo(1));
            newResult.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Skip(1).Select(s => s.ToString()).ToArray()));

            var lastResult = queryRunner.Run(new QueryData
            {
                Query = "zagzag",
                TeamIds = null,
                IncludeNoTeam = true
            });
            lastResult.Total.Should(Be.EqualTo(2));
            lastResult.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Take(1).Concat(new[]{assignableIdWithNullSquad}).Select(s => s.ToString()).ToArray()));
        }
		public void SearchUserStoryByTeamAfterRemoveAssignableSquad()
		{
			var indexer = GetInstance<IEntityIndexer>();
			const int targetTeamId = 1;
			const int expectedAssignableId = 1;
			const int expectedAssignableSquadId = 1;
			const int userStoryTypeId = QueryEntityTypeProvider.USERSTORY_TYPE_ID;
			var target = new AssignableDTO
			{
				ID = expectedAssignableId,
				Name = "zagzag",
				Description = "",
				EntityTypeID = userStoryTypeId,
				SquadID = targetTeamId
			};
			indexer.AddAssignableIndex(target);
			indexer.AddAssignableIndex(new AssignableDTO
			{
				ID = 2,
				Name = "zagzag",
				Description = "",
				EntityTypeID = userStoryTypeId,
				SquadID = targetTeamId
			});
			var targetAssignableSquad = new AssignableSquadDTO
			{
				AssignableSquadID = expectedAssignableSquadId,
				AssignableID = expectedAssignableId,
				SquadID = targetTeamId
			};
			indexer.AddAssignableSquadIndex(targetAssignableSquad);

			var queryRunner = GetInstance<QueryRunner>();
			var result = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { targetTeamId }
			});
			result.Total.Should(Be.EqualTo(2), "result.Total.Should(Be.EqualTo(2))");
			result.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True, "result.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True)");

			indexer.RemoveAssignableSquadIndex(targetAssignableSquad);

			var newResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { targetTeamId }
			});
			newResult.Total.Should(Be.EqualTo(1), "newResult.Total.Should(Be.EqualTo(1))");
			newResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.False, "newResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.False)");
		}
		public void SearchUserStoryByTeamAfterTeamUpdate()
		{
			var indexer = GetInstance<IEntityIndexer>();
			const int targetTeamId = 1;
			const int newTargetTeamId = 10;
			var expectedAssignablesIds = new[] { 1, 4 };
			int userStoryTypeId = QueryEntityTypeProvider.USERSTORY_TYPE_ID;
			var target = new AssignableDTO
				{
					ID = expectedAssignablesIds[0],
					Name = "zagzag", 
					Description = "", 
					EntityTypeID = userStoryTypeId, 
					SquadID = targetTeamId
				};
			indexer.AddAssignableIndex(target);
			indexer.AddAssignableIndex(new AssignableDTO
			{
				ID = 2,
				Name = "zagzag",
				Description = "",
				EntityTypeID = userStoryTypeId,
				SquadID = 2
			});
			indexer.AddAssignableIndex(new AssignableDTO
			{
				ID = 3,
				Name = "qqqqq",
				Description = "wwww",
				EntityTypeID = userStoryTypeId,
				SquadID = targetTeamId
			});
			indexer.AddAssignableIndex(new AssignableDTO
			{
				ID = expectedAssignablesIds[1],
				Name = "zagzag qwerty",
				Description = "",
				EntityTypeID = userStoryTypeId,
				SquadID = targetTeamId
			});
			indexer.AddAssignableIndex(new AssignableDTO
			{
				ID = 5,
				Name = "zagzag qwerty blabla",
				Description = "",
				EntityTypeID = userStoryTypeId,
			});
			var queryRunner = GetInstance<QueryRunner>();
			var result = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { targetTeamId }
			});
			result.Total.Should(Be.EqualTo(2), "result.Total.Should(Be.EqualTo(2))");
			result.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Select(s => s.ToString()).ToArray()), "result.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Select(s => s.ToString()).ToArray()))");

			indexer.UpdateAssignableSquadIndex(new AssignableSquadDTO
			{
				AssignableSquadID = 1,
				AssignableID = target.AssignableID,
				SquadID = newTargetTeamId
			}, new AssignableSquadDTO
			{
				AssignableSquadID = 1,
				AssignableID = target.AssignableID,
				SquadID = targetTeamId
			}, new List<AssignableSquadField> {AssignableSquadField.SquadID});
			target.SquadID = newTargetTeamId;
			indexer.UpdateAssignableIndex(target, new[] {AssignableField.SquadID}, false);

			var newResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { targetTeamId }
			});
			newResult.Total.Should(Be.EqualTo(1), "newResult.Total.Should(Be.EqualTo(1))");
			newResult.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Skip(1).Select(s => s.ToString()).ToArray()), "newResult.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Skip(1).Select(s => s.ToString()).ToArray()))");

			var lastResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { newTargetTeamId }
			});
			lastResult.Total.Should(Be.EqualTo(1), "lastResult.Total.Should(Be.EqualTo(1))");
			lastResult.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Take(1).Select(s => s.ToString()).ToArray()), "lastResult.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Take(1).Select(s => s.ToString()).ToArray()))");
		}
		public void SearchUserStoryByNoTeamAfterChangeAssignableSquad()
		{
			var indexer = GetInstance<IEntityIndexer>();
			const int targetTeamId = 1;
			const int anotherTargetTeamId = 2;
			const int expectedAssignableId = 1;
			const int userStoryTypeId = QueryEntityTypeProvider.USERSTORY_TYPE_ID;
			var target = new AssignableDTO
			{
				ID = expectedAssignableId,
				Name = "zagzag",
				Description = "",
				EntityTypeID = userStoryTypeId,
				SquadID = null
			};
			indexer.AddAssignableIndex(target);
			indexer.AddAssignableIndex(new AssignableDTO
			{
				ID = 2,
				Name = "zagzag",
				Description = "",
				EntityTypeID = userStoryTypeId,
				SquadID = null
			});

			var queryRunner = GetInstance<QueryRunner>();

			var result = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = null,
				IncludeNoTeam = true
			});
			result.Total.Should(Be.EqualTo(2), "result.Total.Should(Be.EqualTo(2))");
			result.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True, "result.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True)");

			var targetAssignableSquad = new AssignableSquadDTO
			{
				AssignableSquadID = 1,
				AssignableID = expectedAssignableId,
				SquadID = targetTeamId
			};
			indexer.AddAssignableSquadIndex(targetAssignableSquad);

			var noTeamResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = null,
				IncludeNoTeam = true
			});
			noTeamResult.Total.Should(Be.EqualTo(1), "noTeamResult.Total.Should(Be.EqualTo(1))");
			noTeamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.False, "noTeamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.False)");

			var teamResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { targetTeamId },
				IncludeNoTeam = true
			});
			teamResult.Total.Should(Be.EqualTo(2), "teamResult.Total.Should(Be.EqualTo(2))");
			teamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True, "teamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True)");

			indexer.UpdateAssignableSquadIndex(new AssignableSquadDTO
			{
				AssignableSquadID = targetAssignableSquad.AssignableSquadID,
				AssignableID = targetAssignableSquad.AssignableID,
				SquadID = anotherTargetTeamId
			}, targetAssignableSquad, new List<AssignableSquadField> { AssignableSquadField.SquadID });

			var updatedNoTeamResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = null,
				IncludeNoTeam = true
			});
			updatedNoTeamResult.Total.Should(Be.EqualTo(1), "updatedNoTeamResult.Total.Should(Be.EqualTo(1))");
			updatedNoTeamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.False, "updatedNoTeamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.False)");

			var updatedTeamResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { targetTeamId }
			});
			updatedTeamResult.Total.Should(Be.EqualTo(0), "updatedTeamResult.Total.Should(Be.EqualTo(0))");
			updatedTeamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.False, "updatedTeamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.False)");

			var anotherTeamResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { anotherTargetTeamId },
				IncludeNoTeam = true
			});
			anotherTeamResult.Total.Should(Be.EqualTo(2), "anotherTeamResult.Total.Should(Be.EqualTo(2))");
			anotherTeamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True, "anotherTeamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True)");

			indexer.RemoveAssignableSquadIndex(new AssignableSquadDTO
			{
				AssignableSquadID = targetAssignableSquad.AssignableSquadID,
				AssignableID = targetAssignableSquad.AssignableID,
				SquadID = anotherTargetTeamId
			});

			var lastNoTeamResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = null,
				IncludeNoTeam = true
			});
			lastNoTeamResult.Total.Should(Be.EqualTo(2), "lastNoTeamResult.Total.Should(Be.EqualTo(2))");
			lastNoTeamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True, "lastNoTeamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True)");

			var lastTeamResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { anotherTargetTeamId }
			});
			lastTeamResult.Total.Should(Be.EqualTo(0), "lastTeamResult.Total.Should(Be.EqualTo(0))");
			lastTeamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.False, "lastTeamResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.False)");
		}
		public void SearchUserStoryByMultipleTeamsAfterChange()
		{
			var indexer = GetInstance<IEntityIndexer>();
			const int targetTeamId = 1;
			const int anotherTargetTeamId = 2;
			const int updatedTeamId = 3;
			const int expectedAssignableId = 1;
			const int userStoryTypeId = QueryEntityTypeProvider.USERSTORY_TYPE_ID;
			var target = new AssignableDTO
			{
				ID = expectedAssignableId,
				Name = "zagzag",
				Description = "",
				EntityTypeID = userStoryTypeId,
				SquadID = targetTeamId
			};
			indexer.AddAssignableIndex(target);
			var targetAssignableSquad  = new AssignableSquadDTO
			{
				AssignableSquadID = 1,
				AssignableID = expectedAssignableId,
				SquadID = targetTeamId
			};
			indexer.AddAssignableSquadIndex(targetAssignableSquad);
			target.SquadID = targetTeamId;
			indexer.UpdateAssignableIndex(target, new[] { AssignableField.SquadID }, false);
			indexer.AddAssignableSquadIndex(new AssignableSquadDTO
			{
				AssignableSquadID = 2,
				AssignableID = expectedAssignableId,
				SquadID = anotherTargetTeamId
			});
			target.SquadID = anotherTargetTeamId;
			indexer.UpdateAssignableIndex(target, new[] { AssignableField.SquadID }, false);

			var queryRunner = GetInstance<QueryRunner>();
			var targetResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { targetTeamId }
			});
			targetResult.Total.Should(Be.EqualTo(1), "targetResult.Total.Should(Be.EqualTo(1))");
			targetResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True, "targetResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True)");

			var anotherResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { anotherTargetTeamId }
			});
			anotherResult.Total.Should(Be.EqualTo(1), "anotherResult.Total.Should(Be.EqualTo(1))");
			anotherResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True, "anotherResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True)");

			indexer.UpdateAssignableSquadIndex(new AssignableSquadDTO
			{
				AssignableSquadID = targetAssignableSquad.AssignableSquadID,
				AssignableID = targetAssignableSquad.AssignableID,
				SquadID = updatedTeamId
			}, targetAssignableSquad, new List<AssignableSquadField> { AssignableSquadField.SquadID });
			target.SquadID = updatedTeamId;
			indexer.UpdateAssignableIndex(target, new[] { AssignableField.SquadID }, isIndexing: false);

			var oldResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { targetTeamId }
			});
			oldResult.Total.Should(Be.EqualTo(0), "oldResult.Total.Should(Be.EqualTo(0))");
			oldResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.False, "oldResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.False)");
			var anotherStillResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { anotherTargetTeamId }
			});
			anotherStillResult.Total.Should(Be.EqualTo(1), "anotherStillResult.Total.Should(Be.EqualTo(1))");
			anotherStillResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True, "anotherStillResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True)");
			var updatedResult = queryRunner.Run(new QueryData
			{
				Query = "zagzag",
				TeamIds = new[] { updatedTeamId }
			});
			updatedResult.Total.Should(Be.EqualTo(1), "updatedResult.Total.Should(Be.EqualTo(1))");
			updatedResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True, "updatedResult.AssignableIds.Contains(expectedAssignableId.ToString()).Should(Be.True)");
		}