public ActionResult DeregisterOdsInstance(DeregisterOdsInstanceModel model) { _deregisterOdsInstanceCommand.Execute(model); Response.Cookies.Delete("Instance"); return(RedirectToActionJson <OdsInstancesController>(x => x.Index(), "Ods Instance deregistered successfully.")); }
public ActionResult DeregisterOdsInstance(DeregisterOdsInstanceModel model) { _deregisterOdsInstanceCommand.Execute(model); var instanceCookie = Request.Cookies.Get("Instance"); if (instanceCookie != null && instanceCookie.Value == model.OdsInstanceId.ToString()) { instanceCookie.Expires = DateTime.Now.AddDays(-1); instanceCookie.Value = null; Response.Cookies.Add(instanceCookie); } return(RedirectToActionJson <OdsInstancesController>(x => x.Index(), "Ods Instance deregistered successfully.")); }
public void ShouldDeregisterOdsInstance() { var users = SetupUsers(2).ToList(); var testUser1 = users[0]; var testUser2 = users[1]; var testInstances = SetupOdsInstanceRegistrations(2).OrderBy(x => x.Name).ToList(); var testInstanceToBeDeregistered = testInstances[0]; var testInstanceNotToBeDeregistered = testInstances[1]; MockInstanceRegistrationSetup(testInstances); using (var database = new SqlServerUsersContext()) { database.OdsInstances.Count().ShouldBe(2); database.Applications.Count().ShouldBe(2); database.Clients.Count().ShouldBe(2); database.ApplicationEducationOrganizations.Count().ShouldBe(2); database.ClientAccessTokens.Count().ShouldBe(2); } ShouldNotBeNull <SecretConfiguration>(x => x.OdsInstanceRegistrationId == testInstanceToBeDeregistered.Id); ShouldNotBeNull <SecretConfiguration>(x => x.OdsInstanceRegistrationId == testInstanceNotToBeDeregistered.Id); SetupUserWithOdsInstanceRegistrations(testUser1.Id, testInstances); SetupUserWithOdsInstanceRegistrations(testUser2.Id, testInstances); var queryInstances = new GetOdsInstanceRegistrationsByUserIdQuery(SetupContext); queryInstances.Execute(testUser1.Id).Count().ShouldBe(2); queryInstances.Execute(testUser2.Id).Count().ShouldBe(2); var deregisterModel = new DeregisterOdsInstanceModel { OdsInstanceId = testInstanceToBeDeregistered.Id, Name = testInstanceToBeDeregistered.Name, Description = testInstanceToBeDeregistered.Description }; using (var sqlServerUsersContext = new SqlServerUsersContext()) { var command = new DeregisterOdsInstanceCommand(SetupContext, sqlServerUsersContext); command.Execute(deregisterModel); } var deregisteredOdsInstance = SetupContext.OdsInstanceRegistrations.SingleOrDefault(x => x.Id == testInstanceToBeDeregistered.Id); deregisteredOdsInstance.ShouldBeNull(); var notDeregisteredOdsInstance = SetupContext.OdsInstanceRegistrations.SingleOrDefault(x => x.Id == testInstanceNotToBeDeregistered.Id); notDeregisteredOdsInstance.ShouldNotBeNull(); ShouldBeNull <SecretConfiguration>(x => x.OdsInstanceRegistrationId == testInstanceToBeDeregistered.Id); ShouldNotBeNull <SecretConfiguration>(x => x.OdsInstanceRegistrationId == testInstanceNotToBeDeregistered.Id); var instancesAssignedToUser1 = queryInstances.Execute(testUser1.Id).ToList(); instancesAssignedToUser1.Count.ShouldBe(1); var onlyInstanceAssignedToUser1 = instancesAssignedToUser1.Single(); onlyInstanceAssignedToUser1.Id.ShouldBe(testInstanceNotToBeDeregistered.Id); onlyInstanceAssignedToUser1.Name.ShouldBe(testInstanceNotToBeDeregistered.Name); onlyInstanceAssignedToUser1.Description.ShouldBe(testInstanceNotToBeDeregistered.Description); var instancesAssignedToUser2 = queryInstances.Execute(testUser2.Id).ToList(); instancesAssignedToUser2.Count.ShouldBe(1); var onlyInstanceAssignedToUser2 = instancesAssignedToUser2.Single(); onlyInstanceAssignedToUser2.Id.ShouldBe(testInstanceNotToBeDeregistered.Id); onlyInstanceAssignedToUser2.Name.ShouldBe(testInstanceNotToBeDeregistered.Name); onlyInstanceAssignedToUser2.Description.ShouldBe(testInstanceNotToBeDeregistered.Description); using (var database = new SqlServerUsersContext()) { database.OdsInstances.Count().ShouldBe(2); database.Applications.Count().ShouldBe(1); database.Clients.Count().ShouldBe(1); database.ApplicationEducationOrganizations.Count().ShouldBe(1); database.ClientAccessTokens.Count().ShouldBe(1); } }