public decimal Substract(decimal value) { StaticLogger.Write($"Substracting {value} from {Value}."); Value -= value; return(Value); }
public decimal Add(decimal value) { StaticLogger.Write($"Adding {value} to {Value}."); Value += value; return(Value); }
public void IsLoginOK_WhenCalled_WritesToLog() { Isolate.Fake.StaticMethods(typeof(StaticLogger)); var lm = new LoginManagerWithStatics(); lm.IsLoginOK("a", "b"); Isolate.Verify .WasCalledWithAnyArguments(() => StaticLogger.Write("")); }
public void IsLoginOK_StaticLoggerThrowsException_CallsStaticWebService() { Isolate.Fake.StaticMethods <StaticLogger>(); Isolate.Fake.StaticMethods <StaticWebService>(); Isolate .WhenCalled(() => StaticLogger.Write("anything")) .WillThrow(new LoggerException("fake exception")); var lm = new LoginManagerWithStatics(); lm.IsLoginOK("a", "b"); Isolate.Verify.WasCalledWithAnyArguments(() => StaticWebService.Write("")); }
public bool IsLoginOK(string user, string password) { try { StaticLogger.Write("blah"); } catch (LoggerException e) { StaticWebService.Write(e.Message + Environment.MachineName); } if (m_users[user] != null && (string)m_users[user] == password) { return(true); } return(false); }
public bool IsLoginOK(string user, string password) { try { string text = "loginrequested"; StaticLogger.Write(text); // <--callLogger() } catch (LoggerException e) { string text = e.Message + Environment.MachineName; StaticWebService.Write(text); } if (m_users[user] != null && (string)m_users[user] == password) { return(true); } return(false); }
public void IsLoginOK_StaticLoggerThrowsException_CallsStaticWebServiceWithCorrectText() { string textWrittenToWebService = null; Isolate.Fake.StaticMethods <StaticLogger>(); Isolate.Fake.StaticMethods <StaticWebService>(); Isolate .WhenCalled(() => StaticLogger.Write("")) .WillThrow(new LoggerException("fake exception")); Isolate .WhenCalled(() => StaticWebService.Write("")) .DoInstead(context => textWrittenToWebService = (string)context.Parameters[0]); var lm = new LoginManagerWithStatics(); lm.IsLoginOK("a", "b"); StringAssert.Contains("fake exception", textWrittenToWebService); }
protected virtual void CallLogger(string text) { StaticLogger.Write(text); }
protected virtual void CallStaticWs() { StaticLogger.Write("blah"); }
protected static void LoggerWrite(string user) { StaticLogger.Write(user); }
/// <summary> /// Encapsulates the call to the StaticLogger in a protected virtual method. /// A testable class can now be made (in the UnitTest project) which inherits /// from this Calculator class and overrides the WriteToStaticLogger method /// to break the dependency with the logger. /// </summary> /// <param name="message">Message to log.</param> protected virtual void WriteToStaticLogger(string message) { StaticLogger.Write(message); }
protected virtual void LogStaticMessage(string user) { StaticLogger.Write(string.Format("user {0} logged in ok", user)); }
public v void WriteLogger(string user) { StaticLogger.Write(user); }