private void AddToLogs(string type, string message, string source, DateTime time, string user, string url, ClientInformation clientInformation) { var errorLog = new ErrorLog { ErrorId = Guid.NewGuid(), Application = "/", Type = type, Message = message, Source = source, Time = time }; if (user.HasValue()) { errorLog.AddServerVariable(HttpServerVariables.LogonUser, user); } if (url.HasValue()) { errorLog.AddServerVariable(HttpServerVariables.Url, url); } errorLog.SetClientInformation(clientInformation); _logs.Add(errorLog); }
public void AddServerVariable_AddsVariable() { // arrange var error = new ErrorLog(); // act error.AddServerVariable("name", "value"); // assert Assert.That(error.ServerVariables.Count, Is.EqualTo(1)); var variable = error.ServerVariables[0]; Assert.That(variable.Name, Is.EqualTo("name")); Assert.That(variable.Value, Is.EqualTo("value")); }
public static ErrorLog CreateFakeErrorLog() { var errorLog = new ErrorLog(); errorLog.Time = new DateTime(2011, 6, 4, 11, 6, 0); errorLog.Type = "System.InvalidOperationException"; errorLog.Source = "System.Web.Mvc"; errorLog.SetStatusCodeInformation(new HttpStatusCodeInformation("500", "Internal error")); errorLog.AddServerVariable(HttpServerVariables.Url, "/some/url"); errorLog.Message = "The IControllerFactory 'Sodra.PP.Web.Helpers.UnityMapControllerFactory' did not return a controller for the name 'seh'."; errorLog.Details = @"System.InvalidOperationException: The IControllerFactory 'Sodra.PP.Web.Helpers.UnityMapControllerFactory' did not return a controller for the name 'seh'. at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)"; return errorLog; }
public void AddServerVariable_NameIsOnIgnoreList_ShouldNotAdd() { // arrange var error = new ErrorLog(); // act error.AddServerVariable("ALL_HTTP", "some values"); // assert Assert.That(error.ServerVariables.Count, Is.EqualTo(0)); }
public void AddServerVariable_NameIsRemoteAddress_SetAsClientIpAddress() { // arrange var error = new ErrorLog(); // act error.AddServerVariable(HttpServerVariables.RemoteAddress, "127.0.0.1"); // assert Assert.That(error.ClientIpAddress, Is.EqualTo("127.0.0.1")); }
public void AddServerVariable_NameIsHttpUserAgent_SetAsHttpUserAgent() { // arrange var error = new ErrorLog(); // act error.AddServerVariable(HttpServerVariables.HttpUserAgent, @"/some/kind/of/monster"); // assert Assert.That(error.HttpUserAgent, Is.EqualTo(@"/some/kind/of/monster")); }
public void AddServerVariable_NameIsURL_ValueIsEmpty_ShouldUseTheDefaultUrlValueForCleanUrl() { // arrange var error = new ErrorLog(); // act error.AddServerVariable(HttpServerVariables.Url, string.Empty); // assert Assert.That(error.CleanUrl, Is.EqualTo("UNKNOWN")); }
public void AddServerVariable_NameIsURL_SetAsUrlInLowerCase() { // arrange var error = new ErrorLog(); // act error.AddServerVariable(HttpServerVariables.Url, @"/Some/Kind/Of/Monster"); // assert Assert.That(error.Url, Is.EqualTo(@"/some/kind/of/monster")); }
public void AddServerVariable_NameIsLogon_User_ValueIsEmpty_ShouldUseTheDefaultUserValue() { // arrange var error = new ErrorLog(); // act error.AddServerVariable(HttpServerVariables.LogonUser, string.Empty); // assert Assert.That(error.User, Is.EqualTo("UNKNOWN")); }
public void AddServerVariable_NameIsLogon_User_SetAsUserInLowerCase() { // arrange var error = new ErrorLog(); // act error.AddServerVariable(HttpServerVariables.LogonUser, @"DOMAIN\user"); // assert Assert.That(error.User, Is.EqualTo(@"domain\user")); }