Пример #1
0
        protected override MoveTask CreateBypassMoveTask()
        {
            MoveTask moveTask;

            // Если ещё не известна целевая точка патруля
            if (_patrolPointIndex == null)
            {
                var currentPatrolPointIndex = CalcCurrentPatrolPointIndex();

                IMapNode nextPatrolPoint;
                if (currentPatrolPointIndex != null)
                {
                    // Актёр уже стоит в одной из точек патруля.
                    nextPatrolPoint = GetNextPatrolPointFromPatrolPoint(currentPatrolPointIndex.Value);
                }
                else
                {
                    // Актёр не на контрольной точке.
                    // Возвращаемся на маршрут патруля.

                    nextPatrolPoint = GetNextPatrolPointFromField();
                }

                moveTask = new MoveTask(Actor, nextPatrolPoint, Map);
            }
            else
            {
                var targetPatrolPoint = _patrolRoute.Points[_patrolPointIndex.Value];

                moveTask = new MoveTask(Actor, targetPatrolPoint, Map);
            }

            return(moveTask);
        }
        public override IActorTask GetTask(IActor actor, ILogicStrategyData strategyData)
        {
            if (!strategyData.ExitNodes.Any())
            {
                Complete = true;
                return(null);
            }

            if (_moveTask == null || _moveTask.IsComplete || !_moveTask.CanExecute())
            {
                var nearbyExitNode = strategyData.ExitNodes
                                     .OrderBy(x => _map.DistanceBetween(actor.Node, x))
                                     .First();

                _moveTask = CreateMoveTask(actor, nearbyExitNode);

                if (_moveTask == null)
                {
                    Complete = true;
                    return(null);
                }

                return(_moveTask);
            }
            else
            {
                return(_moveTask);
            }
        }
Пример #3
0
        private IActorTask HandleBypassMode()
        {
            if (_moveTask == null)
            {
                return(CreateBypassMoveTask());
            }
            else
            {
                if (!_moveTask.IsComplete)
                {
                    // Если команда на перемещение к целевой точке патруля не закончена, тогда продолжаем её.
                    return(_moveTask);
                }

                // Команда на перемещение к целевой точке патруля закончена.
                // Нужно выбрать следующую целевую точку и создать команду на простой.
                _patrolPointIndex++;
                if (_patrolPointIndex >= _patrolRoute.Points.Count())
                {
                    _patrolPointIndex = 0;
                }

                _moveTask = null;
                _idleTask = new IdleTask(_actor, _decisionSource);
                _mode     = PatrolMode.Idle;
                return(_idleTask);
            }
        }
Пример #4
0
        public async System.Threading.Tasks.Task ExecuteTest_MapWithWalls_ActorAvoidWallsAsync()
        {
            // ARRANGE

            var map = await SquareMapFactory.CreateAsync(10);

            map.RemoveEdge(3, 3, 3, 4);
            map.RemoveEdge(3, 3, 2, 3);

            var expectedPath = new IMapNode[] {
                map.Nodes.Cast <HexNode>().SelectBy(4, 4),
                map.Nodes.Cast <HexNode>().SelectBy(3, 4),
                map.Nodes.Cast <HexNode>().SelectBy(2, 4),
                map.Nodes.Cast <HexNode>().SelectBy(1, 5),
            };

            var startNode  = expectedPath.First();
            var finishNode = expectedPath.Last();


            var actor = CreateActor(map, (HexNode)startNode);

            var task = new MoveTask(actor, finishNode, map);


            // ACT
            for (var step = 1; step < expectedPath.Length; step++)
            {
                task.Execute();


                // ASSERT
                actor.Node.Should().Be(expectedPath[step]);
            }
        }
Пример #5
0
        private IActorTask HandlePersuitMode()
        {
            var isAttackAllowed = CheckAttackAvailability(_targetIntruder);

            if (isAttackAllowed)
            {
                var attackTask = new AttackTask(Actor, _targetIntruder, _actService);
                return(attackTask);
            }
            else
            {
                // Маршрут до цели обновляем каждые 3 хода.
                // Для оптимизации.
                // Эффект потери цели.

                if (_pursuitCounter > 0 && _moveTask != null && _moveTask.CanExecute())
                {
                    _pursuitCounter--;
                    return(_moveTask);
                }
                else
                {
                    RefreshPursuitCounter();
                    _moveTask = new MoveTask(Actor, _targetIntruder.Node, Map);
                    return(_moveTask);
                }
            }
        }
Пример #6
0
        public override IActorTask GetTask(IActor actor, ISectorTaskSourceContext context,
                                           ILogicStrategyData strategyData)
        {
            var map = context.Sector.Map;
            var staticObjectManager = context.Sector.StaticObjectManager;
            var staticObject        = FindContainer(actor, staticObjectManager, map);

            if (staticObject == null || !staticObject.GetModule <IPropContainer>().Content.CalcActualItems().Any())
            {
                Complete = true;
                return(null);
            }

            var distance = map.DistanceBetween(actor.Node, staticObject.Node);

            if (distance <= 1)
            {
                return(TakeAllFromContainerTask(actor, staticObject, context.Sector));
            }

            var storedMoveTask = _moveTask;
            var moveTask       = MoveToContainerTask(actor, staticObject.Node, storedMoveTask, context.Sector);

            _moveTask = moveTask;
            return(moveTask);
        }
Пример #7
0
        public void ExecuteTest_MapWithWalls_ActorAvoidWalls()
        {
            // ARRANGE

            var map = new TestGridGenWallMap();

            var expectedPath = new IMapNode[] {
                map.Nodes.Cast <HexNode>().SelectBy(4, 4),
                map.Nodes.Cast <HexNode>().SelectBy(3, 4),
                map.Nodes.Cast <HexNode>().SelectBy(2, 4),
                map.Nodes.Cast <HexNode>().SelectBy(1, 5),
            };

            var startNode  = expectedPath.First();
            var finishNode = expectedPath.Last();


            var actor = CreateActor(map, (HexNode)startNode);

            var task = new MoveTask(actor, finishNode, map);


            // ACT
            for (var step = 1; step < expectedPath.Length; step++)
            {
                task.Execute();


                // ASSERT
                actor.Node.Should().Be(expectedPath[step]);
            }
        }
Пример #8
0
        public void CreateActorTask_CurrentMoveTaskWithOtherTarget_ReturnsNewMoveTask()
        {
            // ARRANGE
            var mapMock = new Mock <IMap>();
            var map     = mapMock.Object;

            var nodeMock = new Mock <IMapNode>();
            var node     = nodeMock.Object;

            var node2Mock = new Mock <IMapNode>();
            var node2     = nodeMock.Object;

            var actorMock = new Mock <IActor>();
            var actor     = actorMock.Object;

            var currentTask = new MoveTask(actor, node, map);

            var intention = new MoveIntention(node2, map);



            // ACT
            var factTask = intention.CreateActorTask(currentTask, actor);



            // ASSERT
            factTask.Should().BeOfType <MoveTask>()
            .And.Subject.As <MoveTask>().TargetNode.Should().Be(node2);
        }
Пример #9
0
        public void CreateActorTask_CurrentMoveTaskWithSameTarget_ReturnsCurrentMoveTask()
        {
            // ARRANGE
            var mapMock = new Mock <IMap>();
            var map     = mapMock.Object;

            var nodeMock = new Mock <IMapNode>();
            var node     = nodeMock.Object;

            var actorMock = new Mock <IActor>();
            var actor     = actorMock.Object;

            var currentTask = new MoveTask(actor, node, map);

            var intention = new MoveIntention(node, map);



            // ACT
            var factTask = intention.CreateActorTask(currentTask, actor);



            // ASSERT
            factTask.Should().Be(currentTask);
        }
Пример #10
0
        private IActorTask HandlePersiutMode()
        {
            var isAttackAllowed = CheckAttackAvailability(_targetIntruder);

            if (isAttackAllowed)
            {
                var attackTask = new AttackTask(_actor, _targetIntruder, _actService);
                return(attackTask);
            }
            else
            {
                // Маршрут до цели обновляем каждые 3 хода.
                // Для оптимизации.
                // Эффект потери цели.

                //TODO Сделать тест аналогичный GetActorTasks_PatrolsTryToAttackEnemy_ReturnsMoveTask
                if (_persuitCounter > 0 && _moveTask != null)
                {
                    _persuitCounter--;
                    return(_moveTask);
                }
                else
                {
                    RefreshPersuiteCounter();
                    _moveTask = new MoveTask(_actor, _targetIntruder.Node, _map);
                    return(_moveTask);
                }
            }
        }
Пример #11
0
        public async System.Threading.Tasks.Task ExecuteTest_FindingPathAndMove_IsCompleteTrueAsync()
        {
            // ARRANGE

            var map = await SquareMapFactory.CreateAsync(10);

            var expectedPath = new IMapNode[] {
                map.Nodes.Cast <HexNode>().SelectBy(4, 4),
                map.Nodes.Cast <HexNode>().SelectBy(3, 4),
                map.Nodes.Cast <HexNode>().SelectBy(2, 4),
                map.Nodes.Cast <HexNode>().SelectBy(1, 5),
            };

            var startNode  = expectedPath.First();
            var finishNode = expectedPath.Last();


            var actor = CreateActor(map, (HexNode)startNode);

            var task = new MoveTask(actor, finishNode, map);



            // ACT
            for (var step = 1; step < expectedPath.Length; step++)
            {
                task.Execute();
            }



            // ASSERT
            task.IsComplete.Should().BeTrue();
        }
Пример #12
0
        private MoveTask CreateBypassMoveTask(IActor actor, ILogicStrategyData strategyData)
        {
            IEnumerable <IGraphNode> availableNodes;
            var frontNodes = WriteObservedNodes(actor, strategyData).ToArray();

            if (frontNodes.Any())
            {
                availableNodes = frontNodes;
            }
            else
            {
                availableNodes = strategyData.ObserverdNodes;
            }

            var availableNodesArray = availableNodes as HexNode[] ?? availableNodes.ToArray();

            for (var i = 0; i < 3; i++)
            {
                var targetNode = DecisionSource.SelectTargetRoamingNode(availableNodesArray);

                if (Map.IsPositionAvailableFor(targetNode, actor))
                {
                    var moveTask = new MoveTask(actor, targetNode, Map);

                    return(moveTask);
                }
            }

            return(null);
        }
Пример #13
0
        private void AnimateMoveTask(MoveTask moveTask, bool isUndo)
        {
            MoveAnimationsFactory moveAnimationsFactory = new MoveAnimationsFactory();

            foreach (var pieceMove in moveTask.MovedPiecesCoordinates)
            {
                Coordinate fromCoordinate = isUndo ? pieceMove.Item2 : pieceMove.Item1;
                Coordinate toCoordinate   = isUndo ? pieceMove.Item1 : pieceMove.Item2;

                Point animationStartPoint = GetCoordinatePositionOnBoard(fromCoordinate);
                Point animationEndPoint   = GetCoordinatePositionOnBoard(toCoordinate);

                ContentPresenter pieceItemView = (ContentPresenter)piecesItemsControl.ContainerFromItem(ViewModel.GetPiece(toCoordinate));
                moveAnimationsFactory.AddMoveAnimation(pieceItemView, animationStartPoint, animationEndPoint);
            }

            if (moveTask.CapturedPieceCoordinate != null)
            {
                // if is not undo the removed piece is marked to be removed and only removed after the animation
                ChessPieceViewModel removedPiece  = isUndo ? ViewModel.GetPiece(moveTask.CapturedPieceCoordinate) : ViewModel.GetRemovedPiece(moveTask.CapturedPieceCoordinate);
                ContentPresenter    pieceItemView = (ContentPresenter)piecesItemsControl.ContainerFromItem(removedPiece);
                moveAnimationsFactory.AddRemoveAnimation(pieceItemView);
            }

            moveAnimationsFactory.StoryBoard.Completed += (o, e) =>
            {
                moveTask.CompleteTask();
                IsHitTestVisible = true;
            };

            moveAnimationsFactory.StoryBoard.Begin();
            // dont allow user interactions with the board for the duration of the animation
            IsHitTestVisible = false;
        }
Пример #14
0
        public async Task ExecuteTest_MapWithWalls_ActorAvoidWallsAsync()
        {
            // ARRANGE

            var map = await SquareMapFactory.CreateAsync(10).ConfigureAwait(false);

            map.RemoveEdge(3, 3, 3, 4);
            map.RemoveEdge(3, 3, 2, 3);

            var expectedPath = CreateExpectedPath(map);

            var startNode  = expectedPath.First();
            var finishNode = expectedPath.Last();

            var actor = CreateActor(map, (HexNode)startNode);

            var contextMock = new Mock <IActorTaskContext>();
            var context     = contextMock.Object;

            var task = new MoveTask(actor, context, finishNode, map);

            // ACT
            for (var step = 1; step < expectedPath.Length; step++)
            {
                task.Execute();

                // ASSERT
                actor.Node.Should().Be(expectedPath[step]);
            }
        }
Пример #15
0
        public async Task ExecuteTest_FindingPathAndMove_IsCompleteTrueAsync()
        {
            // ARRANGE

            var map = await SquareMapFactory.CreateAsync(10).ConfigureAwait(false);

            var expectedPath = CreateExpectedPath(map);

            var startNode  = expectedPath.First();
            var finishNode = expectedPath.Last();

            var actor = CreateActor(map, (HexNode)startNode);

            var contextMock = new Mock <IActorTaskContext>();
            var context     = contextMock.Object;

            var task = new MoveTask(actor, context, finishNode, map);

            // ACT
            for (var step = 1; step < expectedPath.Length; step++)
            {
                task.Execute();
            }

            // ASSERT
            task.IsComplete.Should().BeTrue();
        }
Пример #16
0
        public List <TaskBase> GetTaskTypes(int taskCount)
        {
            var tasks = new List <TaskBase>();

            var r = new Random();

            for (var i = 0; i < taskCount; i++)
            {
                if (i == 0)
                {
                    tasks.Add(new MoveTask());
                }
                else if (i == 1 && taskCount > 2)
                {
                    tasks.Add(new MoveTask());
                }
                else
                {
                    tasks.Add(new BombTask());
                }
            }

            // Make sure there is at least one move-action if more than 1 task
            var noMove = tasks.Any(t => t.GetType() != typeof(MoveTask)) && tasks.Count > 1;

            if (noMove)
            {
                tasks[0] = new MoveTask();
            }

            return(tasks);
        }
Пример #17
0
        private MoveTask CreateBypassMoveTask(IActor actor, ILogicStrategyData strategyData, ISector sector)
        {
            var map = sector.Map;

            var frontNodes = WriteObservedNodesOrGetFromFow(actor, strategyData, sector).ToArray();

            if (!frontNodes.Any())
            {
                return(null);
            }

            var availableNodesArray = frontNodes as HexNode[] ?? frontNodes.ToArray();

            if (availableNodesArray.Length == 0)
            {
                // There is no nodes available to roaming.
                // We can do nothing.
                return(null);
            }

            for (var i = 0; i < 3; i++)
            {
                var targetNode = DecisionSource.SelectTargetRoamingNode(availableNodesArray);

                if (map.IsPositionAvailableFor(targetNode, actor))
                {
                    var context  = new ActorTaskContext(sector);
                    var moveTask = new MoveTask(actor, context, targetNode, map);

                    return(moveTask);
                }
            }

            return(null);
        }
        public override IActorTask GetTask(IActor actor, ISectorTaskSourceContext context,
                                           ILogicStrategyData strategyData)
        {
            var triggerTarget = strategyData.TriggerIntuder;

            if (triggerTarget == null)
            {
                throw new InvalidOperationException(
                          $"Assign {nameof(strategyData.TriggerIntuder)} with not null valie in related trigger.");
            }

            var targetCanBeDamaged = triggerTarget.CanBeDamaged();

            if (!targetCanBeDamaged)
            {
                Complete = true;
                return(null);
            }

            var attackParams = CheckAttackAvailability(actor, triggerTarget, context.Sector.Map);

            if (attackParams.IsAvailable)
            {
                var act = attackParams.CombatAct;

                var taskContext = new ActorTaskContext(context.Sector);

                var attackTask = new AttackTask(actor, taskContext, triggerTarget, act, _actService);
                return(attackTask);
            }

            // Маршрут до цели обновляем каждые 3 хода.
            // Для оптимизации.
            // Эффект потери цели.
            if (_refreshCounter > 0 && _moveTask?.CanExecute() == true)
            {
                _refreshCounter--;
                return(_moveTask);
            }

            var map = context.Sector.Map;

            _refreshCounter = REFRESH_COUNTER_VALUE;
            var targetIsOnLine = map.TargetIsOnLine(actor.Node, triggerTarget.Node);

            if (targetIsOnLine)
            {
                var taskContext = new ActorTaskContext(context.Sector);
                var moveModule  = actor.Person.GetModule <IMovingModule>();
                var moveCost    = moveModule.CalculateCost();

                _moveTask = new MoveTask(actor, taskContext, triggerTarget.Node, map, moveCost);
                return(_moveTask);
            }

            // Цел за пределами видимости. Считается потерянной.
            return(null);
        }
Пример #19
0
        public void Move(Vector2 position, float time)
        {
            if (moveTask != null)
            {
                moveTask.Stop();
            }

            moveTask           = new MoveTask(rectTransform, position, time, tickableManager);
            moveTask.Complete += MoveTaskComplete;
        }
        public override IActorTask GetTask(IActor actor, ILogicStrategyData strategyData)
        {
            if (_target == null)
            {
                _target = GetTarget(actor);
            }

            var targetCanBeDamaged = _target.CanBeDamaged();

            if (!targetCanBeDamaged)
            {
                Complete = true;
                return(null);
            }

            var attackParams = CheckAttackAvailability(actor, _target);

            if (attackParams.IsAvailable)
            {
                var act        = attackParams.TacticalAct;
                var attackTask = new AttackTask(actor, _target, act, _actService);
                return(attackTask);
            }
            else
            {
                // Маршрут до цели обновляем каждые 3 хода.
                // Для оптимизации.
                // Эффект потери цели.

                if (_refreshCounter > 0 && _moveTask?.CanExecute() == true)
                {
                    _refreshCounter--;
                    return(_moveTask);
                }
                else
                {
                    _refreshCounter = REFRESH_COUNTER_VALUE;
                    var targetIsOnLine = _map.TargetIsOnLine(actor.Node, _target.Node);

                    if (targetIsOnLine)
                    {
                        _moveTask = new MoveTask(actor, _target.Node, _map);
                        return(_moveTask);
                    }
                    else
                    {
                        // Цел за пределами видимости. Считается потерянной.
                        return(null);
                    }
                }
            }
        }
Пример #21
0
        private IActorTask HandleBypassMode()
        {
            if (_moveTask == null)
            {
                _moveTask = CreateBypassMoveTask();

                if (_moveTask != null)
                {
                    return(_moveTask);
                }
                else
                {
                    // Это может произойти, если актёр не выбрал следующий узел.
                    // Тогда переводим актёра в режим ожидания.

                    _idleTask = new IdleTask(Actor, DecisionSource);
                    _mode     = Mode.Idle;
                    return(_idleTask);
                }
            }
            else
            {
                if (!_moveTask.IsComplete)
                {
                    // Если команда на перемещение к целевой точке патруля не закончена,
                    // тогда продолжаем её.
                    // Предварительно проверяем, не мешает ли что-либо её продолжить выполнять.
                    if (!_moveTask.CanExecute())
                    {
                        _moveTask = CreateBypassMoveTask();
                    }

                    if (_moveTask != null)
                    {
                        return(_moveTask);
                    }

                    _idleTask = new IdleTask(Actor, DecisionSource);
                    _mode     = Mode.Idle;
                    return(_idleTask);
                }

                // Команда на перемещение к целевому узлу закончена.
                // Нужно выбрать следующую целевую точку и создать команду на простой.
                ProcessMovementComplete();

                _moveTask = null;
                _idleTask = new IdleTask(Actor, DecisionSource);
                _mode     = Mode.Idle;
                return(_idleTask);
            }
        }
Пример #22
0
    public override void PerformTask(Task task)
    {
        MoveTask moveTask  = (task as MoveTask);
        Vector3  targetPos = moveTask.GetTaskPosition();

        if (Vector2.Distance(unit.transform.position, targetPos) <= moveTask.GetTaskRange())
        {
            unit.tasks.FinishTask();
            return;
        }

        unit.transform.position = Vector2.MoveTowards(unit.transform.position, targetPos, speed * Time.deltaTime);
        unit.transform.position = Utils.CorrectPosition(unit.transform.position);
    }
Пример #23
0
        private MoveTask CreateMoveTask(IActor actor, IMapNode targetExitNode)
        {
            Debug.Assert((targetExitNode as HexNode)?.IsObstacle != true,
                         "Узел с выходом не должен быть препятствием.");

            if (!_map.IsPositionAvailableFor(targetExitNode, actor))
            {
                return(null);
            }

            var moveTask = new MoveTask(actor, targetExitNode, _map);

            return(moveTask);
        }
Пример #24
0
        public void Update(GameTime gt)
        {
            if (_tasks.Count > 0)
            {
                Task temp = _tasks.First;
                if (temp.IsFinished)
                {
                    _tasks.Dequeue();
                    if (_tasks.Count == 0)
                    {
                        return;
                    }
                    temp = _tasks.First;
                }
                //Ewwwww.... But I dunno what else to do
                if (!temp.HasStarted)
                {
                    temp.HasStarted = true;
                    switch (temp.TaskName)
                    {
                    case "MoveTask":
                        MoveTask t = (MoveTask)temp;
                        t.StartTask(Position);
                        break;

                    case "GatherResourceTask":
                        GatherResourceTask grt = (GatherResourceTask)temp;
                        grt.StartTask(this);
                        break;
                    }
                }
                switch (temp.TaskName)
                {
                case "MoveTask":
                    MoveTask t = (MoveTask)temp;
                    Vector2  p = Position;
                    t.DoTask(Speed, ref p);
                    Position = p;
                    break;

                case "GatherResourceTask":
                    GatherResourceTask grt = (GatherResourceTask)temp;
                    int food = FoodCount;
                    grt.DoTask(ref food, gt);
                    FoodCount = food;
                    break;
                }
            }
        }
Пример #25
0
        private MoveTask CreateMoveTask(IActor actor, IGraphNode targetExitNode)
        {
            var targetNodeIsBlockedByObstacles = GetObstableInNode(_sector, targetExitNode);

            Debug.Assert(!targetNodeIsBlockedByObstacles,
                         "Узел с выходом не должен быть препятствием.");

            if (!_map.IsPositionAvailableFor(targetExitNode, actor))
            {
                return(null);
            }

            var moveTask = new MoveTask(actor, targetExitNode, _map);

            return(moveTask);
        }
Пример #26
0
        private MoveTask MoveToContainerTask(IActor actor, IGraphNode containerMapNode, MoveTask storedMoveTask)
        {
            var moveTask = storedMoveTask;

            if (storedMoveTask == null)
            {
                moveTask = new MoveTask(actor, containerMapNode, _map);
            }

            if (moveTask.IsComplete || !moveTask.CanExecute())
            {
                Complete = true;
                return(null);
            }

            return(moveTask);
        }
Пример #27
0
        public override IActorTask GetTask(IActor actor, ILogicStrategyData strategyData)
        {
            if (MoveTask == null)
            {
                MoveTask = CreateBypassMoveTask(actor, strategyData);

                if (MoveTask != null)
                {
                    return(MoveTask);
                }
                else
                {
                    // Это может произойти, если актёр не выбрал следующий узел.
                    // Тогда переводим актёра в режим ожидания.

                    IdleTask = new IdleTask(actor, DecisionSource);
                    return(IdleTask);
                }
            }
            else
            {
                if (!MoveTask.IsComplete)
                {
                    // Если команда на перемещение к целевой точке патруля не закончена,
                    // тогда продолжаем её.
                    // Предварительно проверяем, не мешает ли что-либо её продолжить выполнять.
                    if (!MoveTask.CanExecute())
                    {
                        MoveTask = CreateBypassMoveTask(actor, strategyData);
                    }

                    if (MoveTask != null)
                    {
                        return(MoveTask);
                    }

                    IdleTask = new IdleTask(actor, DecisionSource);
                    return(IdleTask);
                }
                else
                {
                    Complete = true;
                    return(null);
                }
            }
        }
        public IEnumerator move_task()
        {
            Human      human          = CreateHuman();
            Vector2Int targetPosition = human.MotionComponent.GridPosition + new Vector2Int(-10, 10);
            var        moveTask       = new MoveTask(human.MotionComponent, targetPosition);

            yield return(AddTaskAndWaitUntilFinished(moveTask, human.CommandProcessor));

            //test position
            if (human.MotionComponent.GridPosition != targetPosition)
            {
                Assert.Fail();
            }

            human.Die();
            Assert.Pass();
        }
Пример #29
0
        public async Task Run_ReturnsNoContentOnSuccess()
        {
            var handler   = new Mock <ICommandHander <MoveTaskCommand> >();
            var container = new Container();
            var parent    = new ParentDTO();
            var listId    = Guid.NewGuid().ToString();
            var taskId    = Guid.NewGuid().ToString();

            handler.Setup(h => h.Execute(It.IsAny <MoveTaskCommand>())).Returns(Task.CompletedTask);
            container.RegisterInstance(handler.Object);
            container.RegisterInstance(_telemetryClient);
            MoveTask.Container = container;

            var result = await MoveTask.Run(parent, listId, taskId) as NoContentResult;

            Assert.IsNotNull(result);
        }
Пример #30
0
        public async Task Run_ReturnsServerErrorOnServerError()
        {
            var handler   = new Mock <ICommandHander <MoveTaskCommand> >();
            var container = new Container();
            var parent    = new ParentDTO();
            var listId    = Guid.NewGuid().ToString();
            var taskId    = Guid.NewGuid().ToString();

            handler.Setup(h => h.Execute(It.IsAny <MoveTaskCommand>()))
            .ThrowsAsync(new Exception());
            container.RegisterInstance(handler.Object);
            container.RegisterInstance(_telemetryClient);
            MoveTask.Container = container;

            var result = await MoveTask.Run(parent, listId, taskId) as InternalServerErrorResult;

            Assert.IsNotNull(result);
        }