public void it_contains_the_stat_name() { var logs = new List <string>(); var contextMock = new Mock <ILambdaLogger>(MockBehavior.Strict); contextMock.Setup(logger => logger.LogLine(It.IsAny <string>())) .Callback((string s) => logs.Add(s)); var metrics = new DogMetrics(contextMock.Object); metrics.Counter("mystat", 1); Assert.True(logs.Count == 1); Assert.True(logs.First().Contains("|mystat|"), $@"Expected the given stat name: ""|mystat|"" but couldn't find it in <{logs.First()}>"); }
public void it_contains_the_current_unix_timestamp() { // Could this test fail when run on exactly the border of a second? var logs = new List <string>(); var contextMock = new Mock <ILambdaLogger>(MockBehavior.Strict); contextMock.Setup(logger => logger.LogLine(It.IsAny <string>())) .Callback((string s) => logs.Add(s)); var metrics = new DogMetrics(contextMock.Object); metrics.Counter("mystat", 1); var currentUnixTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); Assert.True(logs.Count == 1); Assert.True(logs.First().Contains($"|{currentUnixTime}|"), $@"Expected the current unix timestamp: ""|{currentUnixTime}|"" but couldn't find it in <{logs.First()}>"); }