public void Organization_CreateApproveDelete() { string orgName = "TestOrg"; //var perms = new Mock<AuthIdentityService>(); //perms.Setup(f => f.HasPermission(PermissionType.SiteAdmin, null)).Returns(true); User admin; var perms = new Mock<AuthIdentityService>(); using (DataStoreService store = new DataStoreService("admin")) { admin = store.Users.Single(f => f.Username == "admin"); perms.Setup(f => f.User).Returns(admin); perms.Setup(f => f.UserLogin).Returns(admin.Username); var org = store.Organizations.SingleOrDefault(f => f.Name == orgName); using (var controller = new OrganizationsController(perms.Object, new DataStoreFactory())) { var mocks = new ContextMocks(controller); mocks.Request.Setup(r => r.AcceptTypes).Returns(new[] { "application/json" }); if (org != null) { var removeResult = controller.DoDeleteOrganization(org.Id); } } } using (var controller = new OrganizationsController(perms.Object, new DataStoreFactory())) { var mocks = new ContextMocks(controller); mocks.Request.Setup(r => r.AcceptTypes).Returns(new[] { "application/json" }); var action = controller.Create(); var view = (ViewResult)action; Assert.AreEqual(2, view.ViewData.Count, "ViewData should contain 2 items"); Assert.IsTrue(view.ViewData.ContainsKey(OrganizationsController.VIEWDATA_LIST_TIMEZONES), "ViewData should have timezone select list"); Assert.IsTrue(view.ViewData.ContainsKey(OrganizationsController.VIEWDATA_LIST_VISIBILITY), "ViewData should have visibility select list"); action = controller.Create(new NewOrganizationViewModel { Org = new Organization { Name = orgName, LongName = "Long Test Org Name", TimeZone = "Pacific Standard Time" }, Visibility = "Users" }); var redirect = (RedirectToRouteResult)action; Assert.AreEqual(2, redirect.RouteValues.Count); Assert.AreEqual(false, redirect.Permanent); Assert.AreEqual(string.Empty, redirect.RouteName); Guid newOrgId = Guid.Empty; using (var store = new DataStoreService(admin.Username)) { var newOrg = store.Organizations.SingleOrDefault(f => f.Name == orgName); Assert.IsNotNull(newOrg, "New organization was not created"); newOrgId = newOrg.Id; Assert.AreEqual(false, newOrg.IsApproved, "Org should start out as not approved"); } controller.SetOrganizationApproved(newOrgId, true); using (var store = new DataStoreService(admin.Username)) { var newOrg = store.Organizations.SingleOrDefault(f => f.Name == orgName); Assert.AreEqual(true, newOrg.IsApproved, "Org should now be approved"); } controller.DoDeleteOrganization(newOrgId); using (var store = new DataStoreService(admin.Username)) { var newOrg = store.Organizations.SingleOrDefault(f => f.Name == orgName); Assert.IsNull(newOrg, "New organization was not removed"); } } }