public void BackUpStateTest() { createContext(); var backUpGameState = StateFactory.Create(EState.BACK_UP, _context); Assert.IsNotNull(backUpGameState.Commands); Assert.IsTrue(backUpGameState.Commands.Count > 0); Assert.IsTrue(backUpGameState.Commands.FindAll(x => x is EndGameCommand).Count == 1); }
public void StartGameStateTest() { createContext(); var startGameState = StateFactory.Create(EState.START, _context); Assert.IsNotNull(startGameState.Commands); Assert.IsTrue(startGameState.Commands.Count == 2); Assert.IsTrue(startGameState.Commands.FindAll(x => x is StartGameCommand).Count == 1); Assert.IsTrue(startGameState.Commands.FindAll(x => x is CloseGameCommand).Count == 1); }
public void DecidingStateTest() { createContext(); var decidingGameState = StateFactory.Create(EState.DECIDING, _context); Assert.IsNotNull(decidingGameState.Commands); Assert.IsTrue(decidingGameState.Commands.Count == 4); Assert.IsTrue(decidingGameState.Commands.FindAll(x => x is OpenCommand).Count == 1); Assert.IsTrue(decidingGameState.Commands.FindAll(x => x is SkipCommand).Count == 1); Assert.IsTrue(decidingGameState.Commands.FindAll(x => x is MakeSnapshotCommand).Count == 1); Assert.IsTrue(decidingGameState.Commands.FindAll(x => x is EndGameCommand).Count == 1); }
public void Execute() { if (!EState.DECIDING.Equals(eState) && !EState.BACK_UP.Equals(eState)) { throw new Exception("Bad state!"); } if (createRobot) { context.SetRobot(RobotFactoryInvoker.CreateRobot()); } context.SetState(StateFactory.Create(eState, context)); }
public void ChangeState(int state, object[] extraArgs) { if (CurrentState == state) { return; } CurrentState = state; if (StateHandler != null) { StateHandler.Dispose(); StateHandler = null; } StateHandler = StateFactory.Create(state, extraArgs); StateHandler.Initialize(); }
void CommandParser_ParagraphComplete(SymbianParserLib.BaseStructures.ParserElementBase aElement) { TState state = (TState)aElement.Tag; State.State nextState = StateFactory.Create(state, this); // if (iStateObject != null) { iStateObject.Finalise(); iStateObject = null; } // if (nextState == null) { throw new ArgumentException("Invalid state: " + state); } // iStateObject = nextState; iCurrentState = state; // #if DEBUG System.Diagnostics.Debug.WriteLine("SWITCHING STATE: => " + iStateObject.GetType().ToString()); #endif }
public void Execute() { context.Robot.MinusBattery(2); context.SetState(StateFactory.Create(EState.DECIDING, context)); }
public static PaymentTransactionState Create(string id, string msisdn, string orderId, DateTime transactionDateTime) => StateFactory.Create(() => new PaymentTransactionState(msisdn, orderId, transactionDateTime) , state => state.ApplyEvent(new Events.V1.TransactionCreatedDomainEvent(id, msisdn, orderId, transactionDateTime)));
public void Execute() { context.SetState(StateFactory.Create(EState.END, context)); }
public void Execute() { robotSnapshot.BackUp(context); context.SetState(StateFactory.Create(EState.DECIDING, context)); }
public async Task <ActionResult <DataResponse <StateExtModel> > > Put([FromBody] StateModel model, [FromRoute] string id) { DataResponse <StateExtModel> response = new DataResponse <StateExtModel>(); StateExtModel _DTO = null; string errorMsg = String.Empty; try { if (ModelState.IsValid && model != null) { // Custom Validations if (!StateFactory.ValidateModel(model, id, out errorMsg)) { response.Code = ResponseCode.FAILED; response.Description = ResponseDescription.FAILED; response.Message = errorMsg; response.Data = _DTO; return(BadRequest(response)); } Country _theCountry = await _unitOfWork.Countries.GetAsync(model.CountryId).ConfigureAwait(false); // Check Entity Exist if (_unitOfWork.States.CheckExist(model.Name, model.Code, _theCountry, out errorMsg, id)) { response.Code = ResponseCode.FAILED; response.Description = ResponseDescription.FAILED; response.Message = errorMsg; response.Data = _DTO; return(BadRequest(response)); } // Generate entity var _entity = StateFactory.Create(model, _theCountry); // Create user var _state = await _unitOfWork.States.UpdateAsync(_entity).ConfigureAwait(false); int done = await _unitOfWork.CompleteAsync().ConfigureAwait(false); if (done > 0) { _DTO = _mapper.Map <StateExtModel>(_state); response.Code = ResponseCode.SUCCESS; response.Description = ResponseDescription.SUCCESS; response.Message = null; response.Data = _DTO; return(Ok(_DTO)); } } response.Code = ResponseCode.FAILED; response.Description = ResponseDescription.FAILED; response.Message = "Invalid user input"; response.Data = _DTO; return(BadRequest(response)); } catch (Exception ex) { Guid _ErrorCode = Guid.NewGuid(); Log.Error("Fatal Error [{ErrorCode}]: {Message}", _ErrorCode, ex.Message); response.Code = ResponseCode.SYSTEM_ERROR; response.Description = ResponseDescription.SYSTEM_ERROR; response.Message = $"System Error: Something went wrong here! Kindly contact the support with this error code [{_ErrorCode}]"; response.Data = _DTO; return(BadRequest(response)); } }