public void AuthorizeTest() { var app = App.FindByName("test"); if (app != null) { app.Delete(); } var service = new TokenService(); // 没有自动注册 var ex = Assert.Throws <ArgumentOutOfRangeException>(() => service.Authorize("test", "xxx", false)); Assert.NotNull(ex); // 启用 app = App.FindByName("test"); app.Enable = true; app.Update(); // 自动注册 var rs = service.Authorize("test", "xxx", true); Assert.NotNull(rs); Assert.NotNull(app); Assert.Equal(app.Id, rs.Id); // 再次验证 var rs2 = service.Authorize("test", "xxx", false); Assert.NotNull(rs2); Assert.Equal(app.Id, rs.Id); // 错误验证 Assert.Throws <InvalidOperationException>(() => service.Authorize("test", "yyy", true)); }