Beispiel #1
0
        public async Task <DeleteLaunchResult> WaitForGameLaunchEndedAndRecordAsync()
        {
            IAction            action = _actionRecorder.CreateToolAction(ActionType.GameLaunchWaitForEnd);
            DeleteLaunchResult result = null;

            async Task WaitAndRecordTask()
            {
                result = await _gameLaunchBeHelper.WaitUntilGameLaunchEndedAsync(
                    LaunchName, new NothingToCancel(), action);

                EndReason?eReason = result.DeletedLaunch?.GameLaunchEnded?.EndReason;
                var       endData = new DeveloperLogEvent
                {
                    GameLaunchData = new GameLaunchData
                    {
                        LaunchId = LaunchId, EndReason = (int?)eReason
                    }
                };

                action.UpdateEvent(endData);
                if (eReason.HasValue && eReason != EndReason.GameExitedWithSuccessfulCode)
                {
                    throw new GameLaunchFailError("Game stopped due to unexpected reason.");
                }
            }

            await action.RecordAsync(WaitAndRecordTask());

            return(result);
        }
        public async Task WaitForGameLaunchEndedAndRecordTestAsync(EndReason?reason, bool throws)
        {
            _target = GetGameLaunch(false);
            var action = Substitute.For <IAction>();
            DeveloperLogEvent devEvent = SetupUpdateEvent(action);

            action.RecordAsync(Arg.Any <Task>()).Returns(callInfo => callInfo.Arg <Task>());
            _actionRecorder.CreateToolAction(ActionType.GameLaunchWaitForEnd).Returns(action);
            var endResult = new DeleteLaunchResult(
                GetGameLaunch(GameLaunchState.GameLaunchEnded, reason), true);

            _gameLaunchBeHelper
            .WaitUntilGameLaunchEndedAsync(_launchName, Arg.Any <ICancelable>(), action)
            .Returns(Task.FromResult(endResult));

            if (throws)
            {
                Assert.ThrowsAsync <GameLaunchFailError>(
                    async() => await _target.WaitForGameLaunchEndedAndRecordAsync());
            }
            else
            {
                await _target.WaitForGameLaunchEndedAndRecordAsync();
            }

            Assert.That(devEvent.GameLaunchData.LaunchId, Is.EqualTo(_launchId));
            Assert.That(devEvent.GameLaunchData.EndReason, Is.EqualTo((int?)reason));
            await action.Received(1).RecordAsync(Arg.Any <Task>());
        }