public ForceManagementViewModel(ProblemViewModel problemViewModel) { _problemViewModel = problemViewModel; _problemViewModel.Forces.CollectionChanged += ProblemChanged; _problemViewModel.Nodes.CollectionChanged += ProblemChanged; }
public void AddToCollection(ProblemViewModel item, Guid parentId, Guid institutionId) { if (item == null) { throw new InvalidModelException(); } using (var db = Context) { var dbParent = db.Tests.FirstOrDefault(x => x.DocumentId == parentId && x.InstitutionId == institutionId); if (dbParent == null) { throw new ArgumentException("Unable to find a matching test to assign the problem to"); } Problem dbItem = new Problem() { Number = item.Number, Body = item.Content }; dbParent.Problems.Add(dbItem); db.SaveChanges(); item.Id = dbItem.ProblemId; } }
public void SelectedNode_SetNode_ExpectPropertyChangedEventRaised() { //Arrange var problemViewModel = new ProblemViewModel(); var nodeViewModel = problemViewModel.AddNode(); problemViewModel.SelectedNode = null; var checker = new PropertyChangedEventChecker(problemViewModel); //Act problemViewModel.SelectedNode = nodeViewModel; //Assert Assert.That(checker.PropertiesRaised, Is.EqualTo(new [] { "SelectedNode", "SelectedElement", "SelectedForce", "SelectedMaterial", "AvailableNodesForSelectedForces", "AvailableOriginNodesForSelectedElements", "AvailableDestinationNodesForSelectedElements" })); }
public IHttpActionResult Delete(string id) { try { ProblemViewModel vm = new ProblemViewModel(); vm.ProblemId = id; vm.GetById(); long retVal = vm.Delete(); switch (retVal) { case 1: return(Ok("Problem deleted!")); case 0: return(Ok("Problem not deleted!")); default: return(Ok("Problem not deleted!")); } } catch (Exception ex) { return(BadRequest("Retrieve failed - " + ex.Message)); } }
public MainViewModel() { CameraViewModel = new CameraViewModel(); ProblemViewModel = new ProblemViewModel(); InterfaceControlViewModel = new InterfaceControlViewModel(ProblemViewModel, CameraViewModel); ConfigurationViewModel = ApplicationConfiguration.Configuration; }
public IHttpActionResult Delete(string id) { try { ProblemViewModel prob = new ProblemViewModel(); prob.Id = id; long delRetVal = prob.Delete(); switch (delRetVal) { case 1: return(Ok("Ok! Problem " + prob.Description + " has been Deleted!")); case 0: return(Ok("Error! Problem does not Exist!")); default: return(Ok("Problem " + prob.Description + " not deleted!")); } } catch (Exception ex) { return(BadRequest("Delete Failed - Contact Tech Support")); } }
public ProblemViewModel GetProblem(string problema, string username, string contestId, DateTime inicio, DateTime fin) { var client = new RestClient("http://juez.oia.unsam.edu.ar/api/task"); var request = new RestRequest(Method.POST); request.AddHeader("postman-token", "be07341a-d5e3-7184-0d50-cccc1b802cc5"); request.AddHeader("cache-control", "no-cache"); request.AddHeader("content-type", "application/json;charset=UTF-8"); request.AddParameter("application/json;charset=UTF-8", "{\"name\":\"" + problema + "\",\"action\":\"get\"}\r\n", ParameterType.RequestBody); IRestResponse response = client.Execute(request); JObject respuesta = new JObject(); try { respuesta = JObject.Parse(response.Content); while (respuesta.Count == 0 || respuesta.GetValue("success") == null) { System.Threading.Thread.Sleep(1000); response = client.Execute(request); respuesta = JObject.Parse(response.Content); } } catch (Exception e) { throw new NotImplementedException(e.ToString()); } if (respuesta.GetValue("success").ToString() == "0") { return(null); } ProblemViewModel pvm = new ProblemViewModel(); int problemId = Int32.Parse(respuesta.GetValue("id").ToString()); pvm.Nombre = respuesta.GetValue("title").ToString(); pvm.LimiteMemoria = respuesta.GetValue("memory_limit").ToString(); pvm.LimiteTiempo = respuesta.GetValue("time_limit").ToString(); pvm.Envios = firebase.GetSubmissions(contestId, username, problema);//db.Submissions.Where(x => x.ContestId == contestId).Where(x => x.Username == username).Where(x => x.ProblemName == problema).Where(x => inicio <= x.Fecha && x.Fecha <= fin).ToList(); pvm.Archivos = new List <Tuple <string, string> >(); JObject enunciado = JObject.Parse(respuesta.GetValue("statements").ToString()); pvm.Archivos.Add(Tuple.Create(problema + ".pdf", enunciado.GetValue("es").ToString())); if (respuesta.GetValue("attachments") != null) { var attachments = respuesta.GetValue("attachments").Children(); foreach (var item in attachments) { var nombreArchivo = item[0].ToString(); var tokenArchivo = item[1].ToString(); pvm.Archivos.Add(Tuple.Create(nombreArchivo, tokenArchivo)); } } return(pvm); }
public async Task <IActionResult> AddTask(int?subjectId) { try { if (User.Identity.IsAuthenticated) { var user = await _userManager.GetUserAsync(User); ViewBag.Name = user.Name; ProblemViewModel model = new ProblemViewModel { Subjects = _subjectService.GetSubjectsNames().ToList() }; if (subjectId != null) { var subject = _subjectService.GetSubject(subjectId); model.Subject = subject.Name; } return(View("AddTask", model)); } return(RedirectToAction("Login", "Account")); } catch (Exception exc) { return(base.RedirectToAction("Error", "Home", new ErrorViewModel { Message = exc.Message })); } }
public void ProblemVMGetAllShouldReturnList() { ProblemViewModel vm = new ProblemViewModel(); List <ProblemViewModel> probs = vm.GetAll(); Assert.IsTrue(probs.Count > 0); }
public void TestUpdateShouldReturnStale() { if (!did_create_run) { TestCreateShouldReturnNewId(); } ProblemViewModel vm1 = new ProblemViewModel(); ProblemViewModel vm2 = new ProblemViewModel(); vm1.ProblemId = vm2.ProblemId = id_string; vm1.GetById(); vm2.GetById(); vm1.Description = "11"; vm2.Description = "22"; int ver = vm1.Version; Assert.IsTrue(vm1.Update() == (int)UpdateStatus.Ok); Assert.IsTrue(vm2.Update() == (int)UpdateStatus.Stale); vm1.GetById(); // get the update version of the emp Assert.IsTrue(vm1.Description == "11"); Assert.IsTrue(vm1.Version == ver + 1); // change it back vm1.GetById(); vm1.Description = descrip; Assert.IsTrue(vm1.Update() == (int)UpdateStatus.Ok); }// TestUpdateShouldReturnStale
public void TestUpdateShouldReturnOk() { if (!did_create_run) { TestCreateShouldReturnNewId(); } ProblemViewModel vm = new ProblemViewModel(); vm.ProblemId = id_string; vm.GetById(); vm.Description = "1"; int ver = vm.Version; Assert.IsTrue(vm.Update() == (int)UpdateStatus.Ok); vm.GetById(); // get updated version Assert.IsTrue(vm.Version == ver + 1); Assert.IsTrue(vm.Description == "1"); // change it back vm.Description = descrip; Assert.IsTrue(vm.Update() == (int)UpdateStatus.Ok); vm.GetById(); Assert.IsTrue(vm.Version == ver + 2); Assert.IsTrue(vm.Description == descrip); }// TestUpdateShouldReturnOk
public async Task <IActionResult> PutProblem(Guid id, [FromBody] ProblemViewModel problem) { if (id != problem.Id) { return(BadRequest()); } try { Problem newProblem = _mapper.Map <Problem>(problem); foreach (var item in problem.ProblemTypes) { newProblem.ProblemTypeProblems.Add(new ProblemTypeProblem() { Problem = newProblem, ProblemTypeId = item.Id }); } await _problemService.Change(newProblem); newProblem = _problemService.GetProblem(newProblem.Id); ProblemViewModel loadedProblem = _mapper.Map <ProblemViewModel>(newProblem); loadedProblem.ProblemTypes = problem.ProblemTypes; loadedProblem.SubscribersCount = newProblem.Subscribers.Count; return(CreatedAtAction("GetProblem", new { id = newProblem.Id }, loadedProblem)); } catch (DbUpdateConcurrencyException) { if (!_problemService.Exist(id)) { return(NotFound()); } else { throw; } } }
public IHttpActionResult Put(ProblemViewModel prob) { try { int retVal = prob.Update(); switch (retVal) { case 1: return(Ok("Ok! Problem " + prob.Description + " updated!")); case -1: return(Ok("Problem" + prob.Description + " not updated!")); case -2: return(Ok("Data is Stale for " + prob.Description + ", Problem not updated")); default: return(Ok("Department " + prob.Description + " not updated!")); } } catch (Exception ex) { return(BadRequest("Update Failed - Contact Tech Support")); } }
public IHttpActionResult Put(ProblemViewModel prob) { try { int retVal = prob.Update(); switch (retVal) { case 1: return(Ok("Problem " + prob.Description + " updated!")); case -1: return(Ok("Problem " + prob.Description + " not updated!")); case -2: return(Ok("Data is stale for " + prob.Description + ", Problem not updated!")); default: return(Ok("Problem " + prob.Description + " not updated!")); } } catch (Exception ex) { return(BadRequest("Retrieve failed - " + ex.Message)); } }
internal static bool CanProblemBeSolved(ProblemViewModel problemViewModel) { //To solve the problem, the 3 displacements must be constrained //In this kind of problem it means 3 non-collinear fixed nodes return(problemViewModel.Nodes.Any(x => x.IsXFixed) && problemViewModel.Nodes.Any(x => x.IsYFixed) && problemViewModel.Nodes.Any(x => x.IsZFixed)); }
public void ComprehensiveVMTests() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; cvm.DateClosed = null; cvm.OpenStatus = true; evm.Lastname = "Jarocki"; evm.GetByLastname(); cvm.EmployeeId = evm.Id; evm.Lastname = "Burner"; evm.GetByLastname(); cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Kevin has bad RAM, Burner to fix it"; cvm.Add(); Console.WriteLine("New Call Generated - Id = " + cvm.Id); int id = cvm.Id; //need id for delete later cvm.GetById(); cvm.Notes += "\n Ordered new RAM!"; if (cvm.Update() == 1) { Console.WriteLine("Call was updated " + cvm.Notes); } else { Console.WriteLine("Call was not updated!"); } cvm.Notes = "Another change to comments that should not work"; if (cvm.Update() == -2) { Console.WriteLine("Call was not updated data was stale"); } cvm = new CallViewModel(); cvm.Id = id; cvm.GetById(); if (cvm.Delete() == 1) { Console.WriteLine("Call was deleted!"); } else { Console.WriteLine("Call was not deleted"); } cvm.GetById(); }
public void Call_ComprehensiveVMTest() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; //cvm.DateClosed = null; cvm.OpenStatus = true; evm.Email = "*****@*****.**"; evm.GetByEmail(); cvm.EmployeeId = evm.Id; //evm.Lastname = "Park"; evm.Email = "*****@*****.**"; evm.GetByEmail(); cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Jimin has bad RAM, Burner to fix it"; cvm.Add(); output.WriteLine("New Call Generated - Id = " + cvm.Id); int id = cvm.Id; cvm.GetById(); cvm.Notes += "\n Ordered new RAM!!"; if (cvm.Update() == 1) { output.WriteLine("Call was updated " + cvm.Notes); } else { output.WriteLine("Call was not updated!"); } //cvm.Notes = "Another change to comments that should not works"; //if (cvm.Update() == -2) { // output.WriteLine("Call was not updated data was stale"); //} //cvm = new CallViewModel(); //cvm.Id = id; //cvm.GetById(); //if (cvm.Delete() == 1) //{ // output.WriteLine("Call was deleted!"); //} //else { // output.WriteLine("Call was not deleted!"); //} //Exception ex = Assert.Throws<NullReferenceException>(() => cvm.GetById()); //Assert.Equal("Object reference not set to an instance of an object.", ex.Message); }
public ActionResult CriarProblem(ProblemViewModel model) { string[] values = Request.Form.GetValues("Chamados"); model.NumChamado1 = Convert.ToInt32(values[0]); model.NumChamado2 = Convert.ToInt32(values[1]); model.FuncionarioId = Convert.ToInt32(Session["UserId"]); _problemService.CriarProblem(model); return(RedirectToAction("ListarProblems", "Assistencia")); }
public async System.Threading.Tasks.Task <string> AddBugCreate(ProblemViewModel pbvm) { ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); try { if (string.IsNullOrEmpty(pbvm.image_1) && pbvm.image1 != null) { string filename = ""; filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff"); Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync(); _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]); var imageUrl = await _imageUploader.UploadImage(pbvm.image1, filename, "Problem"); pbvm.image_1 = imageUrl; } if (string.IsNullOrEmpty(pbvm.image_2) && pbvm.image2 != null) { string filename = ""; filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff"); Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync(); _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]); var imageUrl = await _imageUploader.UploadImage(pbvm.image2, filename, "Problem"); pbvm.image_2 = imageUrl; } if (string.IsNullOrEmpty(pbvm.image_3) && pbvm.image3 != null) { string filename = ""; filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff"); Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync(); _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]); var imageUrl = await _imageUploader.UploadImage(pbvm.image3, filename, "Problem"); pbvm.image_3 = imageUrl; } pbvm.valid = 1; pbvm.inpdate = DateTime.Now; new UserRepository().addbug(pbvm); // TODO: Add insert logic here return("1"); } catch { return(""); } return(""); }
public void ComprehensiveVMTests() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; cvm.DateClosed = null; cvm.OpenStatus = true; evm.Lastname = "Pollock"; evm.GetByLastname(); cvm.EmployeeId = evm.Id; evm.Lastname = "Burner"; evm.GetByLastname(); cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Chris has bad RAM, Burner to fix it"; cvm.Add(); Console.WriteLine("New Call Generated - Id = " + cvm.Id); int id = cvm.Id; // need Id for delete later cvm.GetById(); cvm.Notes += "\n Ordered new RAM!"; if (cvm.Update() == 1) { Console.WriteLine("Call was updated " + cvm.Notes); } else { Console.WriteLine("Call was NOT updated!"); } cvm.Notes = "Another change to comments that should not work."; if (cvm.Update() == -2) { Console.WriteLine("Call was NOT updated, data was stale."); } cvm = new CallViewModel(); // need to reset because of Concurrency cvm.Id = id; cvm.GetById(); if (cvm.Delete() == 1) { Console.WriteLine("Call was deleted!"); } else { Console.WriteLine("Call was NOT deleted!"); } cvm.GetById(); // should throw expected exception }
public ActionResult CriarProblem() { var itemsChamados = _chamadoService.ListarChamados(); var vm = new ProblemViewModel() { Chamados = itemsChamados.ToList(), }; return(View(vm)); }
public void Call_ComprehensiveVMTest() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; cvm.DateClosed = null; cvm.OpenStatus = true; evm.Email = "*****@*****.**"; evm.GetByEmail(); cvm.EmployeeId = evm.Id; evm.Lastname = "*****@*****.**"; evm.GetByEmail(); cvm.EmployeeName = evm.Lastname; cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Sonia has bad RAM, Burner to fix it"; cvm.Add(); output.WriteLine("New Call Generated - Id = " + cvm.Id); int id = cvm.Id; cvm.GetById(); cvm.Notes += "\n Ordered new RAM!"; if (cvm.Update() == 1) { output.WriteLine("Call was updated " + cvm.Notes); } else { output.WriteLine("Call was not updated!"); } cvm.Notes = "Another change to comments that should not work"; if (cvm.Update() == -2) { output.WriteLine("Call was not updated data was stale"); } cvm = new CallViewModel();// need to reset because of concureency error cvm.Id = id; cvm.GetById(); if (cvm.Delete() == 1) { output.WriteLine("Call was deleted"); } else { output.WriteLine("Call was not deleted"); } Exception ex = Assert.Throws <NullReferenceException>(() => cvm.GetById()); // should throw expected exception Assert.Equal("Object reference not set to an instance of an object.", ex.Message); }
public void AddMaterial_EmptyProblem_ExpectNewMaterialIsSelectedMaterial() { //Arrange var problemViewModel = new ProblemViewModel(); //Act var materialViewModel = problemViewModel.AddMaterial(); //Assert Assert.That(problemViewModel.SelectedMaterial, Is.EqualTo(materialViewModel)); }
public void AddMaterial_EmptyProblem_ExpectNewMaterialIsSelected() { //Arrange var problemViewModel = new ProblemViewModel(); //Act var materialViewModel = problemViewModel.AddMaterial(); //Assert Assert.That(materialViewModel.IsSelected, Is.True); }
public void AddNode_EmptyProblem_ExpectNewNodeIsSelectedNode() { //Arrange var problemViewModel = new ProblemViewModel(); //Act var nodeViewModel = problemViewModel.AddNode(); //Assert Assert.That(problemViewModel.SelectedNode, Is.EqualTo(nodeViewModel)); }
public void AddNode_EmptyProblem_ExpectNewNodeIsSelected() { //Arrange var problemViewModel = new ProblemViewModel(); //Act var nodeViewModel = problemViewModel.AddNode(); //Assert Assert.That(nodeViewModel.IsSelected, Is.True); }
private static ProblemViewModel dbItemToViewModel(Problem dbItem) { var vmItem = new ProblemViewModel() { Id = dbItem.ProblemId, Number = dbItem.Number, Content = dbItem.Body }; return(vmItem); }
public MainWindowViewModel() { var problem = new Problem(); foreach (var item in GetSampleInputData()) { problem.Inputs.Add(item); } Problem = new ProblemViewModel(problem); }
public void DeleteSelectedMaterial_NullSelectedMaterial_ExpectNothingHappened() { //Arrange var problemViewModel = new ProblemViewModel(); var materialViewModel = problemViewModel.AddMaterial(); problemViewModel.SelectedMaterial = null; //Act //Assert Assert.DoesNotThrow(() => problemViewModel.DeleteSelectedMaterial()); }
public void DeleteSelectedNode_NullSelectedNode_ExpectNothingHappened() { //Arrange var problemViewModel = new ProblemViewModel(); var nodeViewModel = problemViewModel.AddNode(); problemViewModel.SelectedNode = null; //Act //Assert Assert.DoesNotThrow(() => problemViewModel.DeleteSelectedNode()); }
public ProblemDetailsViewModel(ProblemViewModel problemViewModel) { ProblemViewModel = problemViewModel; }