public void SerializationTest_Document()
        {
            using (var workspace = new TestWorkspace(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, workspaceKind: "DiagnosticTest"))
            {
                var utcTime  = DateTime.UtcNow;
                var version1 = VersionStamp.Create(utcTime);
                var version2 = VersionStamp.Create(utcTime.AddDays(1));

                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"),
                };

                var original = new DiagnosticIncrementalAnalyzer.AnalysisData(version1, version2, diagnostics.ToImmutableArray());
                var state    = new DiagnosticIncrementalAnalyzer.DiagnosticState("Test", VersionStamp.Default, LanguageNames.CSharp);
                state.PersistAsync(document, original, CancellationToken.None).Wait();

                var recovered = state.TryGetExistingDataAsync(document, CancellationToken.None).Result;

                Assert.Equal(original.TextVersion, recovered.TextVersion);
                Assert.Equal(original.DataVersion, recovered.DataVersion);

                AssertDiagnostics(original.Items, recovered.Items);
            }
        }
        public void SerializationTest_Project()
        {
            using (var workspace = new TestWorkspace(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, workspaceKind: "DiagnosticTest"))
            {
                var utcTime  = DateTime.UtcNow;
                var version1 = VersionStamp.Create(utcTime);
                var version2 = VersionStamp.Create(utcTime.AddDays(1));

                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,
                        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"),
                        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"),
                        workspace, document.Project.Id, description: "test3 description", helpLink: "http://test3link"),
                };

                var original = new DiagnosticIncrementalAnalyzer.AnalysisData(version1, version2, diagnostics.ToImmutableArray());
                var state    = new DiagnosticIncrementalAnalyzer.DiagnosticState("Test", VersionStamp.Default, LanguageNames.CSharp);
                state.PersistAsync(document.Project, original, CancellationToken.None).Wait();

                var recovered = state.TryGetExistingDataAsync(document.Project, CancellationToken.None).Result;

                Assert.Equal(original.TextVersion, recovered.TextVersion);
                Assert.Equal(original.DataVersion, recovered.DataVersion);

                AssertDiagnostics(original.Items, recovered.Items);
            }
        }