public void Test_MakePost1ArgInValid() { Controller.ModelState.AddModelError("key", "Error."); WebSecurity.Setup(w => w.CurrentUserId()).Returns(0); Post APost = new Post { UserID = 988 }; Location ALocation = new Location { LocationID = 988 }; PostLocationModel APlm = new PostLocationModel(); APlm.Tpost = APost; APlm.Tlocation = ALocation; var result = Controller._MakePost(APlm) as PartialViewResult; Assert.IsNotNull(result); Assert.IsNotNull(result.ViewBag.GroupList); foreach (Group g in result.ViewBag.TestingGroupList) { if (g.IsPrivate == true) { //If a private group make sure they are an owner. Assert.IsTrue(db.user0.Groups.Contains(g)); } //Private group not an owner of. Assert.IsFalse(g.GroupID == 3); } Assert.AreEqual("_MakePost", result.ViewName); }
public ActionResult _MakePost(PostLocationModel plm) { User u = ur.GetUser(); if (ModelState.IsValid) { plm.Tpost.UserID = u.UserId; //Location loc = new Location(); // loc.LocationName = plm.Tlocation.LocationName; // loc.Longitude = plm.Tlocation.Longitude; // loc.Latitude = plm.Tlocation.Latitude; db.Locations.Add(plm.Tlocation); db.SaveChanges(); int newPK = plm.Tlocation.LocationID; plm.Tpost.LocationID = newPK; plm.Tpost.CreationDate = System.DateTime.Now; db.Posts.Add(plm.Tpost); db.SaveChanges(); var glist = gr.NotPrivateOrOwner(u); ViewBag.TestingGroupList = glist; ViewBag.GroupList = new SelectList(glist, "GroupID", "GroupName"); //Close the post window, remove the circle selector, and add the new post // to the map. string closepostjs = "$('#postcontainer').hide(); removeRadiusSelctor();" + "updateMarkers();"; return(JavaScript(closepostjs)); } // take groups which are not private unioned with private groups to which the user is an owner var glist1 = gr.NotPrivateOrOwner(u); ViewBag.TestingGroupList = glist1; ViewBag.GroupList = new SelectList(glist1, "GroupID", "GroupName"); return(PartialView("_MakePost")); }
public void Test_MakePost1ArgValid() { WebSecurity.Setup(w => w.CurrentUserId()).Returns(0); Post APost = new Post { UserID = 988 }; Location ALocation = new Location { LocationID = 988 }; PostLocationModel APlm = new PostLocationModel(); APlm.Tpost = APost; APlm.Tlocation = ALocation; var result = Controller._MakePost(APlm) as JavaScriptResult; Assert.IsNotNull(result); Assert.IsTrue(SocialContext.Posts.Contains(APost)); Assert.IsTrue(SocialContext.Locations.Contains(ALocation)); Assert.AreEqual(result.Script, "$('#postcontainer').hide(); removeRadiusSelctor();" + "updateMarkers();"); }