//returns latest webLogEntry on the server private IWebCallLog GetLastWebLogEntry() { Startup.FlushLogs(); var utcNow = Startup.BooksApp.TimeService.UtcNow; var session = Startup.BooksApp.OpenSession(); var qWL = from wl in session.EntitySet <IWebCallLog>() where wl.CreatedOn <= utcNow // Diagnostics controller test messes up time, so we might have some entries posted in the future - filter them orderby wl.CreatedOn descending select wl; var result = qWL.FirstOrDefault(); return(result); }
public void TestLogViewerApi() { // Here we test Vita.Modules.Logging.Api.LoggingDataController functions var client = Startup.Client; // Make two calls, a good one, and one with server error; then try to retrieve the logs var vbBooks = client.ExecuteGet <SearchResults <Book> >("api/books?titlestart={0}", "vb"); Assert.IsTrue(vbBooks.Results.Count > 0, "Failed to find VB book"); var exc = TestUtil.ExpectFailWith <Exception>(() => client.ExecuteGet <string>("api/special/nullref")); Assert.IsNotNull(exc, "Expected exception"); //Flush all logs - they are usually flushed every second Startup.FlushLogs(); // Login as Kevin, he is site admin this.LoginAs("Kevin"); var errors = client.ExecuteGet <SearchResults <ErrorData> >("api/logs/errors?take=1"); //find last error Assert.IsTrue(errors.Results.Count > 0, "Expected at least 1 error"); var lastErr = errors.Results[0]; Assert.AreEqual("NullReferenceException", lastErr.ExceptionType, "Expected null-ref exc"); // we used 'search' call which brings list of errors without details; let's get data by ID - now with call stack Assert.IsTrue(string.IsNullOrWhiteSpace(lastErr.Details), "Expected no details"); var lastErrD = client.ExecuteGet <ErrorData>("api/logs/errors/{0}", lastErr.Id); Assert.IsNotNull(lastErrD, "Failed to get error details."); Assert.IsFalse(string.IsNullOrWhiteSpace(lastErrD.Details), "Expected details"); // Let's get WebCall data for this error var webCallData = client.ExecuteGet <WebCallLogData>("api/logs/webcalls/{0}", lastErr.WebCallId); Assert.IsNotNull(webCallData, "Failed to get web call data."); Assert.IsTrue(webCallData.Url.EndsWith("api/special/nullref"), "Expected null-ref URL"); Logout(); // login as Diego - he is not site admin, so he cannot access logs this.LoginAs("Diego"); var exc2 = TestUtil.ExpectFailWith <ApiException>(() => client.ExecuteGet <SearchResults <ErrorData> >("api/logs/errors?take=1")); //access denied Assert.IsNotNull(exc2, "Expected access denied exception"); Assert.AreEqual(HttpStatusCode.Forbidden, exc2.Status, "Expected Forbidden status"); Logout(); }
public void TestCleanup() { Startup.FlushLogs(); }