示例#1
0
        private void IdentifyDateTimeNowProblem(TimeNowTypes errorType)
        {
            var expected = new DiagnosticResult
            {
                Id        = "ClockNowAnalyser",
                Message   = "Use Clock.UtcNow instead of DateTime",
                Severity  = DiagnosticSeverity.Warning,
                Locations = new[] { new DiagnosticResultLocation("Test0.cs", 10, 27) }
            };

            VerifyCSharpDiagnostic(GetSourceCodeWithIssue(errorType), expected);
        }
示例#2
0
        private string GetSourceCodeWithIssue(TimeNowTypes timeNowTypes)
        {
            var    code  = @"
    using System;

    namespace ConsoleApplication1
    {{
        class TypeName
        {{
            public TypeName()
            {{
                var now = {0};
            }}
        }}
    }}";
            string issue = GetIssueValue(timeNowTypes);

            return(string.Format(code, issue));
        }
示例#3
0
        private string GetIssueValue(TimeNowTypes timeNowTypes)
        {
            switch (timeNowTypes)
            {
            case TimeNowTypes.DateTimeNow:
                return("DateTime.Now");

            case TimeNowTypes.DateTimeUtcNow:
                return("DateTime.UtcNow");

            case TimeNowTypes.DateTimeOffsetNow:
                return("DateTimeOffset.Now");

            case TimeNowTypes.DateTimeOffsetUtcNow:
                return("DateTimeOffset.UtcNow");

            default:
                throw new ArgumentOutOfRangeException(nameof(timeNowTypes), timeNowTypes, null);
            }
        }