public void FileAnswerCreate() { var problem = new ProblemUserModel { Content = "aaa", Name = "bbb" }; var problemLink = _problemService.Create(problem.ToModel()); var element = new AnswerUserModel { Content = "![](a.png) ![](b.png) ![](c.png)", Files = new[] { new FileDataView { FileName = "a.png", FileBytes = Convert.FromBase64String("aaaa") }, new FileDataView { FileName = "b.png", FileBytes = Convert.FromBase64String("bbbb") }, new FileDataView { FileName = "c.png", FileBytes = Convert.FromBase64String("cccc") } } }; var answerId = _problemService.CreateAnswer(problemLink.Id, element.ToModel()); var answer = _problemService.GetAnswer(problemLink.Id, answerId); Assert.Contains("aaaa", answer.Content); Assert.Contains("bbbb", answer.Content); Assert.Contains("cccc", answer.Content); }
// Add new view for uploading a photo and send the viewmodel for user and problem // There should be a button for that in details of problems or in the index file public ActionResult AddSolutionToProblem(Problem model) { if (User.Identity.IsAuthenticated && db.Challenges.Find(model.ChallengeFK).Participants.Contains(db.Users.Find(User.Identity.GetUserId()))) { ProblemUserModel problemUserModel = new ProblemUserModel() { Problem = model, ProblemFK = model.Id, User = db.Users.Find(User.Identity.GetUserId()), UserFK = User.Identity.GetUserId() }; return(View(problemUserModel)); } return(HttpNotFound()); }
public ActionResult AddSolutionToProblem(ProblemUserModel model) { if (model.Solution == null) { return(HttpNotFound()); } ProblemUserModel problemUserModel = db.Solutions.Find(model.ProblemFK, model.UserFK); Problem problem = db.Problems.Include(p => p.Solutions).Where(p => p.Id == model.ProblemFK).First(); if (problemUserModel != null) { problemUserModel.Solution = model.Solution; db.SaveChanges(); } else { problem.Solutions.Add(model); db.Solutions.Add(model); db.SaveChanges(); } return(RedirectToAction("Index", new { id = problem.ChallengeFK })); }
public void FileProblemCreate() { var element = new ProblemUserModel { Name = "abc", Content = "cde ![](abc.png) ![](cde.png) ![](efg.png)", Files = new[] { new FileDataView { FileName = "abc.png", FileBytes = Convert.FromBase64String("aaaa") }, new FileDataView { FileName = "cde.png", FileBytes = Convert.FromBase64String("bbbb") }, new FileDataView { FileName = "efg.png", FileBytes = Convert.FromBase64String("cccc") } } }; var problemLink = _problemService.Create(element.ToModel()); var problem = _problemService.Get(problemLink.Id); Assert.Equal(3, problem.Files.Count()); var b64List = problem.Files.Select(f => Convert.ToBase64String(f.FileBytes)).ToList(); Assert.Contains("aaaa", b64List); Assert.Contains("bbbb", b64List); Assert.Contains("cccc", b64List); element.Render(); Assert.Contains("aaaa", element.Content); Assert.Contains("bbbb", element.Content); Assert.Contains("cccc", element.Content); }
public void FileProblemEdit() { var fsNum1 = _fileDataService.GetFileSystemFilesCount(); var dbNum1 = _fileDataService.GetDataBaseFilesCount(); // Tworzymy nowy problem. var id = _problemService.Create(new Problem { Name = "xxx", Content = "![](a.png) ![](b.png) ![](c.png)", Files = new[] { new FileDataView { FileName = "a.png", FileBytes = Convert.FromBase64String("aaaa") }, new FileDataView { FileName = "b.png", FileBytes = Convert.FromBase64String("bbbb") }, new FileDataView { FileName = "c.png", FileBytes = Convert.FromBase64String("cccc") } } }).Id; var fsNum2 = _fileDataService.GetFileSystemFilesCount(); var dbNum2 = _fileDataService.GetDataBaseFilesCount(); Assert.Equal(fsNum1 + 3, fsNum2); Assert.Equal(dbNum1 + 3, dbNum2); // Wartości powinny być takie jak utworzone. var problem = _problemService.Get(id).ToView(); Assert.Equal(id, problem.Id); Assert.Equal("xxx", problem.Name); Assert.Contains("aaaa", problem.Content); Assert.Contains("bbbb", problem.Content); Assert.Contains("cccc", problem.Content); // Edytujemy wartości problemu. var problem2 = new ProblemUserModel { Name = "yyy", Content = "![](x.png) ![](y.png) ![](z.png)", Files = new[] { new FileDataView { FileName = "x.png", FileBytes = Convert.FromBase64String("xxxx") }, new FileDataView { FileName = "y.png", FileBytes = Convert.FromBase64String("yyyy") }, new FileDataView { FileName = "z.png", FileBytes = Convert.FromBase64String("zzzz") } } }; var res = _problemService.Edit(problem2.ToModel(), id); Assert.True(res); // Nowe wartości powinny być odpowiednie do wprowadzonych. var problem3 = _problemService.Get(id).ToView(); Assert.Equal(id, problem3.Id); Assert.Equal("yyy", problem3.Name); Assert.Contains("xxxx", problem3.Content); Assert.Contains("yyyy", problem3.Content); Assert.Contains("zzzz", problem3.Content); var fsNum3 = _fileDataService.GetFileSystemFilesCount(); var dbNum3 = _fileDataService.GetDataBaseFilesCount(); Assert.Equal(fsNum2, fsNum3); Assert.Equal(dbNum2, dbNum3); }