public async Task SerializationTest_Document()
        {
            using (var workspace = new TestWorkspace(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, workspaceKind: "DiagnosticDataSerializerTest"))
            {
                var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", "");

                var diagnostics = new[]
                {
                    new DiagnosticData(
                        "test1", "Test", "test1 message", "test1 message format",
                        DiagnosticSeverity.Info, DiagnosticSeverity.Info, false, 1,
                        ImmutableArray<string>.Empty, ImmutableDictionary<string, string>.Empty,
                        workspace, document.Project.Id, new DiagnosticDataLocation(document.Id,
                            new TextSpan(10, 20), "originalFile1", 30, 30, 40, 40, "mappedFile1", 10, 10, 20, 20)),
                    new DiagnosticData(
                        "test2", "Test", "test2 message", "test2 message format",
                        DiagnosticSeverity.Warning, DiagnosticSeverity.Warning, true, 0,
                        ImmutableArray.Create<string>("Test2"), ImmutableDictionary<string, string>.Empty.Add("propertyKey", "propertyValue"),
                        workspace, document.Project.Id, new DiagnosticDataLocation(document.Id,
                            new TextSpan(30, 40), "originalFile2", 70, 70, 80, 80, "mappedFile2", 50, 50, 60, 60), title: "test2 title", description: "test2 description", helpLink: "http://test2link"),
                    new DiagnosticData(
                        "test3", "Test", "test3 message", "test3 message format",
                        DiagnosticSeverity.Error, DiagnosticSeverity.Warning, true, 2,
                        ImmutableArray.Create<string>("Test3", "Test3_2"), ImmutableDictionary<string, string>.Empty.Add("p1Key", "p1Value").Add("p2Key", "p2Value"),
                        workspace, document.Project.Id, new DiagnosticDataLocation(document.Id,
                            new TextSpan(50, 60), "originalFile3", 110, 110, 120, 120, "mappedFile3", 90, 90, 100, 100), title: "test3 title", description: "test3 description", helpLink: "http://test3link"),
                }.ToImmutableArray();

                var utcTime = DateTime.UtcNow;
                var analyzerVersion = VersionStamp.Create(utcTime);
                var version = VersionStamp.Create(utcTime.AddDays(1));

                var key = "document";
                var serializer = new CodeAnalysis.Workspaces.Diagnostics.DiagnosticDataSerializer(analyzerVersion, version);

                Assert.True(await serializer.SerializeAsync(document, key, diagnostics, CancellationToken.None).ConfigureAwait(false));
                var recovered = await serializer.DeserializeAsync(document, key, CancellationToken.None);

                AssertDiagnostics(diagnostics, recovered.Value);
            }
        }
示例#2
0
        public async Task SerializationTest_Document()
        {
            using (var workspace = new TestWorkspace(EditorServicesUtil.ExportProvider, workspaceKind: "DiagnosticDataSerializerTest"))
            {
                var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", "");

                var diagnostics = new[]
                {
                    new DiagnosticData(
                        "test1", "Test", "test1 message", "test1 message format",
                        DiagnosticSeverity.Info, DiagnosticSeverity.Info, false, 1,
                        ImmutableArray <string> .Empty, ImmutableDictionary <string, string> .Empty,
                        workspace, document.Project.Id, new DiagnosticDataLocation(document.Id,
                                                                                   new TextSpan(10, 20), "originalFile1", 30, 30, 40, 40, "mappedFile1", 10, 10, 20, 20)),
                    new DiagnosticData(
                        "test2", "Test", "test2 message", "test2 message format",
                        DiagnosticSeverity.Warning, DiagnosticSeverity.Warning, true, 0,
                        ImmutableArray.Create <string>("Test2"), ImmutableDictionary <string, string> .Empty.Add("propertyKey", "propertyValue"),
                        workspace, document.Project.Id, new DiagnosticDataLocation(document.Id,
                                                                                   new TextSpan(30, 40), "originalFile2", 70, 70, 80, 80, "mappedFile2", 50, 50, 60, 60), title: "test2 title", description: "test2 description", helpLink: "http://test2link"),
                    new DiagnosticData(
                        "test3", "Test", "test3 message", "test3 message format",
                        DiagnosticSeverity.Error, DiagnosticSeverity.Warning, true, 2,
                        ImmutableArray.Create <string>("Test3", "Test3_2"), ImmutableDictionary <string, string> .Empty.Add("p1Key", "p1Value").Add("p2Key", "p2Value"),
                        workspace, document.Project.Id, new DiagnosticDataLocation(document.Id,
                                                                                   new TextSpan(50, 60), "originalFile3", 110, 110, 120, 120, "mappedFile3", 90, 90, 100, 100), title: "test3 title", description: "test3 description", helpLink: "http://test3link"),
                }.ToImmutableArray();

                var utcTime         = DateTime.UtcNow;
                var analyzerVersion = VersionStamp.Create(utcTime);
                var version         = VersionStamp.Create(utcTime.AddDays(1));

                var key        = "document";
                var serializer = new CodeAnalysis.Workspaces.Diagnostics.DiagnosticDataSerializer(analyzerVersion, version);

                Assert.True(await serializer.SerializeAsync(document, key, diagnostics, CancellationToken.None).ConfigureAwait(false));
                var recovered = await serializer.DeserializeAsync(document, key, CancellationToken.None);

                AssertDiagnostics(diagnostics, recovered.Value);
            }
        }
示例#3
0
        public async Task SerializationTest_Project()
        {
            using (var workspace = new TestWorkspace(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, workspaceKind: "DiagnosticDataSerializerTest"))
            {
                var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", "");

                var diagnostics = new[]
                {
                    new DiagnosticData(
                        "test1", "Test", "test1 message", "test1 message format",
                        DiagnosticSeverity.Info, DiagnosticSeverity.Info, false, 1,
                        ImmutableArray <string> .Empty, ImmutableDictionary <string, string> .Empty,
                        workspace, document.Project.Id, description: "test1 description", helpLink: "http://test1link"),
                    new DiagnosticData(
                        "test2", "Test", "test2 message", "test2 message format",
                        DiagnosticSeverity.Warning, DiagnosticSeverity.Warning, true, 0,
                        ImmutableArray.Create <string>("Test2"), ImmutableDictionary <string, string> .Empty.Add("p1Key", "p2Value"),
                        workspace, document.Project.Id),
                    new DiagnosticData(
                        "test3", "Test", "test3 message", "test3 message format",
                        DiagnosticSeverity.Error, DiagnosticSeverity.Warning, true, 2,
                        ImmutableArray.Create <string>("Test3", "Test3_2"), ImmutableDictionary <string, string> .Empty.Add("p2Key", "p2Value").Add("p1Key", "p1Value"),
                        workspace, document.Project.Id, description: "test3 description", helpLink: "http://test3link"),
                }.ToImmutableArray();

                var utcTime         = DateTime.UtcNow;
                var analyzerVersion = VersionStamp.Create(utcTime);
                var version         = VersionStamp.Create(utcTime.AddDays(1));

                var key        = "project";
                var serializer = new CodeAnalysis.Workspaces.Diagnostics.DiagnosticDataSerializer(analyzerVersion, version);

                Assert.True(await serializer.SerializeAsync(document, key, diagnostics, CancellationToken.None).ConfigureAwait(false));
                var recovered = await serializer.DeserializeAsync(document, key, CancellationToken.None);

                AssertDiagnostics(diagnostics, recovered.Value);
            }
        }
示例#4
0
        public async Task SerializationTest_Document()
        {
            using var workspace = new TestWorkspace(EditorServicesUtil.ExportProvider, workspaceKind: "DiagnosticDataSerializerTest");
            var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", "");

            var diagnostics = new[]
            {
                new DiagnosticData(
                    id: "test1",
                    category: "Test",
                    message: "test1 message",
                    enuMessageForBingSearch: "test1 message format",
                    severity: DiagnosticSeverity.Info,
                    defaultSeverity: DiagnosticSeverity.Info,
                    isEnabledByDefault: false,
                    warningLevel: 1,
                    customTags: ImmutableArray <string> .Empty,
                    properties: ImmutableDictionary <string, string> .Empty,
                    document.Project.Id,
                    new DiagnosticDataLocation(document.Id, new TextSpan(10, 20), "originalFile1", 30, 30, 40, 40, "mappedFile1", 10, 10, 20, 20),
                    language: LanguageNames.CSharp),

                new DiagnosticData(
                    id: "test2",
                    category: "Test",
                    message: "test2 message",
                    enuMessageForBingSearch: "test2 message format",
                    severity: DiagnosticSeverity.Warning,
                    defaultSeverity: DiagnosticSeverity.Warning,
                    isEnabledByDefault: true,
                    warningLevel: 0,
                    customTags: ImmutableArray.Create("Test2"),
                    properties: ImmutableDictionary <string, string> .Empty.Add("propertyKey", "propertyValue"),
                    document.Project.Id,
                    new DiagnosticDataLocation(document.Id, new TextSpan(30, 40), "originalFile2", 70, 70, 80, 80, "mappedFile2", 50, 50, 60, 60),
                    language: "VB",
                    title: "test2 title",
                    description: "test2 description",
                    helpLink: "http://test2link"),

                new DiagnosticData(
                    id: "test3",
                    category: "Test",
                    message: "test3 message",
                    enuMessageForBingSearch: "test3 message format",
                    severity: DiagnosticSeverity.Error,
                    defaultSeverity: DiagnosticSeverity.Warning,
                    isEnabledByDefault: true,
                    warningLevel: 2,
                    customTags: ImmutableArray.Create("Test3", "Test3_2"),
                    properties: ImmutableDictionary <string, string> .Empty.Add("p1Key", "p1Value").Add("p2Key", "p2Value"),
                    document.Project.Id,
                    new DiagnosticDataLocation(document.Id, new TextSpan(50, 60), "originalFile3", 110, 110, 120, 120, "mappedFile3", 90, 90, 100, 100),
                    title: "test3 title",
                    description: "test3 description",
                    helpLink: "http://test3link"),
            }.ToImmutableArray();

            var utcTime         = DateTime.UtcNow;
            var analyzerVersion = VersionStamp.Create(utcTime);
            var version         = VersionStamp.Create(utcTime.AddDays(1));

            var key = "document";

            var persistentService = workspace.Services.GetRequiredService <IPersistentStorageService>();
            var serializer        = new CodeAnalysis.Workspaces.Diagnostics.DiagnosticDataSerializer(analyzerVersion, version);

            Assert.True(await serializer.SerializeAsync(persistentService, document.Project, document, key, diagnostics, CancellationToken.None).ConfigureAwait(false));

            var recovered = await serializer.DeserializeAsync(persistentService, document.Project, document, key, CancellationToken.None);

            AssertDiagnostics(diagnostics, recovered);
        }
        public async Task SerializationTest_Project()
        {
            using (var workspace = new TestWorkspace(EditorServicesUtil.ExportProvider, workspaceKind: "DiagnosticDataSerializerTest"))
            {
                var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", "");

                var diagnostics = new[]
                {
                    new DiagnosticData(
                        "test1", "Test", "test1 message", "test1 message format",
                        DiagnosticSeverity.Info, DiagnosticSeverity.Info, false, 1,
                        ImmutableArray<string>.Empty, ImmutableDictionary<string, string>.Empty,
                        workspace, document.Project.Id, description: "test1 description", helpLink: "http://test1link"),
                    new DiagnosticData(
                        "test2", "Test", "test2 message", "test2 message format",
                        DiagnosticSeverity.Warning, DiagnosticSeverity.Warning, true, 0,
                        ImmutableArray.Create<string>("Test2"), ImmutableDictionary<string, string>.Empty.Add("p1Key", "p2Value"),
                        workspace, document.Project.Id),
                    new DiagnosticData(
                        "test3", "Test", "test3 message", "test3 message format",
                        DiagnosticSeverity.Error, DiagnosticSeverity.Warning, true, 2,
                        ImmutableArray.Create<string>("Test3", "Test3_2"), ImmutableDictionary<string, string>.Empty.Add("p2Key", "p2Value").Add("p1Key", "p1Value"),
                        workspace, document.Project.Id, description: "test3 description", helpLink: "http://test3link"),
                }.ToImmutableArray();

                var utcTime = DateTime.UtcNow;
                var analyzerVersion = VersionStamp.Create(utcTime);
                var version = VersionStamp.Create(utcTime.AddDays(1));

                var key = "project";
                var serializer = new CodeAnalysis.Workspaces.Diagnostics.DiagnosticDataSerializer(analyzerVersion, version);

                Assert.True(await serializer.SerializeAsync(document, key, diagnostics, CancellationToken.None).ConfigureAwait(false));
                var recovered = await serializer.DeserializeAsync(document, key, CancellationToken.None);

                AssertDiagnostics(diagnostics, recovered.Value);
            }
        }
        public async Task SerializationTest_Project()
        {
            using var workspace = new TestWorkspace(composition: EditorTestCompositions.EditorFeatures.AddParts(
                                                        typeof(TestPersistentStorageServiceFactory)));

            var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", "");

            var diagnostics = new[]
            {
                new DiagnosticData(
                    id: "test1",
                    category: "Test",
                    message: "test1 message",
                    enuMessageForBingSearch: "test1 message format",
                    severity: DiagnosticSeverity.Info,
                    defaultSeverity: DiagnosticSeverity.Info,
                    isEnabledByDefault: false,
                    warningLevel: 1,
                    customTags: ImmutableArray <string> .Empty,
                    properties: ImmutableDictionary <string, string> .Empty,
                    projectId: document.Project.Id,
                    language: LanguageNames.VisualBasic,
                    description: "test1 description",
                    helpLink: "http://test1link"),

                new DiagnosticData(
                    id: "test2",
                    category: "Test",
                    message: "test2 message",
                    enuMessageForBingSearch: "test2 message format",
                    severity: DiagnosticSeverity.Warning,
                    defaultSeverity: DiagnosticSeverity.Warning,
                    isEnabledByDefault: true,
                    warningLevel: 0,
                    customTags: ImmutableArray.Create("Test2"),
                    properties: ImmutableDictionary <string, string> .Empty.Add("p1Key", "p2Value"),
                    projectId: document.Project.Id),

                new DiagnosticData(
                    id: "test3",
                    category: "Test",
                    message: "test3 message",
                    enuMessageForBingSearch: "test3 message format",
                    severity: DiagnosticSeverity.Error,
                    defaultSeverity: DiagnosticSeverity.Warning,
                    isEnabledByDefault: true,
                    warningLevel: 2,
                    customTags: ImmutableArray.Create("Test3", "Test3_2"),
                    properties: ImmutableDictionary <string, string> .Empty.Add("p2Key", "p2Value").Add("p1Key", "p1Value"),
                    projectId: document.Project.Id,
                    description: "test3 description",
                    helpLink: "http://test3link"),
            }.ToImmutableArray();

            var utcTime         = DateTime.UtcNow;
            var analyzerVersion = VersionStamp.Create(utcTime);
            var version         = VersionStamp.Create(utcTime.AddDays(1));

            var key = "project";
            var persistentService = workspace.Services.GetRequiredService <IPersistentStorageService>();
            var serializer        = new CodeAnalysis.Workspaces.Diagnostics.DiagnosticDataSerializer(analyzerVersion, version);

            Assert.True(await serializer.SerializeAsync(persistentService, document.Project, document, key, diagnostics, CancellationToken.None).ConfigureAwait(false));
            var recovered = await serializer.DeserializeAsync(persistentService, document.Project, document, key, CancellationToken.None);

            AssertDiagnostics(diagnostics, recovered);
        }