public AuthControllerTests() { var mockAuthService = new Mock <IAuthService>(); var mockAuthServiceGetAuthDataHandle = new Mock <AuthData>(); var mockLogger = new Mock <ILoggerService>(); mockAuthService .Setup(o => o.HashPassword(It.IsAny <string>())) .Returns("AQAAAAEAACcQAAAAENt3qvnso/FOo/LM46ZXTSvnBKcVDAaWlO+YHGcyGnwGz2+wCVAoAZUASC5ZhD6ISw=="); mockAuthService .Setup(o => o.VerifyPassword(It.IsAny <string>(), It.IsAny <string>())) .Returns(true); mockAuthService .Setup(o => o.GetAuthData(It.IsAny <string>())) .Returns(mockAuthServiceGetAuthDataHandle.Object); DbContextOptions <TodoListDbContext> options = new DbContextOptionsBuilder <TodoListDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new TodoListDbContext(options); _userRepository = new UserRepository(mockAuthService.Object, db); _authController = new AuthController(mockAuthService.Object, _userRepository, mockLogger.Object); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, TodoListDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } context.Database.Migrate(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public ActionResult Index() { using (var db = new TodoListDbContext()) { return(View(db.Tasks.ToList())); } }
public async Task ReturnTrueIfValidItemIsPassedToMarkDoneAsync() { var options = new DbContextOptionsBuilder <TodoListDbContext>() .UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options; // Set up a context (connection to the "DB") for writing using (var context = new TodoListDbContext(options)) { var service = new TodoItemService(context); var fakeUser = new IdentityUser { Id = "fake-000", UserName = "******" }; await service.AddItemAsync(new TodoItem { Title = "Testing?" }, fakeUser); var items = await service.GetIncompleteItemsAsync(fakeUser); Assert.True(await service.MarkDoneAsync(items[0].Id, fakeUser)); } }
public async Task ReturnOnlyItemsOwnedByAParticularUser() { var options = new DbContextOptionsBuilder <TodoListDbContext>() .UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options; // Set up a context (connection to the "DB") for writing using (var context = new TodoListDbContext(options)) { var service = new TodoItemService(context); var fakeUser = new IdentityUser { Id = "fake-000", UserName = "******" }; await service.AddItemAsync(new TodoItem { Title = "Testing?" }, fakeUser); var items = await service.GetIncompleteItemsAsync(fakeUser); Assert.Equal("Testing?", items[0].Title); } }
public ActionResult Index() { TodoListDbContext db = new TodoListDbContext(); List <Task> tasks = db.Tasks.ToList(); return(View(tasks)); }
public ActionResult Index() { using (var db = new TodoListDbContext()) { var films = db.Tasks.ToList(); return(View(films)); } }
public ActionResult Index() { using (var database = new TodoListDbContext()) { var tasks = database.Tasks.ToList(); return(View(tasks)); } }
public ActionResult Index() { using (var db = new TodoListDbContext()) { List <Task> tasks = db.Tasks.ToList(); return(View(tasks)); } }
public ActionResult Delete(int id) { using (var db = new TodoListDbContext()) { Task task = db.Tasks.Find(id); return(View(task)); } }
public ActionResult Create(Task task) { using (var db = new TodoListDbContext()) { db.Tasks.Add(task); db.SaveChanges(); } return(RedirectToAction("Index", "Task")); }
public ActionResult DeleteConfirm(int id) { using (var db = new TodoListDbContext()) { Task task = db.Tasks.Find(id); db.Tasks.Remove(task); db.SaveChanges(); } return(RedirectToAction("Index", "Task")); }
public ActionResult DeleteConfirm(int id) { using (var db = new TodoListDbContext()) { var task = db.Tasks.First(t => t.Id == id); db.Tasks.Remove(task); db.SaveChanges(); return(RedirectToAction("Index")); } }
public AuthServiceTests() { _authService = new AuthService("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjYyM2VhMjM5LTljODItNDQ1YS1hOTAzLTA1YjdlNmVjZTlhNSIsIm5iZiI6MTU4MTYyMjk5NywiZXhwIjoxNTg0MjE0OTk3LCJpYXQiOjE1ODE2MjI5OTd9.Ik0-1dCwFBYyU4Gi8_PAfzJMgFsorCZs6keXOtVMKeY", 1584214997); DbContextOptions <TodoListDbContext> options = new DbContextOptionsBuilder <TodoListDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; _db = new TodoListDbContext(options); AddUserToDataBase(); }
public ActionResult Create(Task task) { if (ModelState.IsValid) { using (var database = new TodoListDbContext()) { database.Tasks.Add(task); database.SaveChanges(); } } return(RedirectToAction("Index")); }
public ActionResult Edit(int?id) { using (var db = new TodoListDbContext()) { var task = db.Tasks.Find(id); if (task != null) { return(View(task)); } } return(Redirect("/")); }
public ActionResult Delete(int id) { using (var db = new TodoListDbContext()) { var task = db.Tasks.Find(id); if (task == null) { return(RedirectToAction("Index")); } return(View(task)); } }
public ActionResult Create(Task task) { if (string.IsNullOrWhiteSpace(task.Title) || string.IsNullOrWhiteSpace(task.Comments)) { return(RedirectToAction("Index")); } using (var db = new TodoListDbContext()) { db.Tasks.Add(task); db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult DeleteConfirm(int id) { using (var db = new TodoListDbContext()) { var task = db.Tasks.Find(id); if (task != null) { db.Tasks.Remove(task); db.SaveChanges(); } return(Redirect("/")); } }
public ActionResult EditConfirm([Bind(Include = "Id,Title,Comments")] Task task) { using (var db = new TodoListDbContext()) { if (ModelState.IsValid) { db.Entry(task).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); } }
public ActionResult Create(Task task) { if (ModelState.IsValid) { using (var db = new TodoListDbContext()) { db.Tasks.Add(task); db.SaveChanges(); return(Redirect("/")); } } return(View()); }
public ActionResult Create(Task task) { if (task == null || task.Title == null || task.Comments == null) { return(RedirectToAction("Index")); } using (var db = new TodoListDbContext()) { db.Tasks.Add(task); db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Delete(int id) { using (var db = new TodoListDbContext()) { try { var task = db.Tasks.First(t => t.Id == id); return(View(task)); } catch (InvalidOperationException) { return(RedirectToAction("Index")); } } }
public ActionResult DeleteConfirm(int id) { TodoListDbContext db = new TodoListDbContext(); Task task = db.Tasks.Find(id); if (task == null) { return(RedirectToAction("Index")); } db.Tasks.Remove(task); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Delete(int id) { using (var db = new TodoListDbContext()) { var task = db.Tasks .Where(t => t.Id == id) .First(); if (task == null) { return(HttpNotFound()); } return(View(task)); } }
public ActionResult Create(Task task) { if (task == null) { return(RedirectToAction("Index", "Task")); } if (ModelState.IsValid) { using (var db = new TodoListDbContext()) { db.Tasks.Add(task); db.SaveChanges(); } return(RedirectToAction("index", "Task")); } return(RedirectToAction("Create", "Task")); }
public ActionResult DeleteConfirm(int?id) { using (var db = new TodoListDbContext()) { var taskFromDb = db.Tasks.Find(id); if (taskFromDb == null) { return(HttpNotFound()); } db.Tasks.Remove(taskFromDb); db.SaveChanges(); return(Redirect("/")); } }
public ActionResult Delete(int id) { if (id == null) { return(HttpNotFound()); } using (var database = new TodoListDbContext()) { Task task = database.Tasks.Find(id); if (task == null) { return(RedirectToAction("Index")); } return(View(task)); } }
public ActionResult Create(Task task) { if (task == null) { return(RedirectToAction("Index")); } if (string.IsNullOrWhiteSpace(task.Title) || string.IsNullOrWhiteSpace(task.Comments)) { ViewBag.message = "Попълни полетата!"; return(View(task)); } using (var db = new TodoListDbContext()) { db.Tasks.Add(task); db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var database = new TodoListDbContext()) { var task = database.Tasks.Where(t => t.Id == id).First(); if (task == null) { return(HttpNotFound()); } return(View(task)); } }