コード例 #1
0
        public void Can_Delete_Solution_RedirectToIndex()
        {
            UnitTestSolution solution = new UnitTestSolution() { Id = 1, Name = "ok" };
            MockDbRepository.Mock.Setup(x => x.GetUnitTestSolution(It.IsAny<int>())).Returns(solution);

            ViewResult result = unitTestController.Delete(1) as ViewResult;
            var model = (result as ViewResult).Model as SolutionViewModel;
            Assert.AreEqual(1, model.Id);
        }
コード例 #2
0
 public void Can_Edit_Solution_Redirect()
 {
     UnitTestSolution singleSolution = new UnitTestSolution() { Id = 1 };
     MockDbRepository.Mock.Setup(x => x.GetUnitTestSolution(It.IsAny<int>())).Returns(singleSolution);
     var result = unitTestController.Edit(1) as ViewResult;
     Assert.AreEqual("Solution", result.ViewName);
 }
コード例 #3
0
        private HttpResponseMessage CreateOrUpdate(SolutionViewModel model)
        {
            if (model == null) return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Solution can't be null");
            UnitTestSolution solution = new UnitTestSolution();
            if (ModelState.IsValid)
            {
                if (model?.Id > 0)
                {
                    solution = dbRepository.GetUnitTestSolution(model.Id);
                    if (solution == null) return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Solution doesn't exist");
                }

                Mapper.Map(model, solution);
                List<object> ret = new List<object>();
                IList<Error> errors = compilerService.Compile(solution, model.References);
                if (errors.Count > 0)
                {
                    foreach (Error e in errors)
                    {
                        ret.Add(new { Message = e.ToString(), Alert = e.IsWarning ? "warning" : "danger" });
                    }
                }
                dbRepository.SaveUnitTestSolution(solution, model.References);
                return Request.CreateResponse(HttpStatusCode.OK, new
                {
                    compileErrors = ret.ToArray(),
                    solution = Mapper.Map<SolutionViewModel>(solution)
                });
            }
            else
            {
                List<object> ret = new List<object>();
                foreach (var m in ModelState.Values)
                {
                    foreach (var e in m.Errors)
                    {
                        ret.Add(new { Message = e.ErrorMessage, Alert = "danger" });
                    }
                }
                return Request.CreateResponse(HttpStatusCode.BadRequest, ret.ToArray());
            }
        }