// GET: Engine public ActionResult Index() { List <Engine> engines = _uow.EngineRepository.GetAll(); List <EngineViewModel> engineViewModels = EngineViewModel.ToList(engines); return(View(engineViewModels)); }
public async Task ShouldCreateEngineWithEmptyDb() { using (var context = new MockContext(DbHelper.GetNewDbOptions <MockContext>())) { var service = new EngineService(context); var engineVm = new EngineViewModel { Capacity = 1600, Configuration = "Inline 4", FuelType = "Petrol" }; var isCreateSuccess = await service.CreateNewEngine(engineVm); var engine = context.Engines.First(); Assert.True(isCreateSuccess); Assert.Single(context.Engines); Assert.Equal(engineVm.Capacity, engine.Capacity); Assert.Equal(engineVm.Configuration, engine.Configuration); Assert.Equal(engineVm.FuelType, engine.FuelType); } }
private void PerformMoveCalculations(int depth) { Bitmap board = PieceFinderViewModel.GetInstance().FindPieces(this.GameBoard); // Ensure kings are on the board and game state makes some degree of sense if (!this.PassesSanityChecks()) { return; } DateTime startTime = DateTime.Now; string nextMove = string.Empty; // Calculate best move string newFen = this.GameBoard.GenerateFEN(); if (newFen != this.LastFen) { // Use the engine to calculate the next best move nextMove = Cuckoo.simplyCalculateMove(newFen, depth); // Inform view of updates this.UpdateBoardCallback(board, nextMove, EngineViewModel.GetInstance().PlayingWhite); this.LastFen = newFen; } TimeSpan elapsedTime = DateTime.Now - startTime; }
public async Task ShouldCreateEngineWithExistingDb() { var dbOptions = DbHelper.GetNewDbOptions <MockContext>(); await CreateTestDatabase(dbOptions); using (var context = new MockContext(dbOptions)) { var service = new EngineService(context); var engineVm = new EngineViewModel { Capacity = 1600, Configuration = "Inline 4", FuelType = "Petrol" }; var isCreateSuccess = await service.CreateNewEngine(engineVm); var engines = context.Engines; var engine1 = engines.First(); var engine5 = engines.Last(); Assert.True(isCreateSuccess); Assert.Equal(5, engines.Count()); Assert.Equal(2400, engine1.Capacity); Assert.Equal("Inline 4 Vtec", engine1.Configuration); Assert.Equal("Petrol", engine1.FuelType); Assert.Equal(engineVm.Capacity, engine5.Capacity); Assert.Equal(engineVm.Configuration, engine5.Configuration); Assert.Equal(engineVm.FuelType, engine5.FuelType); } }
/// <summary> /// 获取发动机参数 /// </summary> /// <param name="code"></param> /// <returns></returns> public static EngineViewModel GetEngineOther(string code, string mto) { TopLineEngineQueueModel queueModel = new TopLineEngineQueueModel { EngineCode = code, EngineMTO = mto }; if (!string.IsNullOrEmpty(code)) { LEngineTypeModel engineType = LocalSQLHandler.LEngineType.Get(code); queueModel.EngineType = engineType?.TypeName; if (!string.IsNullOrEmpty(mto)) { LEngineCodeModel autoType = LocalSQLHandler.LEngineCode.Get(mto); queueModel.TCaseType = autoType?.TCaseType; } else { queueModel = MSSQLHandler.TopLineEngineQueue.Get(code); } } string lmpstr = queueModel.EngineType + " " + queueModel.TCaseType; return(EngineViewModel.CreateModel(queueModel.EngineCode, queueModel.EngineMTO, queueModel.EngineType, lmpstr)); }
public GeometryModel3D ConvertOne( EngineViewModel engine ) { var white = Color.FromRgb(255, 255, 255); var whiteBrush = new SolidColorBrush(white); var model = new GeometryModel3D(GetGeometry(), new DiffuseMaterial(whiteBrush)); var transform = new Transform3DGroup(); var scaleTransform = new ScaleTransform3D(); var translateTransform = new TranslateTransform3D(); transform.Children.Add(scaleTransform); transform.Children.Add(translateTransform); scaleTransform.ScaleX = 3; scaleTransform.ScaleY = 3; var powerBinding = new Binding("Power") {Mode = BindingMode.OneWay, Source = engine}; BindingOperations.SetBinding( scaleTransform, ScaleTransform3D.ScaleZProperty, powerBinding); translateTransform.OffsetX = engine.OffsetX; translateTransform.OffsetY = engine.OffsetY; model.Transform = transform; return model; }
public JsonResult GetEngineList() { return(ExecuteFunctionRun(() => { System.Data.DataTable table = this.Connection.GetLogicUnitTable(); List <EngineViewModel> list = new List <EngineViewModel>(); if (table != null) { foreach (DataRow row in table.Rows) { EngineViewModel model = new EngineViewModel() { Code = row[OThinker.Clusterware.LogicUnitConfig.PropertyName_Code] + string.Empty, DBType = ((OThinker.Data.Database.DatabaseType) int.Parse(row[OThinker.Clusterware.LogicUnitConfig.PropertyName_DBType] + string.Empty)).ToString(), DBServer = row[OThinker.Clusterware.LogicUnitConfig.PropertyName_DBServer] + string.Empty, DBName = row[OThinker.Clusterware.LogicUnitConfig.PropertyName_DBName] + string.Empty, LogDBType = ((OThinker.Data.Database.DatabaseType) int.Parse(row[OThinker.Clusterware.LogicUnitConfig.PropertyName_LogDBType] + string.Empty)).ToString(), LogDBServer = row[OThinker.Clusterware.LogicUnitConfig.PropertyName_LogDBServer] + string.Empty, LogDBName = row[OThinker.Clusterware.LogicUnitConfig.PropertyName_LogDBName] + string.Empty, UnitState = (row[OThinker.Clusterware.LogicUnitConfig.PropertyName_UnitState] + string.Empty == "1") ? "运行状态" : "挂起状态" }; list.Add(model); } } return Json(CreateLigerUIGridData(list.ToArray()), JsonRequestBehavior.AllowGet); })); }
public async Task <IActionResult> Create(EngineViewModel model) { if (ModelState.IsValid) { try { _context.Add(new Models.Engine() { Name = model.Name, SeaLevel = new Models.Performance() { Isp = model.SeaLevel.Isp, Thrust = model.SeaLevel.Thrust }, Vacuum = new Models.Performance() { Isp = model.Vacuum.Isp, Thrust = model.Vacuum.Thrust } }); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to create new engine"); } } return(View(model)); }
/// <summary> /// 获取发动机参数 /// </summary> /// <param name="code"></param> /// <returns></returns> public EngineViewModel GetEngineOther(string code, string mto) { TopLineEngineQueueModel queueModel = new TopLineEngineQueueModel { EngineCode = code, EngineMTO = mto }; if (!string.IsNullOrEmpty(code)) { EngineTypeModel engineType = DbDataCache.GetEngineType(code); queueModel.EngineType = engineType?.TypeName; if (!string.IsNullOrEmpty(mto)) { EngineAutoTypeModel autoType = DbDataCache.GetTCaseType(mto); queueModel.TCaseType = autoType?.TCaseType; } else { queueModel = TopLineEngineQueue.Get(code); } } string lmpstr = queueModel.EngineType + " " + queueModel.TCaseType; return(EngineViewModel.CreateModel(queueModel.EngineCode, queueModel.EngineMTO, queueModel.EngineType, lmpstr)); }
public async Task <IActionResult> Post([FromBody] EngineViewModel engineViewModel) { if (!await engineService.CreateNewEngine(engineViewModel)) { return(BadRequest($"Unable to create engine for: {JsonConvert.SerializeObject(engineViewModel)}")); } return(NoContent()); }
public ActionResult Edit([Bind(Include = "ID,Type,Cylinders,CoolingSystem,Capacity,Horsepower,CreatedAt,UpdatedAt")] EngineViewModel engineViewModel) { if (ModelState.IsValid) { Engine engine = TransformToDatabaseModel(engineViewModel); _uow.EngineRepository.CreateOrUpdate(engine); return(RedirectToAction("Index")); } return(View(engineViewModel)); }
protected override void OnUpdate() { if (EngineViewModel.GetInstance().FastMode) { this.PerformMoveCalculations(3); } else { this.PerformMoveCalculations(7); } }
public void UpdateSquare(int x, int y, GamePiece.PieceName pieceName, GamePiece.PieceColor pieceColor) { // Adjust coords since we're looking at it 'upside down' if (!EngineViewModel.GetInstance().PlayingWhite) { y = (GameBoard.SquareCount - 1) - y; x = (GameBoard.SquareCount - 1) - x; } Pieces[x, y].Name = pieceName; Pieces[x, y].Color = pieceColor; }
private void MakeEnginesViewBag(EngineViewModel engineViewModel = null) { List <Engine> engine = _uow.EngineRepository.GetAll(); List <EngineViewModel> engineViewModels = EngineViewModel.ToList(engine); if (engineViewModel != null) { ViewBag.Engines = new SelectList(engineViewModels, "ID", "Info", engineViewModel.ID); } else { ViewBag.Engines = new SelectList(engineViewModels, "ID", "Info"); } }
private Engine TransformToDatabaseModel(EngineViewModel engineViewModel) { return(new Engine() { ID = engineViewModel.ID, Type = engineViewModel.Type, Cylinders = engineViewModel.Cylinders, CoolingSystem = engineViewModel.CoolingSystem, Capacity = engineViewModel.Capacity, Horsepower = engineViewModel.Horsepower, CreatedAt = engineViewModel.CreatedAt, UpdatedAt = engineViewModel.UpdatedAt }); }
public void AutoSetup() { EngineViewModel.GetInstance().WhiteCanCastleKS = true; EngineViewModel.GetInstance().WhiteCanCastleQS = true; EngineViewModel.GetInstance().BlackCanCastleKS = true; EngineViewModel.GetInstance().BlackCanCastleQS = true; for (int column = 0; column < GameBoard.SquareCount; column++) { for (int row = 0; row < GameBoard.SquareCount; row++) { if (this.Pieces[row, column].Name == GamePiece.PieceName.None) { continue; } if (this.Pieces[row, column].Color == GamePiece.PieceColor.White) { if (EngineViewModel.GetInstance().PlayingWhite) { EngineViewModel.GetInstance().PlayingWhite = false; EngineViewModel.GetInstance().WhiteToMove = false; } else { EngineViewModel.GetInstance().PlayingWhite = true; EngineViewModel.GetInstance().WhiteToMove = true; } return; } else if (this.Pieces[row, column].Color == GamePiece.PieceColor.Black) { if (EngineViewModel.GetInstance().PlayingWhite) { EngineViewModel.GetInstance().PlayingWhite = true; EngineViewModel.GetInstance().WhiteToMove = true; } else { EngineViewModel.GetInstance().PlayingWhite = false; EngineViewModel.GetInstance().WhiteToMove = false; } return; } } } }
public AddEngineForm(string title, EngineViewModel engine, List <EngineViewModel> engineViewModels) { InitializeComponent(); Title = title + " os engine"; BtnAccept.Content = OsLocalization.Entity.ButtonAccept; if (engine == null) { engine = new EngineViewModel(); } DataContext = engine; _engine = engine; _engineViewModels = engineViewModels; }
private void ButtonAdd_Click(object sender, RoutedEventArgs e) { if (_vm == null) { return; } var engine = new EngineViewModel(); AddEngineForm form = new AddEngineForm(OsLocalization.Entity.BtnAdd, engine, _vm.Engines.ToList()); var result = form.ShowDialog(); if (result.HasValue && result.Value == true) { _vm.AddEngine(engine); } ChangeContext(); }
// GET: Engine/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Engine engine = _uow.EngineRepository.GetByID((int)id); if (engine == null) { return(HttpNotFound()); } EngineViewModel engineViewModel = new EngineViewModel(engine); return(View(engineViewModel)); }
public async Task ShouldCreate() { var service = new Mock <IEngineService>(); var controller = new EnginesController(service.Object); var viewModel = new EngineViewModel { Capacity = 2400, Configuration = "Inline 4 Vtec", FuelType = "Petrol" }; service.Setup(x => x.CreateNewEngine(viewModel)).Returns(Task.FromResult(true)); var result = await controller.Post(viewModel); Assert.IsType <NoContentResult>(result); }
public void EngineViewModelTest_MakeMoves() { FileUtilities.Lines.Add("5 5"); FileUtilities.Lines.Add("1 2 N"); FileUtilities.Lines.Add("LMLMLMLMM"); FileUtilities.Lines.Add("3 3 E"); FileUtilities.Lines.Add("MMRMMRMRRM"); var engine = new EngineViewModel(Container); engine.ParseData(new string[] { "file.txt" }); var lines = engine.MakeMoves(); Assert.AreEqual(2, lines.Length); Assert.AreEqual("1 3 N", lines[0]); Assert.AreEqual("5 1 E", lines[1]); engine.Dispose(); }
public override string ToString() { string boardString = string.Empty; // Print regularly if (EngineViewModel.GetInstance().WhiteToMove) { for (int Row = 0; Row < GameBoard.SquareCount; Row++) { for (int Column = 0; Column < GameBoard.SquareCount; Column++) { boardString += this.GetPieceText(Row, Column) + " "; } // New row if (Row != GameBoard.SquareCount - 1) { boardString += "\n"; } } } // Print board flipped else { for (int Row = GameBoard.SquareCount - 1; Row >= 0; Row--) { for (int Column = GameBoard.SquareCount - 1; Column >= 0; Column--) { boardString += this.GetPieceText(Row, Column); } // New row if (Row != 0) { boardString += "\n"; } } } return(boardString); }
public void EngineViewModelTest_ParseData() { FileUtilities.Lines.Add("5 5"); FileUtilities.Lines.Add("1 2 E"); FileUtilities.Lines.Add("LMLMLMLMM"); FileUtilities.Lines.Add("3 3 N"); FileUtilities.Lines.Add("MMRMMRMRRM"); var engine = new EngineViewModel(Container); // true Assert.IsTrue(engine.ParseData(new string[] { "file.txt" })); FileUtilities.Lines.Clear(); // false Assert.IsFalse(engine.ParseData(new string[] { "" })); Assert.IsFalse(engine.ParseData(new string[] { })); Assert.IsFalse(engine.ParseData(null)); engine.Dispose(); }
public void ShouldGet() { var service = new Mock <IEngineService>(); var controller = new EnginesController(service.Object); var payload = new EngineViewModel[] { new EngineViewModel { Capacity = 2400, Configuration = "Inline 4 Vtec", FuelType = "Petrol" } }; service.Setup(x => x.GetEngines()).Returns(payload); var result = controller.Get(); Assert.IsType <OkObjectResult>(result); Assert.Equal(((OkObjectResult)result).Value, payload); }
public async Task <bool> CreateNewEngine(EngineViewModel engineVm) { try { var engine = new Engine { Capacity = engineVm.Capacity, FuelType = engineVm.FuelType, Configuration = engineVm.Configuration }; await context.Engines.AddAsync(engine); await context.SaveChangesAsync(); return(true); } catch { // TODO: handle ex return(false); } }
private void CheckCastling() { // Out of position rooks: if (this.Pieces[0, 0].Name != GamePiece.PieceName.Rook) { EngineViewModel.GetInstance().BlackCanCastleQS = false; } if (this.Pieces[7, 0].Name != GamePiece.PieceName.Rook) { EngineViewModel.GetInstance().BlackCanCastleKS = false; } if (this.Pieces[0, 7].Name != GamePiece.PieceName.Rook) { EngineViewModel.GetInstance().WhiteCanCastleQS = false; } if (this.Pieces[7, 7].Name != GamePiece.PieceName.Rook) { EngineViewModel.GetInstance().WhiteCanCastleKS = false; } // Out of position black king: if (this.Pieces[4, 0].Name != GamePiece.PieceName.King) { EngineViewModel.GetInstance().BlackCanCastleKS = false; EngineViewModel.GetInstance().BlackCanCastleQS = false; } // Out of position white king: if (this.Pieces[4, 7].Name != GamePiece.PieceName.King) { EngineViewModel.GetInstance().WhiteCanCastleKS = false; EngineViewModel.GetInstance().WhiteCanCastleQS = false; } }
/// <summary> /// 保存引擎实例 /// </summary> /// <param name="model">引擎实例模型</param> /// <returns>是否保存成功</returns> public JsonResult SaveEngine(EngineViewModel model) { return(ExecuteFunctionRun(() => { ActionResult result = new ActionResult(false); OThinker.Clusterware.LogicUnitConfig config = new EngineConfig(); if (Code != string.Empty && false) { // ERROR, 更新状态 config = this.Connection.GetLogicUnitConfigByCode(Code); OThinker.Data.Database.DatabaseType dbType = (OThinker.Data.Database.DatabaseType) int.Parse(model.DBType); string connString = OThinker.Data.Database.Database.GetConnectionString(dbType, config.DBServer, config.DBName, model.DBUser.Trim(), model.DBPassword.Trim()); string logConnString = OThinker.Data.Database.Database.GetConnectionString(dbType, config.LogDBServer, config.LogDBName, model.LogDBName.Trim(), model.LogDBPassword.Trim()); CommandFactory factory = new CommandFactory(dbType, connString); CommandFactory Logfactory = new CommandFactory(dbType, logConnString); if (!factory.CheckConnection() || !Logfactory.CheckConnection()) { result.Success = false; result.Message = "数据库无法正常连接"; } else { config.DBUser = model.DBUser.Trim(); config.DBPassword = model.DBPassword.Trim(); config.LogDBUser = model.LogDBUser.Trim(); config.LogDBPassword = model.LogDBPassword.Trim(); config.UnitState = Clusterware.LogicUnitState.Running; this.Connection.UpdateLogicUnit(config); result.Success = true; } return Json(result, JsonRequestBehavior.AllowGet); } else { Regex reg = new Regex("[\\u4e00-\\u9fa5]"); if (reg.IsMatch(model.Code.Trim())) { result.Success = false; result.Message = "引擎编码不可包含中文!"; return Json(result, JsonRequestBehavior.AllowGet); } ; if (model.Code.Contains(" ")) { result.Success = false; result.Message = "引擎编码不可包含空格!"; return Json(result, JsonRequestBehavior.AllowGet); } ; if (string.IsNullOrEmpty(model.DBName) && DatabaseType.SqlServer == (OThinker.Data.Database.DatabaseType) int.Parse(model.DBType)) { result.Success = false; result.Message = "数据库名称不可为空!"; return Json(result, JsonRequestBehavior.AllowGet); } ; if (string.IsNullOrEmpty(model.LogDBName) && DatabaseType.SqlServer == (OThinker.Data.Database.DatabaseType) int.Parse(model.LogDBType)) { result.Success = false; result.Message = "日志数据库名称不可为空!"; return Json(result, JsonRequestBehavior.AllowGet); } ; config = new EngineConfig() { Code = model.Code.Trim(), DBType = (OThinker.Data.Database.DatabaseType) int.Parse(model.DBType), DBServer = model.DBServer.Trim(), DBName = string.IsNullOrEmpty(model.DBName) ? "" : model.DBName.Trim(), DBUser = model.DBUser.Trim(), DBPassword = model.DBPassword.Trim(), LogDBType = (OThinker.Data.Database.DatabaseType) int.Parse(model.LogDBType), LogDBServer = model.LogDBServer.Trim(), LogDBName = string.IsNullOrEmpty(model.LogDBName) ? "" : model.LogDBName.Trim(), LogDBUser = model.LogDBUser.Trim(), LogDBPassword = model.LogDBPassword.Trim(), UnitState = Clusterware.LogicUnitState.Running, InitialUserLoginName = "Administrator@" + Code }; if (!this.Connection.AddLogicUnit(config)) { this.Connection.RemoveLogicUnit(config.Code); result.Success = false; result.Message = "无法成功创建,信息不正确,或者没有足够可用的数据库"; } else { result.Success = true; } if (config.DBType == OThinker.Data.Database.DatabaseType.Oracle) { CommandFactory factory = new CommandFactory(DatabaseType.Oracle, config.DBConnString); if (!factory.CheckConnection()) { result.Success = false; result.Message = "数据库无法正常连接"; } } } return Json(result, JsonRequestBehavior.AllowGet); })); }
public static KeyValuePair<Engine, EngineViewModel> RecursiveCompilationCollectionTestMap() { var engineId = Guid.NewGuid(); var cylinderId = Guid.NewGuid(); var engine = new Engine { Id = engineId, Capacity = "3.5 V6", Cylinders = new List<Cylinder> { new Cylinder { Id = cylinderId, Engine = new Engine { Id = engineId, Capacity = "2.4", Cylinders = new List<Cylinder> {new Cylinder { Id = cylinderId, Capacity = 5.2M} } } }, new Cylinder { Id = cylinderId, Engine = new Engine {Id = engineId, Capacity = "2.4"} }, new Cylinder { Id = cylinderId, Engine = new Engine {Id = engineId, Capacity = "2.4"} }, new Cylinder { Id = cylinderId, Engine = new Engine {Id = engineId, Capacity = "2.4"} }, new Cylinder { Id = cylinderId, Engine = new Engine {Id = engineId, Capacity = "2.4"} } } }; var engineVm = new EngineViewModel { Id = engineId, Capacity = "3.5 V6", Cylinders = new List<CylinderViewModel> { new CylinderViewModel { Id = cylinderId, Engine = new EngineViewModel { Id = engineId, Capacity = "2.4", Cylinders = new List<CylinderViewModel> {new CylinderViewModel { Id = cylinderId, Capacity = 5.2M} } } }, new CylinderViewModel { Id = cylinderId, Engine = new EngineViewModel {Id = engineId, Capacity = "2.4"} }, new CylinderViewModel { Id = cylinderId, Engine = new EngineViewModel {Id = engineId, Capacity = "2.4"} }, new CylinderViewModel { Id = cylinderId, Engine = new EngineViewModel {Id = engineId, Capacity = "2.4"} }, new CylinderViewModel { Id = cylinderId, Engine = new EngineViewModel {Id = engineId, Capacity = "2.4"} } } }; return new KeyValuePair<Engine, EngineViewModel>(engine, engineVm); }
public void SetPlayingWhite(bool playingWhite) { EngineViewModel.GetInstance().PlayingWhite = playingWhite; }
/// <summary> /// Starts useful services that run in the background. /// </summary> private void StartBackgroundServices() { EngineViewModel.GetInstance().BeginAnalysis(); }
private string GetPieceText(int row, int column) { // Place peice (or lack thereof) switch (this.Pieces[column, row].Name) { case GamePiece.PieceName.None: if ((row % 2 == 1 && column % 2 == 0 || row % 2 == 0 && column % 2 == 1) && EngineViewModel.GetInstance().PlayingWhite || (row % 2 == 0 && column % 2 == 0 || row % 2 == 1 && column % 2 == 1) && !EngineViewModel.GetInstance().PlayingWhite) { return("⬜"); // ⬛ } else { return("⬜"); } case GamePiece.PieceName.Pawn: if ((this.Pieces[column, row].Color == GamePiece.PieceColor.Black && EngineViewModel.GetInstance().PlayingWhite) || (this.Pieces[column, row].Color == GamePiece.PieceColor.White && !EngineViewModel.GetInstance().PlayingWhite)) { return("♟"); } else { return("♙"); } case GamePiece.PieceName.Knight: if ((this.Pieces[column, row].Color == GamePiece.PieceColor.Black && EngineViewModel.GetInstance().PlayingWhite) || (this.Pieces[column, row].Color == GamePiece.PieceColor.White && !EngineViewModel.GetInstance().PlayingWhite)) { return("♞"); } else { return("♘"); } case GamePiece.PieceName.Bishop: if ((this.Pieces[column, row].Color == GamePiece.PieceColor.Black && EngineViewModel.GetInstance().PlayingWhite) || (this.Pieces[column, row].Color == GamePiece.PieceColor.White && !EngineViewModel.GetInstance().PlayingWhite)) { return("♝"); } else { return("♗"); } case GamePiece.PieceName.Rook: if ((this.Pieces[column, row].Color == GamePiece.PieceColor.Black && EngineViewModel.GetInstance().PlayingWhite) || (this.Pieces[column, row].Color == GamePiece.PieceColor.White && !EngineViewModel.GetInstance().PlayingWhite)) { return("♜"); } else { return("♖"); } case GamePiece.PieceName.Queen: if ((this.Pieces[column, row].Color == GamePiece.PieceColor.Black && EngineViewModel.GetInstance().PlayingWhite) || (this.Pieces[column, row].Color == GamePiece.PieceColor.White && !EngineViewModel.GetInstance().PlayingWhite)) { return("♛"); } else { return("♕"); } case GamePiece.PieceName.King: if ((this.Pieces[column, row].Color == GamePiece.PieceColor.Black && EngineViewModel.GetInstance().PlayingWhite) || (this.Pieces[column, row].Color == GamePiece.PieceColor.White && !EngineViewModel.GetInstance().PlayingWhite)) { return("♚"); } else { return("♔"); } default: throw new Exception("Unable to find text for provided piece"); } }
public async Task ShouldCreateAndFetchNewVehiclesWithWheelsAndEnginesAsync(VehicleViewModel vehicleVm) { using (var context = new MockContext(DbHelper.GetNewDbOptions <MockContext>())) { // Ensure DB was cleaned up context.ResetValueGenerators(); await context.Database.EnsureDeletedAsync(); var vehicleService = new VehicleService(context); var wheelService = new WheelService(context); var engineService = new EngineService(context); var engineVm = new EngineViewModel { Capacity = 4000, Configuration = "V8", FuelType = "Petrol" }; var wheelVm = new WheelViewModel { Size = 17, Width = 7 }; // Ensure DB emtpy var noVehicles = vehicleService.GetVehicles(); var noEngines = engineService.GetEngines(); var noWheels = wheelService.GetWheels(); Assert.Empty(noVehicles); Assert.Empty(noEngines); Assert.Empty(noWheels); // Add entities var isCreatedOk = await engineService.CreateNewEngine(engineVm); isCreatedOk = isCreatedOk && await wheelService.CreateNewWheel(wheelVm); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // TODO: This should fail in the second execution due to foreign key constraint. We are trying to add a vehicle // with an engine and wheel combination that does not yet exist. This fails during normal execution. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! isCreatedOk = isCreatedOk && await vehicleService.CreateNewVehicle(vehicleVm); // Ensure all created ok Assert.True(isCreatedOk); // Ensure vehicle added OK var oneEngine = engineService.GetEngines(); var oneWheel = wheelService.GetWheels(); var oneVehicles = vehicleService.GetVehicles(); Assert.Single(oneEngine); Assert.Single(oneWheel); Assert.Single(oneVehicles); // Verify many-to-many tables var oneVehicleEngine = context.VehicleEngines; var fourVehicleWheels = context.VehicleWheels; Assert.Single(oneVehicleEngine); Assert.Equal(4, fourVehicleWheels.Count()); } }