Example #1
0
        public void Digi001CodeFix()
        {
            var testCode  = @"
namespace RoslynSandBox
{
    using DigiBotExtensions;
    [IrcConnection("""")]
    public class ↓MuhConnection
    {
    }
}";
            var fixedCode = @"
namespace RoslynSandBox
{
    using DigiBotExtensions;
    [IrcConnection("""")]
    public class MuhConnection : IIrcConnection
    {
    }
}";

            AnalyzerAssert.AddTransitiveMetadataReferences(typeof(DigiBotExtension.IIrcConnection).Assembly);
            AnalyzerAssert.AddTransitiveMetadataReferences(typeof(Avalonia.Controls.Control).Assembly);
            AnalyzerAssert.AddTransitiveMetadataReferences(typeof(DIGI001IrcConnectShouldImplementIIrcConnection).Assembly);
            AnalyzerAssert.CodeFix(Analyzer, CodeFix, testCode, fixedCode, allowCompilationErrors: AllowCompilationErrors.No);
            AnalyzerAssert.ResetMetadataReferences();
        }
Example #2
0
        public void ResetMetadataReferences()
        {
            CollectionAssert.IsNotEmpty(AnalyzerAssert.MetadataReferences);

            AnalyzerAssert.MetadataReferences.Clear();
            CollectionAssert.IsEmpty(AnalyzerAssert.MetadataReferences);

            AnalyzerAssert.ResetMetadataReferences();
            CollectionAssert.IsNotEmpty(AnalyzerAssert.MetadataReferences);
        }
Example #3
0
        public void Digi001NotFound()
        {
            var testCode = @"
namespace RosylnSandbox
{
    class MuhClass {}
}";

            AnalyzerAssert.AddTransitiveMetadataReferences(typeof(DIGI001IrcConnectShouldImplementIIrcConnection).Assembly);
            AnalyzerAssert.Valid(Analyzer, testCode);
            AnalyzerAssert.ResetMetadataReferences();
        }
Example #4
0
        public void ResetMetadataReferences()
        {
            var expected = new[]
            {
                MetadataReference.CreateFromFile(typeof(object).Assembly.Location)
                .WithAliases(ImmutableArray.Create("global", "mscorlib")),
                MetadataReference.CreateFromFile(typeof(System.Diagnostics.Debug).Assembly.Location)
                .WithAliases(ImmutableArray.Create("global", "System")),
                MetadataReference.CreateFromFile(typeof(System.Linq.Enumerable).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(System.Net.WebClient).Assembly.Location),
            };

            CollectionAssert.AreEqual(expected, AnalyzerAssert.MetadataReferences, MetadataReferenceComparer.Default);

            AnalyzerAssert.MetadataReferences.Clear();
            AnalyzerAssert.ResetMetadataReferences();
            CollectionAssert.AreEqual(expected, AnalyzerAssert.MetadataReferences, MetadataReferenceComparer.Default);
        }
Example #5
0
        public void Digi001Valid()
        {
            var testCode = @"
namespace RosylnSandbox
{
    using System;
    using System.Collections.Generic;
    using System.Collections.Concurrent;
    using System.IO;
    using System.Linq;
    using System.Net.Sockets;
    using System.Threading.Tasks;
    using System.Threading;
    using DigiBotExtension;
    using Avalonia.Controls;
    [IrcConnection("""")]
    public class ValidClass : IIrcConnection
    {
        public int RetryLimit { get; set; }
        public Action<StreamWriter,IEnumerable<string>> Pong { get; set; }
        public Action<StreamWriter> Logon { get; set; }
        public Avalonia.Controls.Control ConfigBox { get; }
        public event MessageReceived OnMessageReceived;
        public event ConnectedEvent OnConnected;
        public event DisconnectEvent OnDisconnect;
        public string Channel { get; set; }
        public bool Connected { get; }
    
        public Task Start(){ return Task.CompletedTask; }
        public Task Stop(){ return Task.CompletedTask; }
        public void WriteLine(object o){}
        public void WriteLine(string format, params object[] o){}

        public void Dispose(){}
    }
}";

            AnalyzerAssert.AddTransitiveMetadataReferences(typeof(DigiBotExtension.IIrcConnection).Assembly);
            AnalyzerAssert.AddTransitiveMetadataReferences(typeof(Avalonia.Controls.Control).Assembly);
            AnalyzerAssert.AddTransitiveMetadataReferences(typeof(DIGI001IrcConnectShouldImplementIIrcConnection).Assembly);
            AnalyzerAssert.Valid(Analyzer, testCode);
            AnalyzerAssert.ResetMetadataReferences();
        }
Example #6
0
        public void Digi001Found()
        {
            var testCode = @"
namespace RoslynSandBox
{
    using DigiBotExtension;
    [IrcConnection("""")]
    public class ↓MuhConnection
    {
    }
}";

            AnalyzerAssert.AddTransitiveMetadataReferences(typeof(DigiBotExtension.IIrcConnection).Assembly);
            AnalyzerAssert.AddTransitiveMetadataReferences(typeof(Avalonia.Controls.Control).Assembly);
            AnalyzerAssert.AddTransitiveMetadataReferences(typeof(DIGI001IrcConnectShouldImplementIIrcConnection).Assembly);
            var expectedMessage = ExpectedDiagnostic.CreateFromCodeWithErrorsIndicated(
                "DIGI001",
                "The class MuhConnection should impliment: IIrcConnection to use IrcConnectionAttribute.",
                testCode,
                out testCode);

            AnalyzerAssert.Diagnostics <DIGI001IrcConnectShouldImplementIIrcConnection>(expectedMessage, testCode);
            AnalyzerAssert.ResetMetadataReferences();
        }
 public void TearDown()
 {
     AnalyzerAssert.ResetMetadataReferences();
 }
Example #8
0
 public void ResetMetadataReferences()
 {
     AnalyzerAssert.MetadataReferences.Add(MetadataReference.CreateFromFile(typeof(int).Assembly.Location));
     AnalyzerAssert.ResetMetadataReferences();
     CollectionAssert.IsEmpty(AnalyzerAssert.MetadataReferences);
 }