Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/dotnet/APIView/APIViewUnitTests/APIViewUnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
</ItemGroup>

<ItemGroup>
<None Update="SampleTestFiles\azure.data.tables.12.9.0.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SampleTestFiles\azure.data.tables.12.9.0_dep_diff.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SampleTestFiles\azure.data.tables.12.9.0_altered.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SampleTestFiles\azure.data.tables.12.9.1.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SampleTestFiles\TokenFileWithSectionsRevision3.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
125 changes: 124 additions & 1 deletion src/dotnet/APIView/APIViewUnitTests/CodeFileHelpersTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using A;
Comment thread
praveenkuttappan marked this conversation as resolved.
Outdated
using ApiView;
using APIView.Model.V2;
using APIView.TreeToken;
using APIViewWeb.Helpers;
using APIViewWeb.LeanModels;
using SharpCompress.Common;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -209,7 +214,7 @@ public void ComputeTokenDiff_Verify_API_only_Change_dummy_data()
{
modifiedCount += ModifiedLineCount(l);
}
Assert.Equal(1, modifiedCount);
Assert.Equal(4, modifiedCount);
}

private int ModifiedLineCount(ReviewLine line)
Expand All @@ -225,5 +230,123 @@ private int ModifiedLineCount(ReviewLine line)
}
return count;
}

[Fact]
public async void VerifyRenderedCodeFile()
{
var testCodeFilePath = Path.Combine("SampleTestFiles", "azure.data.tables.12.9.0.json");
FileInfo fileInfo = new FileInfo(testCodeFilePath);
var codeFile = await CodeFile.DeserializeAsync(fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read));
CodePanelRawData codePanelRawData = new CodePanelRawData()
{
activeRevisionCodeFile = codeFile
};
//Verify total lines in rendered output
var result = await CodeFileHelpers.GenerateCodePanelDataAsync(codePanelRawData);
Assert.NotNull(result);
Assert.Equal(false, result.HasDiff);
Assert.Equal(478, result.NodeMetaData.Count);

//Expected top level nodes 16
Assert.Equal(16, result.NodeMetaData["root"].ChildrenNodeIdsInOrder.Count);

//Verify rendered result has no diff when comparing same API code files
FileInfo fileInfoB = new FileInfo(testCodeFilePath);
var codeFileB = await CodeFile.DeserializeAsync(fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read));
codePanelRawData.diffRevisionCodeFile = codeFileB;
result = await CodeFileHelpers.GenerateCodePanelDataAsync(codePanelRawData);
Assert.NotNull(result);
Assert.Equal(false, result.HasDiff);

//Verify system generated comments
Assert.Equal(15, result.NodeMetaData.Values.Select(v => v.DiagnosticsObj.Count).Sum());
}

[Fact]
public async void VerifyCompareDiffApiSurface()
{
var testCodeFilePath = Path.Combine("SampleTestFiles", "azure.data.tables.12.9.0.json");
FileInfo fileInfo = new FileInfo(testCodeFilePath);
var codeFile = await CodeFile.DeserializeAsync(fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read));
CodePanelRawData codePanelRawData = new CodePanelRawData()
{
activeRevisionCodeFile = codeFile
};
var result = await CodeFileHelpers.GenerateCodePanelDataAsync(codePanelRawData);
Assert.NotNull(result);
Assert.Equal(false, result.HasDiff);
Assert.Equal(478, result.NodeMetaData.Count);

//Expected top level nodes 16
Assert.Equal(16, result.NodeMetaData["root"].ChildrenNodeIdsInOrder.Count);

//Verify rendered result has no diff when comparing different API code files
testCodeFilePath = Path.Combine("SampleTestFiles", "azure.data.tables.12.9.1.json");
FileInfo fileInfoB = new FileInfo(testCodeFilePath);
var codeFileB = await CodeFile.DeserializeAsync(fileInfoB.Open(FileMode.Open, FileAccess.Read, FileShare.Read));
codePanelRawData.diffRevisionCodeFile = codeFileB;
result = await CodeFileHelpers.GenerateCodePanelDataAsync(codePanelRawData);
Assert.NotNull(result);
Assert.Equal(true, result.HasDiff);
// Thre is only one API line change difference between 12.9.1 and 12.9.0
Assert.Equal(1, result.NodeMetaData.Values.Count(m => m.IsNodeWithDiff));
}

[Fact]
public async void VerifyAttributeLineChangeOnly()
{
var testCodeFilePath = Path.Combine("SampleTestFiles", "azure.data.tables.12.9.0.json");
FileInfo fileInfo = new FileInfo(testCodeFilePath);
var codeFile = await CodeFile.DeserializeAsync(fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read));
CodePanelRawData codePanelRawData = new CodePanelRawData()
{
activeRevisionCodeFile = codeFile
};
var result = await CodeFileHelpers.GenerateCodePanelDataAsync(codePanelRawData);
Assert.NotNull(result);
Assert.Equal(false, result.HasDiff);
Assert.Equal(478, result.NodeMetaData.Count);

//Expected top level nodes 16
Assert.Equal(16, result.NodeMetaData["root"].ChildrenNodeIdsInOrder.Count);

//Verify rendered result has no diff when comparing different API code files
testCodeFilePath = Path.Combine("SampleTestFiles", "azure.data.tables.12.9.0_altered.json");
FileInfo fileInfoB = new FileInfo(testCodeFilePath);
var codeFileB = await CodeFile.DeserializeAsync(fileInfoB.Open(FileMode.Open, FileAccess.Read, FileShare.Read));
codePanelRawData.diffRevisionCodeFile = codeFileB;
result = await CodeFileHelpers.GenerateCodePanelDataAsync(codePanelRawData);
Assert.NotNull(result);
Assert.Equal(true, result.HasDiff);
// Thre is only one API line change difference between 12.9.1 and 12.9.0
Assert.Equal(2, result.NodeMetaData.Values.Count(m => m.IsNodeWithDiff));
var modifiedLines = result.NodeMetaData.Values.Where(m => m.IsNodeWithDiff);
var changedTexts = new HashSet<string> (modifiedLines.Select(l => l.CodeLines.FirstOrDefault().ToString().Trim()));
Assert.Contains("[Flags]", changedTexts);
Assert.Contains("[FlagsModified]", changedTexts);
}

[Fact]
public async void VerifySameApiwithDependencyVersionChange()
{
var testCodeFilePath = Path.Combine("SampleTestFiles", "azure.data.tables.12.9.0.json");
FileInfo fileInfo = new FileInfo(testCodeFilePath);
var codeFile = await CodeFile.DeserializeAsync(fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read));
CodePanelRawData codePanelRawData = new CodePanelRawData()
{
activeRevisionCodeFile = codeFile
};

//Verify rendered result has no diff when comparing different API code files
testCodeFilePath = Path.Combine("SampleTestFiles", "azure.data.tables.12.9.0_dep_diff.json");
FileInfo fileInfoB = new FileInfo(testCodeFilePath);
var codeFileB = await CodeFile.DeserializeAsync(fileInfoB.Open(FileMode.Open, FileAccess.Read, FileShare.Read));
codePanelRawData.diffRevisionCodeFile = codeFileB;
var result = await CodeFileHelpers.GenerateCodePanelDataAsync(codePanelRawData);
Assert.NotNull(result);
//Dependency version change(marked as skip from diff )should not be considered as diff
Assert.Equal(false, result.HasDiff);
Assert.Equal(478, result.NodeMetaData.Count);
}
}
}

Large diffs are not rendered by default.

Loading