public async Task PostTestExample(Symbol sym) { var ex = new ExampleCreate() { Description = "This is a test example", Code = new ExampleCreate.CodeLine[] { new ExampleCreate.CodeLine() { Data = "void main()", Comment = "" }, new ExampleCreate.CodeLine() { Data = "{", Comment = "" }, new ExampleCreate.CodeLine() { Data = "}", Comment = "" } } }.CreateModel(); ex.Symbol = sym; ex.User = User.User; await Manager.PostAsync(ex); }
public ActionResult Create(ExampleCreate model) { var service = GetCodeExampleService(); if (service.CreateExample(model)) { return(RedirectToAction(nameof(Index))); } return(View(model)); }
public bool CreateExample(ExampleCreate model) { using (var context = new ApplicationDbContext()) { var entity = new CodeExample { CodeExampleId = model.CodeExampleId, CategoryId = model.CategoryId, ProfileId = _userId, Title = model.Title, ExampleCode = model.ExampleCode, ExampleDescription = model.ExampleDescription, InitialPost = DateTimeOffset.Now, EditedPost = null }; context.CodeExamples.Add(entity); return(context.SaveChanges() == 1); } }
public async Task Post_Error_Invalid() { var sym = await PostTestSymbol(new Symbols.SymbolController(new SymbolManager(Context, new Config() { MaxSymsPerPage = 15 }), User)); Assert.ThrowsAsync <Shared.Exceptions.InvalidResource>(() => PostTestExample(null)); Assert.ThrowsAsync <Shared.Exceptions.InvalidResource>(async() => { var ex = new ExampleCreate() { Description = "This is a test example", Code = new ExampleCreate.CodeLine[] { new ExampleCreate.CodeLine() { Data = "void main()", Comment = "" }, new ExampleCreate.CodeLine() { Data = "{", Comment = "" }, new ExampleCreate.CodeLine() { Data = "}", Comment = "" } } }.CreateModel(); ex.Symbol = sym; await Manager.PostAsync(ex); }); }