public void CreateDeleteServicePrincipalTest() { using (UndoContext context = UndoContext.Current) { context.Start(); //Arrange var client = new GraphTestBase(); ServicePrincipal sp = null; //Test var passwordCredential = client.CreatePasswordCredential(); var application = client.CreateApplication(passwordCredential); try { sp = client.CreateServicePrincipal(application.AppId); client.DeleteServicePrincipal(sp.ObjectId); } finally { client.DeleteApplication(application.ObjectId); } //verify the user has been deleted. Assert.Throws(typeof(CloudException), () => { client.SearchServicePrincipal(sp.ObjectId); }); } }