This commit is contained in:
Jimmy Lewis 2024-04-22 13:12:37 -07:00
Родитель 0ff93a1a0c
Коммит ed687cc19d
4 изменённых файлов: 109 добавлений и 1 удалений

Просмотреть файл

@ -55,6 +55,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Web.LibraryManage
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Web.LibraryManager.Vsix.Test", "test\Microsoft.Web.LibraryManager.Vsix.Test\Microsoft.Web.LibraryManager.Vsix.Test.csproj", "{00EE7B7F-EDA3-49E6-AA38-118C15B58CDB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Web.LibraryManager.Contracts.Test", "test\LibraryManager.Contracts.Test\Microsoft.Web.LibraryManager.Contracts.Test.csproj", "{514120AD-8F89-476A-8AB3-F582E6CA8697}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "schema", "schema", "{4B76692E-EF61-499F-900F-752FFC08D6E9}"
ProjectSection(SolutionItems) = preProject
src\schema\libman.json = src\schema\libman.json
@ -202,6 +204,18 @@ Global
{00EE7B7F-EDA3-49E6-AA38-118C15B58CDB}.Release|x64.Build.0 = Release|Any CPU
{00EE7B7F-EDA3-49E6-AA38-118C15B58CDB}.Release|x86.ActiveCfg = Release|Any CPU
{00EE7B7F-EDA3-49E6-AA38-118C15B58CDB}.Release|x86.Build.0 = Release|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Debug|Any CPU.Build.0 = Debug|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Debug|x64.ActiveCfg = Debug|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Debug|x64.Build.0 = Debug|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Debug|x86.ActiveCfg = Debug|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Debug|x86.Build.0 = Debug|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Release|Any CPU.ActiveCfg = Release|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Release|Any CPU.Build.0 = Release|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Release|x64.ActiveCfg = Release|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Release|x64.Build.0 = Release|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Release|x86.ActiveCfg = Release|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -219,6 +233,7 @@ Global
{E9BE3307-5F07-4757-BB06-3460813D7B9D} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
{00EE7B7F-EDA3-49E6-AA38-118C15B58CDB} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
{4B76692E-EF61-499F-900F-752FFC08D6E9} = {A72570B1-99EF-4BDD-B629-321CD56C9F7F}
{514120AD-8F89-476A-8AB3-F582E6CA8697} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {720C6A7F-67F7-4D00-881F-D3CDEA7ABE69}

Просмотреть файл

@ -2,4 +2,5 @@
using System.Runtime.CompilerServices;
[assembly: NeutralResourcesLanguage("en")]
[assembly:InternalsVisibleTo("Microsoft.Web.LibraryManager.Test")]
[assembly: InternalsVisibleTo("Microsoft.Web.LibraryManager.Test")]
[assembly: InternalsVisibleTo("Microsoft.Web.LibraryManager.Contracts.Test")]

Просмотреть файл

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreTFM);$(NetFxTFM)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\LibraryManager.Contracts\Microsoft.Web.LibraryManager.Contracts.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,65 @@
using Microsoft.Web.LibraryManager.Contracts;
namespace LibraryManager.Contracts.Test
{
[TestClass]
public class OperationResultTests
{
[TestMethod]
public void HasResult_NoErrors_Success()
{
var sut = new OperationResult<object>(new object());
Assert.IsTrue(sut.Success);
Assert.IsFalse(sut.Cancelled);
Assert.IsNotNull(sut.Result);
Assert.AreEqual(0, sut.Errors.Count);
Assert.IsFalse(sut.UpToDate);
}
[TestMethod]
public void HasResult_WithErrors_Failure()
{
var sut = new OperationResult<object>(new Error("TEST", "Test error"))
{
Result = new object(),
};
Assert.IsFalse(sut.Success);
Assert.IsFalse(sut.Cancelled);
Assert.IsNotNull(sut.Result);
Assert.AreEqual(1, sut.Errors.Count);
Assert.AreEqual("TEST", sut.Errors[0].Code);
}
[TestMethod]
public void NoResult_NoErrors_Failure()
{
// This scenario may represent an unknown failure - no errors were reported,
// but the expected result was not returned, so the operation was not successful.
var sut = new OperationResult<object>((object?)null);
Assert.IsFalse(sut.Success);
Assert.IsFalse(sut.Cancelled);
Assert.IsNull(sut.Result);
Assert.AreEqual(0, sut.Errors.Count);
}
[TestMethod]
[DataRow(true)]
[DataRow(false)]
public void Cancelled_NoErrors_Failure(bool isResultNull)
{
var sut = new OperationResult<object>(isResultNull ? null : new object())
{
Cancelled = true,
};
Assert.IsFalse(sut.Success);
Assert.IsTrue(sut.Cancelled);
Assert.AreEqual(isResultNull, sut.Result is null);
Assert.AreEqual(0, sut.Errors.Count);
}
}
}