public void SetUp() { var bins = new List <Bin> { new Bin { Trash = new List <Trash>(), Id = 1, Description = "Description", Name = "Bin1", ApplicationUserId = "1" }, new Bin { Trash = new List <Trash>(), Id = 2, Description = "Description", Name = "Bin2", ApplicationUserId = "1" }, new Bin { Trash = new List <Trash>(), Id = 3, Description = "Description", Name = "Bin3", ApplicationUserId = "1" } }; var repositoryMock = new Mock <IRepository>(); repositoryMock.Setup(x => x.Bins).Returns(bins.AsQueryable()); repositoryMock.Setup(x => x.Add(It.IsAny <Bin>())).Callback((object bin) => bins.Add(bin as Bin)); repositoryMock.Setup(x => x.Remove(It.IsAny <Bin>())).Callback((object bin) => bins.Remove(bin as Bin)); repositoryMock.Setup(x => x.Edit(It.IsAny <Bin>())).Callback((object bin) => bins[bins.IndexOf(bins.First(x => x.Id == (bin as Bin).Id))] = bin as Bin); this.repository = repositoryMock.Object; var identityMock = new Mock <IControllerIdentity>(); identityMock.Setup(x => x.Name).Returns("Name"); identityMock.Setup(x => x.AuthenticationType).Returns("Type"); identityMock.Setup(x => x.IsAuthenticated).Returns(true); identityMock.Setup(x => x.GetUserId()).Returns("1"); identityMock.Setup(x => x.GetUserName()).Returns("Name"); this.identity = identityMock.Object; this.controller = new BinsController(this.repository, this.identity); }
// GET: Trashes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Trash trash = this.db.Trash.FirstOrDefault(x => x.Id == id.Value); if (trash == null) { return(this.HttpNotFound()); } if (this.reloadUserIdentity) { this.identity = new ControllerIdentity(this.User.Identity); } string userId = this.identity.GetUserId(); this.ViewBag.BinId = new SelectList( this.db.Bins.Where(x => x.ApplicationUserId == userId), "Id", "Name", trash.BinId); return(this.View("Edit", trash)); }
public void SetUp() { this.repository = new FakeRepository(); this.identity = new FakeIdentity(); var comment = new Comment { Content = "content" }; var trash = new Trash { Id = 1, Title = "Title", AddTime = DateTime.Now, Content = "content", Comments = new List <Comment>() { comment } }; var trash2 = new Trash { Id = 2, Title = "Title", AddTime = DateTime.Now, Content = "content", Comments = new List <Comment>() { comment } }; var trash3 = new Trash { Id = 3, Title = "Title", AddTime = DateTime.Now, Content = "content", Comments = new List <Comment>() { comment } }; this.repository.Add(trash); this.repository.Add(trash2); this.repository.Add(trash3); this.controller = new TrashesController(this.repository, this.identity); }
public ActionResult DeleteConfirmed(int id) { if (this.reloadUserIdentity) { this.identity = new ControllerIdentity(this.User.Identity); } var bin = this.db.Bins.FirstOrDefault(x => x.Id == id); this.db.Remove(bin); return(this.RedirectToAction("Details", "Account", new { userName = this.identity.GetUserName() })); }
public ActionResult Create([Bind(Include = "Id,Name,Description")] Bin bin) { if (this.ModelState.IsValid) { if (this.reloadUserIdentity) { this.identity = new ControllerIdentity(this.User.Identity); } bin.ApplicationUserId = this.identity.GetUserId(); this.db.Add(bin); return(this.RedirectToAction("Details", "Account", new { userName = this.identity.GetUserName() })); } return(this.View("Create", bin)); }
// GET: Trashes/Create public ActionResult Create() { if (this.reloadUserIdentity) { this.identity = new ControllerIdentity(this.User.Identity); } string id = this.identity.GetUserId(); var user = this.db.Users.Include(x => x.Bins).FirstOrDefault(x => x.Id == id); if (user?.Bins != null && user.Bins.Count == 0) { return(this.RedirectToAction("Create", "Bins")); } this.ViewBag.BinId = new SelectList(this.db.Bins.Where(x => x.ApplicationUserId == id), "Id", "Name"); return(this.View("Create")); }
public void SetUp() { var comment = new Comment { Content = "content" }; var trashes = new List <Trash> { new Trash { Id = 1, Title = "Title", AddTime = DateTime.Now, Content = "content", Comments = new List <Comment>() { comment } }, new Trash { Id = 2, Title = "Title", AddTime = DateTime.Now, Content = "content", Comments = new List <Comment>() { comment } }, new Trash { Id = 3, Title = "Title", AddTime = DateTime.Now, Content = "content", Comments = new List <Comment>() { comment } } }; var repositoryMock = new Mock <IRepository>(); repositoryMock.Setup(x => x.Trash).Returns(trashes.AsQueryable()); repositoryMock.Setup(x => x.Add(It.IsAny <Trash>())).Callback((object trash) => trashes.Add(trash as Trash)); repositoryMock.Setup(x => x.Remove(It.IsAny <Trash>())).Callback((object trash) => trashes.Remove(trash as Trash)); repositoryMock.Setup(x => x.Edit(It.IsAny <Trash>())).Callback((object trash) => trashes[trashes.IndexOf(trashes.First(x => x.Id == (trash as Trash).Id))] = trash as Trash); this.repository = repositoryMock.Object; var identityMock = new Mock <IControllerIdentity>(); identityMock.Setup(x => x.Name).Returns("Name"); identityMock.Setup(x => x.AuthenticationType).Returns("Type"); identityMock.Setup(x => x.IsAuthenticated).Returns(true); identityMock.Setup(x => x.GetUserId()).Returns("1"); identityMock.Setup(x => x.GetUserName()).Returns("Name"); this.identity = identityMock.Object; this.controller = new TrashesController(this.repository, this.identity); }
public void SetUp() { this.repository = new FakeRepository(); this.identity = new FakeIdentity(); var bin = new Bin { Trash = new List <Trash>(), Id = 1, Description = "Description", Name = "Bin1", ApplicationUserId = "1" }; var bin2 = new Bin { Trash = new List <Trash>(), Id = 2, Description = "Description", Name = "Bin2", ApplicationUserId = "1" }; var bin3 = new Bin { Trash = new List <Trash>(), Id = 3, Description = "Description", Name = "Bin3", ApplicationUserId = "1" }; this.repository.Add(bin); this.repository.Add(bin2); this.repository.Add(bin3); this.controller = new BinsController(this.repository, this.identity); }
public ActionResult Create([Bind(Include = "Id,Title,Content,AddTime,BinId")] Trash trash) { if (this.ModelState.IsValid) { trash.AddTime = DateTime.Now; this.db.Add(trash); return(this.RedirectToAction("Details", "Bins", new { id = trash.BinId })); } if (this.reloadUserIdentity) { this.identity = new ControllerIdentity(this.User.Identity); } string id = this.identity.GetUserId(); this.ViewBag.BinId = new SelectList( this.db.Bins.Where(x => x.ApplicationUserId == id), "Id", "Name", trash.BinId); return(this.View("Create", trash)); }
public ActionResult Details(string commentContent, int trashId) { if (this.reloadUserIdentity) { this.identity = new ControllerIdentity(this.User.Identity); } var trash = this.db.Trash.Include(x => x.Comments).First(x => x.Id == trashId); if (string.IsNullOrEmpty(commentContent)) { return(this.View(trash)); } var comment = new Comment { ApplicationUserId = this.identity.GetUserId(), TrashId = trashId, Content = commentContent }; trash.Comments.Add(comment); this.db.Edit(trash); return(this.View(trash)); }
public BinsController(IRepository repository, IControllerIdentity identity) { this.db = repository; this.identity = identity; this.reloadUserIdentity = false; }
public TrashesController(IRepository context, IControllerIdentity identity) { this.db = context; this.identity = identity; this.reloadUserIdentity = false; }