1
0
Форкнуть 0

Merge pull request #451 from whoisj/better-tests

Update dependencies and migrate tests to Xunit.
This commit is contained in:
J Wyman 2017-06-23 00:04:17 -04:00 коммит произвёл GitHub
Родитель 1dd064a597 a36f3937a8
Коммит ce1c34bb18
47 изменённых файлов: 892 добавлений и 730 удалений

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

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -16,6 +17,8 @@
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -64,6 +67,9 @@
<Name>Microsoft.Alm.Authentication</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
@ -84,6 +90,12 @@
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

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

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net452" developmentDependency="true" />
</packages>

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

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -12,6 +13,8 @@
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -144,9 +147,6 @@
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Resource Include="Assets\atlassian-rgb-navy-medium.png" />
<Resource Include="Assets\bitbucket_rgb_blue.png" />
@ -158,8 +158,19 @@
<ItemGroup>
<Resource Include="Assets\SourceTree.ico" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<Import Project="..\Gui-Shared\Gui-Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

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

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.13.1" targetFramework="net451" />
</packages>
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net451" developmentDependency="true" />
</packages>

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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -142,7 +142,7 @@ COPY /V /Y "%25src%25LICENSE.txt" "%25dst%25LICENSE.txt"
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

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

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="2.0.1" targetFramework="net451" developmentDependency="true" />
</packages>
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net451" developmentDependency="true" />
</packages>

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

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -9,7 +11,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Alm.CredentialHelper.Test</RootNamespace>
<AssemblyName>Microsoft.Alm.CredentialHelper.Test</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
@ -19,6 +21,7 @@
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -45,26 +48,27 @@
<CodeAnalysisRuleSet>..\analysisRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.0.0\lib\net45\Castle.Core.dll</HintPath>
<Reference Include="Castle.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.1.0\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.7.8.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.7.8\lib\net45\Moq.dll</HintPath>
<Reference Include="Moq, Version=4.7.63.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.7.63\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="OperationArgumentsTests.cs" />
@ -88,31 +92,14 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

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

@ -2,14 +2,13 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Microsoft.Alm.Cli.Test
{
[TestClass]
public class OperationArgumentsTests
{
[TestMethod]
[Fact]
public void Typical()
{
const string input = "protocol=https\n"
@ -30,19 +29,20 @@ namespace Microsoft.Alm.Cli.Test
cut = new OperationArguments.Impl(memory);
}
Assert.AreEqual("https", cut.QueryProtocol);
Assert.AreEqual("example.visualstudio.com", cut.QueryHost);
Assert.AreEqual("https://example.visualstudio.com/", cut.TargetUri.ToString());
Assert.AreEqual("path", cut.QueryPath);
Assert.AreEqual("userName", cut.CredUsername);
Assert.AreEqual("incorrect", cut.CredPassword);
Assert.Equal("https", cut.QueryProtocol);
Assert.Equal("example.visualstudio.com", cut.QueryHost);
Assert.Equal("https://example.visualstudio.com/", cut.TargetUri.ToString());
Assert.Equal("path", cut.QueryPath);
Assert.Equal("userName", cut.CredUsername);
Assert.Equal("incorrect", cut.CredPassword);
var expected = ReadLines(input);
var actual = ReadLines(cut.ToString());
CollectionAssert.AreEqual(expected, actual);
Assert.Equal(expected, actual);
}
[TestMethod]
[Fact]
public void SpecialCharacters()
{
const string input = "protocol=https\n"
@ -63,19 +63,19 @@ namespace Microsoft.Alm.Cli.Test
cut = new OperationArguments.Impl(memory);
}
Assert.AreEqual("https", cut.QueryProtocol);
Assert.AreEqual("example.visualstudio.com", cut.QueryHost);
Assert.AreEqual("https://example.visualstudio.com/", cut.TargetUri.ToString());
Assert.AreEqual("path", cut.QueryPath);
Assert.AreEqual("userNamể", cut.CredUsername);
Assert.AreEqual("ḭncorrect", cut.CredPassword);
Assert.Equal("https", cut.QueryProtocol);
Assert.Equal("example.visualstudio.com", cut.QueryHost);
Assert.Equal("https://example.visualstudio.com/", cut.TargetUri.ToString());
Assert.Equal("path", cut.QueryPath);
Assert.Equal("userNamể", cut.CredUsername);
Assert.Equal("ḭncorrect", cut.CredPassword);
var expected = ReadLines(input);
var actual = ReadLines(cut.ToString());
CollectionAssert.AreEqual(expected, actual);
Assert.Equal(expected, actual);
}
[TestMethod]
[Fact]
public void CreateTargetUriGitHubSimple()
{
var input = new InputArg()
@ -89,7 +89,7 @@ namespace Microsoft.Alm.Cli.Test
CreateTargetUriTestWithPath(input);
}
[TestMethod]
[Fact]
public void CreateTargetUri_VstsSimple()
{
var input = new InputArg()
@ -103,7 +103,7 @@ namespace Microsoft.Alm.Cli.Test
CreateTargetUriTestWithPath(input);
}
[TestMethod]
[Fact]
public void CreateTargetUriGitHubComplex()
{
var input = new InputArg()
@ -118,7 +118,7 @@ namespace Microsoft.Alm.Cli.Test
CreateTargetUriTestWithPath(input);
}
[TestMethod]
[Fact]
public void CreateTargetUriWithPortNumber()
{
var input = new InputArg()
@ -132,7 +132,7 @@ namespace Microsoft.Alm.Cli.Test
CreateTargetUriTestWithPath(input);
}
[TestMethod]
[Fact]
public void CreateTargetUriComplexAndMessy()
{
var input = new InputArg()
@ -147,7 +147,7 @@ namespace Microsoft.Alm.Cli.Test
CreateTargetUriTestWithPath(input);
}
[TestMethod]
[Fact]
public void CreateTargetUriWithCredentials()
{
var input = new InputArg()
@ -163,7 +163,7 @@ namespace Microsoft.Alm.Cli.Test
CreateTargetUriTestWithPath(input);
}
[TestMethod]
[Fact]
public void CreateTargetUriUnc()
{
var input = new InputArg()
@ -178,7 +178,7 @@ namespace Microsoft.Alm.Cli.Test
CreateTargetUriTestWithPath(input);
}
[TestMethod]
[Fact]
public void CreateTargetUriUncColloquial()
{
var input = new InputArg()
@ -203,17 +203,17 @@ namespace Microsoft.Alm.Cli.Test
var oparg = new OperationArguments.Impl(memory);
Assert.IsNotNull(oparg);
Assert.AreEqual(input.Protocol ?? string.Empty, oparg.QueryProtocol);
Assert.AreEqual(input.Host ?? string.Empty, oparg.QueryHost);
Assert.AreEqual(input.Path, oparg.QueryPath);
Assert.AreEqual(input.Username, oparg.CredUsername);
Assert.AreEqual(input.Password, oparg.CredPassword);
Assert.NotNull(oparg);
Assert.Equal(input.Protocol ?? string.Empty, oparg.QueryProtocol);
Assert.Equal(input.Host ?? string.Empty, oparg.QueryHost);
Assert.Equal(input.Path, oparg.QueryPath);
Assert.Equal(input.Username, oparg.CredUsername);
Assert.Equal(input.Password, oparg.CredPassword);
// file or unc paths are treated specially
if (oparg.QueryUri.Scheme != "file")
if (oparg.QueryUri.Scheme != System.Uri.UriSchemeFile)
{
Assert.AreEqual("/", oparg.QueryUri.AbsolutePath);
Assert.Equal("/", oparg.QueryUri.AbsolutePath);
}
}
}
@ -231,17 +231,17 @@ namespace Microsoft.Alm.Cli.Test
var oparg = new OperationArguments.Impl(memory);
oparg.UseHttpPath = false;
Assert.IsNotNull(oparg);
Assert.AreEqual(input.Protocol ?? string.Empty, oparg.QueryProtocol);
Assert.AreEqual(input.Host ?? string.Empty, oparg.QueryHost);
Assert.AreEqual(input.Path, oparg.QueryPath);
Assert.AreEqual(input.Username, oparg.CredUsername);
Assert.AreEqual(input.Password, oparg.CredPassword);
Assert.NotNull(oparg);
Assert.Equal(input.Protocol ?? string.Empty, oparg.QueryProtocol);
Assert.Equal(input.Host ?? string.Empty, oparg.QueryHost);
Assert.Equal(input.Path, oparg.QueryPath);
Assert.Equal(input.Username, oparg.CredUsername);
Assert.Equal(input.Password, oparg.CredPassword);
// file or unc paths are treated specially
if (oparg.QueryUri.Scheme != "file")
if (oparg.QueryUri.Scheme != System.Uri.UriSchemeFile)
{
Assert.AreEqual("/", oparg.QueryUri.AbsolutePath);
Assert.Equal("/", oparg.QueryUri.AbsolutePath);
}
}
}
@ -259,17 +259,17 @@ namespace Microsoft.Alm.Cli.Test
var oparg = new OperationArguments.Impl(memory);
oparg.UseHttpPath = true;
Assert.IsNotNull(oparg);
Assert.AreEqual(input.Protocol ?? string.Empty, oparg.QueryProtocol);
Assert.AreEqual(input.Host ?? string.Empty, oparg.QueryHost);
Assert.AreEqual(input.Path, oparg.QueryPath);
Assert.AreEqual(input.Username, oparg.CredUsername);
Assert.AreEqual(input.Password, oparg.CredPassword);
Assert.NotNull(oparg);
Assert.Equal(input.Protocol ?? string.Empty, oparg.QueryProtocol);
Assert.Equal(input.Host ?? string.Empty, oparg.QueryHost);
Assert.Equal(input.Path, oparg.QueryPath);
Assert.Equal(input.Username, oparg.CredUsername);
Assert.Equal(input.Password, oparg.CredPassword);
// file or unc paths are treated specially
if (oparg.QueryUri.Scheme != "file")
if (oparg.QueryUri.Scheme != System.Uri.UriSchemeFile)
{
Assert.AreEqual("/" + input.Path, oparg.QueryUri.AbsolutePath);
Assert.Equal("/" + input.Path, oparg.QueryUri.AbsolutePath);
}
}
}

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

@ -25,22 +25,21 @@
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Xunit;
namespace Microsoft.Alm.Cli.Test
{
[TestClass]
public class ProgramTests
{
[TestMethod]
[Fact]
public void LoadOperationArgumentsTest()
{
Program program = new Program();
program._dieException = (Program caller, Exception e, string path, int line, string name) => Assert.Fail($"Error: {e.ToString()}");
program._dieMessage = (Program caller, string m, string path, int line, string name) => Assert.Fail($"Error: {m}");
program._exit = (Program caller, int e, string m, string path, int line, string name) => Assert.Fail($"Error: {e} {m}");
program._dieException = (Program caller, Exception e, string path, int line, string name) => Assert.False(true, $"Error: {e.ToString()}");
program._dieMessage = (Program caller, string m, string path, int line, string name) => Assert.False(true, $"Error: {m}");
program._exit = (Program caller, int e, string m, string path, int line, string name) => Assert.False(true, $"Error: {e} {m}");
var envvars = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
@ -64,10 +63,10 @@ namespace Microsoft.Alm.Cli.Test
program.LoadOperationArguments(opargs);
Assert.IsNotNull(opargs);
Assert.NotNull(opargs);
}
[TestMethod]
[Fact]
public void TryReadBooleanTest()
{
bool? yesno;
@ -93,12 +92,12 @@ namespace Microsoft.Alm.Cli.Test
Program program = new Program();
Assert.IsFalse(CommonFunctions.TryReadBoolean(program, opargsMock.Object, "notFound", "notFound", out yesno));
Assert.IsFalse(yesno.HasValue);
Assert.False(CommonFunctions.TryReadBoolean(program, opargsMock.Object, "notFound", "notFound", out yesno));
Assert.False(yesno.HasValue);
Assert.IsTrue(CommonFunctions.TryReadBoolean(program, opargsMock.Object, Program.ConfigPreserveCredentialsKey, Program.EnvironPreserveCredentialsKey, out yesno));
Assert.IsTrue(yesno.HasValue);
Assert.IsFalse(yesno.Value);
Assert.True(CommonFunctions.TryReadBoolean(program, opargsMock.Object, Program.ConfigPreserveCredentialsKey, Program.EnvironPreserveCredentialsKey, out yesno));
Assert.True(yesno.HasValue);
Assert.False(yesno.Value);
envvars = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
@ -108,9 +107,9 @@ namespace Microsoft.Alm.Cli.Test
opargsMock.Setup(r => r.EnvironmentVariables)
.Returns(envvars);
Assert.IsTrue(CommonFunctions.TryReadBoolean(program, opargsMock.Object, Program.ConfigPreserveCredentialsKey, Program.EnvironPreserveCredentialsKey, out yesno));
Assert.IsTrue(yesno.HasValue);
Assert.IsTrue(yesno.Value);
Assert.True(CommonFunctions.TryReadBoolean(program, opargsMock.Object, Program.ConfigPreserveCredentialsKey, Program.EnvironPreserveCredentialsKey, out yesno));
Assert.True(yesno.HasValue);
Assert.True(yesno.Value);
envvars = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
@ -120,8 +119,8 @@ namespace Microsoft.Alm.Cli.Test
opargsMock.Setup(r => r.EnvironmentVariables)
.Returns(envvars);
Assert.IsFalse(CommonFunctions.TryReadBoolean(program, opargsMock.Object, Program.ConfigPreserveCredentialsKey, Program.EnvironPreserveCredentialsKey, out yesno));
Assert.IsFalse(yesno.HasValue);
Assert.False(CommonFunctions.TryReadBoolean(program, opargsMock.Object, Program.ConfigPreserveCredentialsKey, Program.EnvironPreserveCredentialsKey, out yesno));
Assert.False(yesno.HasValue);
}
}
}

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

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="4.0.0" targetFramework="net452" />
<package id="Microsoft.Net.Compilers" version="2.0.1" targetFramework="net452" developmentDependency="true" />
<package id="Moq" version="4.7.8" targetFramework="net452" />
</packages>
<package id="Castle.Core" version="4.1.0" targetFramework="net452" />
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net452" developmentDependency="true" />
<package id="Moq" version="4.7.63" targetFramework="net452" />
<package id="xunit" version="2.2.0" targetFramework="net452" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net452" />
<package id="xunit.assert" version="2.2.0" targetFramework="net452" />
<package id="xunit.core" version="2.2.0" targetFramework="net452" />
<package id="xunit.extensibility.core" version="2.2.0" targetFramework="net452" />
<package id="xunit.extensibility.execution" version="2.2.0" targetFramework="net452" />
<package id="xunit.runner.visualstudio" version="2.2.0" targetFramework="net452" developmentDependency="true" />
</packages>

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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<ProjectGuid>{19770407-63D4-40A8-A9DF-F1C4B473308A}</ProjectGuid>
@ -122,7 +122,7 @@ COPY /V /Y "%25src%25LICENSE.txt" "%25dst%25LICENSE.txt"
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

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

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="2.0.1" targetFramework="net451" developmentDependency="true" />
</packages>
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net451" developmentDependency="true" />
</packages>

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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -14,6 +14,7 @@
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -80,7 +81,7 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

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

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="2.0.1" targetFramework="net452" developmentDependency="true" />
</packages>
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net452" developmentDependency="true" />
</packages>

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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
</startup>
</configuration>

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<ProjectGuid>{CF306116-BBF0-4CC7-AFCE-A506AC4752CB}</ProjectGuid>
@ -236,7 +236,7 @@ COPY /V /Y "%25src%25LICENSE.txt" "%25dst%25LICENSE.txt"
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

44
GitHub.Authentication/Properties/Resources.Designer.cs сгенерированный
Просмотреть файл

@ -10,8 +10,8 @@
namespace GitHub.Authentication.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
@ -23,15 +23,15 @@ namespace GitHub.Authentication.Properties {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
@ -45,7 +45,7 @@ namespace GitHub.Authentication.Properties {
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
@ -59,7 +59,7 @@ namespace GitHub.Authentication.Properties {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Cancel.
/// </summary>
@ -68,7 +68,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("CancelText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Dont have an account? .
/// </summary>
@ -77,7 +77,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("DoNotHaveAccountText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Forgot your password?.
/// </summary>
@ -86,7 +86,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("ForgotPasswordText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Learn More.
/// </summary>
@ -95,7 +95,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("LearnMoreLink", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Login.
/// </summary>
@ -104,7 +104,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("LoginLabel", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Login.
/// </summary>
@ -113,7 +113,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("LoginLinkText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Username or email.
/// </summary>
@ -122,7 +122,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("LoginPromptText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Please enter your username or email address.
/// </summary>
@ -131,7 +131,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("LoginRequired", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Open the two-factor authentication app on your device to view your authentication code..
/// </summary>
@ -140,7 +140,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("OpenTwoFactorAuthAppText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Password.
/// </summary>
@ -149,7 +149,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("PasswordPromptText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Please enter your password.
/// </summary>
@ -158,7 +158,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("PasswordRequired", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sign up.
/// </summary>
@ -167,7 +167,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("SignUpLinkText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Two-factor authentication.
/// </summary>
@ -176,7 +176,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("TwoFactorAuthText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to We sent you a message via SMS with your authentication code..
/// </summary>
@ -185,7 +185,7 @@ namespace GitHub.Authentication.Properties {
return ResourceManager.GetString("TwoFactorSms", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Ok.
/// </summary>

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

@ -9,14 +9,14 @@
//------------------------------------------------------------------------------
namespace GitHub.Authentication.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;

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

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="2.0.1" targetFramework="net451" developmentDependency="true" />
</packages>
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net451" developmentDependency="true" />
</packages>

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

@ -1,9 +1,8 @@
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Microsoft.Alm.Authentication.Test
{
[TestClass]
public class BasicAuthTests
{
public BasicAuthTests()
@ -11,7 +10,7 @@ namespace Microsoft.Alm.Authentication.Test
Trace.Listeners.AddRange(Debug.Listeners);
}
[TestMethod]
[Fact]
public void BasicAuthDeleteCredentialsTest()
{
TargetUri targetUri = new TargetUri("http://localhost");
@ -21,10 +20,10 @@ namespace Microsoft.Alm.Authentication.Test
basicAuth.DeleteCredentials(targetUri);
Assert.IsNull(basicAuth.CredentialStore.ReadCredentials(targetUri), "User credentials were not deleted as expected");
Assert.Null(basicAuth.CredentialStore.ReadCredentials(targetUri));
}
[TestMethod]
[Fact]
public void BasicAuthGetCredentialsTest()
{
TargetUri targetUri = new TargetUri("http://localhost");
@ -32,16 +31,16 @@ namespace Microsoft.Alm.Authentication.Test
Credential credentials = null;
Assert.IsNull(credentials = basicAuth.GetCredentials(targetUri), "User credentials were unexpectedly retrieved.");
Assert.Null(credentials = basicAuth.GetCredentials(targetUri));
credentials = new Credential("username", "password");
basicAuth.CredentialStore.WriteCredentials(targetUri, credentials);
Assert.IsNotNull(credentials = basicAuth.GetCredentials(targetUri), "User credentials were unexpectedly not retrieved.");
Assert.NotNull(credentials = basicAuth.GetCredentials(targetUri));
}
[TestMethod]
[Fact]
public void BasicAuthSetCredentialsTest()
{
TargetUri targetUri = new TargetUri("http://localhost");
@ -49,19 +48,17 @@ namespace Microsoft.Alm.Authentication.Test
Credential credentials = null;
Assert.IsNull(credentials = basicAuth.GetCredentials(targetUri), "User credentials were unexpectedly retrieved.");
try
Assert.Null(credentials = basicAuth.GetCredentials(targetUri));
Assert.Throws<System.ArgumentNullException>(() =>
{
basicAuth.SetCredentials(targetUri, credentials);
Assert.Fail("User credentials were unexpectedly set.");
}
catch { }
});
credentials = new Credential("username", "password");
basicAuth.SetCredentials(targetUri, credentials);
Assert.IsNotNull(credentials = basicAuth.GetCredentials(targetUri), "User credentials were unexpectedly not retrieved.");
Assert.NotNull(credentials = basicAuth.GetCredentials(targetUri));
}
private BasicAuthentication GetBasicAuthentication(string @namespace)

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

@ -1,14 +1,13 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Microsoft.Alm.Authentication.Test
{
[TestClass]
public class CredentialTests
{
private const string Namespace = "test";
[TestMethod]
[Fact]
public void UriToName_GitHubSimple()
{
const string Expected = Namespace + ":https://www.github.com";
@ -17,7 +16,7 @@ namespace Microsoft.Alm.Authentication.Test
UriToNameTest(Namespace, Original, Expected);
}
[TestMethod]
[Fact]
public void UriToName_VstsSimple()
{
const string Expected = Namespace + ":https://account.visualstudio.com";
@ -26,7 +25,7 @@ namespace Microsoft.Alm.Authentication.Test
UriToNameTest(Namespace, Original, Expected);
}
[TestMethod]
[Fact]
public void UriToName_HttpsWithPath()
{
const string Expected = Namespace + ":https://github.com/Microsoft/Git-Credential-Manager-for-Windows.git";
@ -35,7 +34,7 @@ namespace Microsoft.Alm.Authentication.Test
UriToNameTest(Namespace, Original, Expected);
}
[TestMethod]
[Fact]
public void UriToName_HttpsWithTrailingSlash()
{
const string Expected = Namespace + ":https://www.github.com";
@ -44,7 +43,7 @@ namespace Microsoft.Alm.Authentication.Test
UriToNameTest(Namespace, Original, Expected);
}
[TestMethod]
[Fact]
public void UriToName_ComplexVsts()
{
const string Expected = Namespace + ":https://mytenant.visualstudio.com/MYTENANT/_git/App.MyApp";
@ -53,10 +52,10 @@ namespace Microsoft.Alm.Authentication.Test
var uri = new Uri(Original);
var actual = Secret.UriToName(uri, Namespace);
Assert.AreEqual(Expected, actual);
Assert.Equal(Expected, actual);
}
[TestMethod]
[Fact]
public void UriToName_Unc()
{
const string Expected = Namespace + ":file://unc/path";
@ -65,7 +64,7 @@ namespace Microsoft.Alm.Authentication.Test
UriToNameTest(Namespace, Original, Expected);
}
[TestMethod]
[Fact]
public void UriToName_UncWithPrefix()
{
const string Expected = Namespace + ":file://unc/path";
@ -74,7 +73,7 @@ namespace Microsoft.Alm.Authentication.Test
UriToNameTest(Namespace, Original, Expected);
}
[TestMethod]
[Fact]
public void UriToName_UncWithTrailingSlash()
{
const string Expected = Namespace + ":file://unc/path";
@ -83,85 +82,89 @@ namespace Microsoft.Alm.Authentication.Test
var uri = new Uri(Original);
var actual = Secret.UriToName(uri, Namespace);
Assert.AreEqual(Expected, actual);
Assert.Equal(Expected, actual);
}
[TestMethod]
[Fact]
public void CredentialStoreUrl()
{
ICredentialStoreTest(new SecretStore("test", null, null, Secret.UriToName), "http://dummy.url/for/testing", "username", "password");
}
[TestMethod]
[Fact]
public void CredentialStoreUrlWithParams()
{
ICredentialStoreTest(new SecretStore("test", null, null, Secret.UriToName), "http://dummy.url/for/testing?with=params", "username", "password");
}
[TestMethod]
[Fact]
public void CredentialStoreUnc()
{
ICredentialStoreTest(new SecretStore("test", null, null, Secret.UriToName), @"\\unc\share\test", "username", "password");
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
[Fact]
public void CredentialStoreUsernameNullReject()
{
ICredentialStoreTest(new SecretStore("test", null, null, Secret.UriToName), "http://dummy.url/for/testing", null, "null_usernames_are_illegal");
Assert.Throws<ArgumentNullException>(() =>
{
ICredentialStoreTest(new SecretStore("test", null, null, Secret.UriToName), "http://dummy.url/for/testing", null, "null_usernames_are_illegal");
});
}
[TestMethod]
[Fact]
public void CredentialStoreUsernameBlank()
{
ICredentialStoreTest(new SecretStore("test", null, null, Secret.UriToName), "http://dummy.url/for/testing", "", "blank_usernames_are_legal");
}
[TestMethod]
[Fact]
public void CredentialStorePasswordNull()
{
ICredentialStoreTest(new SecretStore("test", null, null, Secret.UriToName), "http://dummy.url/for/testing", "null_passwords_are_illegal", null);
}
[TestMethod]
[Fact]
public void CredentialStorePassswordBlank()
{
ICredentialStoreTest(new SecretStore("test", null, null, Secret.UriToName), "http://dummy.url/for/testing", "blank_passwords_are_legal", "");
}
[TestMethod]
[Fact]
public void SecretCacheUrl()
{
ICredentialStoreTest(new SecretCache("test-cache"), "http://dummy.url/for/testing", "username", "password");
ICredentialStoreTest(new SecretCache("test-cache"), "http://dummy.url/for/testing", "username", "password");
}
[TestMethod]
[Fact]
public void SecretCacheUrlWithParams()
{
ICredentialStoreTest(new SecretCache("test-cache", Secret.UriToName), "http://dummy.url/for/testing?with=params", "username", "password");
}
[TestMethod]
[Fact]
public void SecretCacheUnc()
{
ICredentialStoreTest(new SecretCache("test-cache", Secret.UriToName), @"\\unc\share\test", "username", "password");
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
[Fact]
public void SecretCacheUsernameNull()
{
ICredentialStoreTest(new SecretCache("test-cache", Secret.UriToName), "http://dummy.url/for/testing", null, "null_usernames_are_illegal");
Assert.Throws<ArgumentNullException>(() =>
{
ICredentialStoreTest(new SecretCache("test-cache", Secret.UriToName), "http://dummy.url/for/testing", null, "null_usernames_are_illegal");
});
}
[TestMethod]
[Fact]
public void SecretCacheUsernameBlankReject()
{
ICredentialStoreTest(new SecretCache("test-cache", Secret.UriToName), "http://dummy.url/for/testing", "", "blank_usernames_are_illegal");
}
[TestMethod]
[Fact]
public void SecretCachePasswordNull()
{
ICredentialStoreTest(new SecretCache("test-cache", Secret.UriToName), "http://dummy.url/for/testing", "null_passwords_are_illegal", null);
@ -175,19 +178,14 @@ namespace Microsoft.Alm.Authentication.Test
credentialStore.WriteCredentials(uri, writeCreds);
if ((readCreds = credentialStore.ReadCredentials(uri)) != null)
{
Assert.AreEqual(writeCreds.Password, readCreds.Password, "Passwords did not match between written and read credentials");
Assert.AreEqual(writeCreds.Username, readCreds.Username, "Usernames did not match between written and read credentials");
}
else
{
Assert.Fail("Failed to read credentials");
}
readCreds = credentialStore.ReadCredentials(uri);
Assert.NotNull(readCreds);
Assert.Equal(writeCreds.Password, readCreds.Password);
Assert.Equal(writeCreds.Username, readCreds.Username);
credentialStore.DeleteCredentials(uri);
Assert.IsNull(readCreds = credentialStore.ReadCredentials(uri), "Deleted credentials were read back");
Assert.Null(readCreds = credentialStore.ReadCredentials(uri));
}
private static void UriToNameTest(string @namespace, string original, string expected)
@ -195,7 +193,7 @@ namespace Microsoft.Alm.Authentication.Test
var uri = new Uri(original);
var actual = Secret.UriToName(uri, @namespace);
Assert.AreEqual(expected, actual);
Assert.Equal(expected, actual);
}
}
}

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

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -9,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Alm.Authentication.Test</RootNamespace>
<AssemblyName>Microsoft.Alm.Authentication.Test</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
@ -19,6 +20,7 @@
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -45,34 +47,35 @@
<CodeAnalysisRuleSet>..\analysisRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.13.1.846, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.1\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
<Private>True</Private>
<Reference Include="Castle.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.1.0\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.13.1.846, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.1\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll</HintPath>
<Private>True</Private>
<Reference Include="Moq, Version=4.7.63.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.7.63\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Net.Http" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="AuthenticationTests.cs" />
<Compile Include="BasicAuthTests.cs" />
<Compile Include="CredentialTests.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TargetUriTests.cs" />
<Compile Include="TokenTests.cs" />
</ItemGroup>
<ItemGroup>
@ -84,32 +87,18 @@
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="xunit.runner.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

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

@ -0,0 +1,137 @@
using System;
using System.Collections.Generic;
using Xunit;
namespace Microsoft.Alm.Authentication.Test
{
public class TargetUriTests
{
public static object[] UrlData
{
get
{
List<object[]> data = new List<object[]>()
{
new object[] { "https://microsoft.visualstudio.com", "https://github.com", "https://bitbucket.org" },
new object[] { "https://my-host.com", null, "http://proxy-local:8080" },
new object[] { "https://random-host.com", null, null },
new object[] { "https://random-host.com", "https://q.random.com", null },
new object[] { "https://random-host.com", "https://q.random.com", "http://proxy-local:8080" },
new object[] { "http://random-host.com", "http://q.random.com", "https://proxy-local:8080" },
};
return data.ToArray();
}
}
[Theory]
[MemberData(nameof(UrlData))]
public void TargetUri_Basics(string actualUrl, string queryUrl, string proxyUrl)
{
TargetUri targetUri;
Uri actualUri;
Uri queryUri;
Uri proxyUri;
actualUri = new TargetUri(actualUrl);
targetUri = new TargetUri(actualUrl);
Assert.NotNull(targetUri);
Assert.Equal(actualUri.AbsolutePath, targetUri.AbsolutePath);
Assert.Equal(actualUri.DnsSafeHost, targetUri.DnsSafeHost);
Assert.Equal(actualUri.Host, targetUri.Host);
Assert.Equal(actualUri.IsAbsoluteUri, targetUri.IsAbsoluteUri);
Assert.Equal(actualUri.IsDefaultPort, targetUri.IsDefaultPort);
Assert.Equal(actualUri.Port, targetUri.Port);
Assert.Equal(actualUri.Scheme, targetUri.Scheme);
Assert.Equal(actualUri.UserInfo, targetUri.TargetUriUsername);
actualUri = actualUrl is null ? null : new Uri(actualUrl);
queryUri = queryUrl is null ? null : new Uri(queryUrl);
proxyUri = proxyUrl is null ? null : new Uri(proxyUrl);
targetUri = new TargetUri(actualUrl, queryUrl, proxyUrl);
Assert.NotNull(targetUri);
// Since the actual Uri will substitute for a null query Uri,
// test the correct value.
var uri = queryUri ?? actualUri;
Assert.Equal(uri.AbsolutePath, targetUri.AbsolutePath);
Assert.Equal(uri.DnsSafeHost, targetUri.DnsSafeHost);
Assert.Equal(uri.Host, targetUri.Host);
Assert.Equal(uri.IsAbsoluteUri, targetUri.IsAbsoluteUri);
Assert.Equal(uri.IsDefaultPort, targetUri.IsDefaultPort);
Assert.Equal(uri.Port, targetUri.Port);
Assert.Equal(uri.Scheme, targetUri.Scheme);
Assert.Equal(uri.UserInfo, targetUri.TargetUriUsername);
Assert.Equal(actualUri, targetUri.ActualUri);
Assert.Equal(uri, targetUri.QueryUri);
Assert.Equal(proxyUri, targetUri.ProxyUri);
targetUri = new TargetUri(actualUri, queryUri, proxyUri);
Assert.NotNull(targetUri);
Assert.Equal(uri.AbsolutePath, targetUri.AbsolutePath);
Assert.Equal(uri.DnsSafeHost, targetUri.DnsSafeHost);
Assert.Equal(uri.Host, targetUri.Host);
Assert.Equal(uri.IsAbsoluteUri, targetUri.IsAbsoluteUri);
Assert.Equal(uri.IsDefaultPort, targetUri.IsDefaultPort);
Assert.Equal(uri.Port, targetUri.Port);
Assert.Equal(uri.Scheme, targetUri.Scheme);
Assert.Equal(uri.UserInfo, targetUri.TargetUriUsername);
Assert.Equal(actualUri, targetUri.ActualUri);
Assert.Equal(uri, targetUri.QueryUri);
Assert.Equal(proxyUri, targetUri.ProxyUri);
}
[Theory]
[MemberData(nameof(UrlData))]
public void TargetUri_WebProxy(string actualUrl, string queryUrl, string proxyUrl)
{
var targetUri = new TargetUri(actualUrl, queryUrl, proxyUrl);
var proxy = targetUri.WebProxy;
Assert.NotNull(proxy);
if (!(proxyUrl is null))
{
Assert.Equal(new Uri(proxyUrl), proxy.Address);
}
else
{
Assert.Null(proxy.Address);
}
}
[Theory]
[MemberData(nameof(UrlData))]
public void TargetUri_HttpClientHandler(string actualUrl, string queryUrl, string proxyUrl)
{
var targetUri = new TargetUri(actualUrl, queryUrl, proxyUrl);
var client = targetUri.HttpClientHandler;
Assert.NotNull(client);
if (!(proxyUrl is null))
{
Assert.True(client.UseProxy);
Assert.NotNull(client.Proxy);
if (client.Proxy is System.Net.WebProxy proxy)
{
Assert.Equal(new Uri(proxyUrl), proxy.Address);
}
}
else
{
Assert.Null(client.Proxy);
Assert.False(client.UseProxy);
}
}
}
}

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

@ -1,43 +1,42 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Microsoft.Alm.Authentication.Test
{
[TestClass]
public class TokenTests
{
private const string TokenString = "The Azure AD Authentication Library (ADAL) for .NET enables client application developers to easily authenticate users to cloud or on-premises Active Directory (AD), and then obtain access tokens for securing API calls. ADAL for .NET has many features that make authentication easier for developers, such as asynchronous support, a configurable token cache that stores access tokens and refresh tokens, automatic token refresh when an access token expires and a refresh token is available, and more. By handling most of the complexity, ADAL can help a developer focus on business logic in their application and easily secure resources without being an expert on security.";
[TestMethod]
[Fact]
public void TokenStoreUrl()
{
ITokenStoreTest(new SecretStore("test-token"), "http://dummy.url/for/testing", TokenString);
}
[TestMethod]
[Fact]
public void TokenStoreUrlWithParams()
{
ITokenStoreTest(new SecretStore("test-token"), "http://dummy.url/for/testing?with=params", TokenString);
}
[TestMethod]
[Fact]
public void TokenStoreUnc()
{
ITokenStoreTest(new SecretStore("test-token"), @"\\unc\share\test", TokenString);
}
[TestMethod]
[Fact]
public void TokenCacheUrl()
{
ITokenStoreTest(new SecretCache("test-token"), "http://dummy.url/for/testing", TokenString);
}
[TestMethod]
[Fact]
public void TokenCacheUrlWithParams()
{
ITokenStoreTest(new SecretCache("test-token"), "http://dummy.url/for/testing?with=params", TokenString);
}
[TestMethod]
[Fact]
public void TokenCacheUnc()
{
ITokenStoreTest(new SecretCache("test-token"), @"\\unc\share\test", TokenString);
@ -52,19 +51,14 @@ namespace Microsoft.Alm.Authentication.Test
tokenStore.WriteToken(uri, writeToken);
if ((readToken = tokenStore.ReadToken(uri)) != null)
{
Assert.AreEqual(writeToken.Value, readToken.Value, "Token values did not match between written and read");
Assert.AreEqual(writeToken.Type, readToken.Type, "Token types did not mathc between written and read");
}
else
{
Assert.Fail("Failed to read token");
}
readToken = tokenStore.ReadToken(uri);
Assert.NotNull(readToken);
Assert.Equal(writeToken.Value, readToken.Value);
Assert.Equal(writeToken.Type, readToken.Type);
tokenStore.DeleteToken(uri);
Assert.IsNull(readToken = tokenStore.ReadToken(uri), "Deleted token was read back");
Assert.Null(readToken = tokenStore.ReadToken(uri));
}
}
}

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

@ -1,15 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.18.0.0" newVersion="2.18.0.0" />
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.18.0.0" newVersion="2.18.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
</configuration>

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

@ -1,5 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.13.1" targetFramework="net452" />
<package id="Microsoft.Net.Compilers" version="2.0.1" targetFramework="net452" developmentDependency="true" />
</packages>
<package id="Castle.Core" version="4.1.0" targetFramework="net452" />
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net452" developmentDependency="true" />
<package id="Moq" version="4.7.63" targetFramework="net452" />
<package id="xunit" version="2.2.0" targetFramework="net452" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net452" />
<package id="xunit.assert" version="2.2.0" targetFramework="net452" />
<package id="xunit.core" version="2.2.0" targetFramework="net452" />
<package id="xunit.extensibility.core" version="2.2.0" targetFramework="net452" />
<package id="xunit.extensibility.execution" version="2.2.0" targetFramework="net452" />
<package id="xunit.runner.visualstudio" version="2.2.0" targetFramework="net452" developmentDependency="true" />
</packages>

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

@ -0,0 +1,6 @@
{
"appDomain": "denied",
"diagnosticMessages": true,
"methodDisplay": "method",
"parallelizeAssembly": true
}

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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<ProjectGuid>{19770407-B493-459D-BB4F-04FBEFB1BA13}</ProjectGuid>
@ -88,7 +88,7 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

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

@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.13.1" targetFramework="net451" />
<package id="Microsoft.Net.Compilers" version="2.0.1" targetFramework="net451" developmentDependency="true" />
<package id="MSBuildTasks" version="1.5.0.196" targetFramework="net451" developmentDependency="true" />
</packages>
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net451" developmentDependency="true" />
</packages>

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

@ -1,60 +1,45 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Microsoft.Alm.Git.Test
{
/// <summary>
/// A class to test <see cref="Configuration"/>.
/// </summary>
[TestClass]
public class ConfigurationTests
{
[TestMethod]
public void ParseGitConfigSimple()
public static object[] ParseData
{
const string input = @"
[core]
autocrlf = false
";
get
{
var data = new List<object[]>()
{
new object[] { "\n[core]\n autocrlf = false\n", "core.autocrlf", "false", StringComparer.OrdinalIgnoreCase },
new object[] { "\n[core]\n autocrlf = true\n autocrlf = ThisShouldBeInvalidButIgnored\n autocrlf = false\n", "core.autocrlf", "false", StringComparer.OrdinalIgnoreCase },
new object[] { "\n[core \"oneQuote]\n autocrlf = \"false\n", "core.oneQuote.autocrlf", "false", StringComparer.OrdinalIgnoreCase },
};
var values = TestParseGitConfig(input);
Assert.AreEqual("false", values["core.autocrlf"]);
return data.ToArray();
}
}
[TestMethod]
public void ParseGitConfigOverwritesValues()
[Theory]
[MemberData(nameof(ParseData))]
public void GitConfif_Parse(string input, string expectedName, string expected, StringComparer comparer)
{
const string input = @"
[core]
autocrlf = true
autocrlf = ThisShouldBeInvalidButIgnored
autocrlf = false
";
var values = TestParseGitConfig(input);
Assert.NotNull(values);
Assert.AreEqual("false", values["core.autocrlf"]);
Assert.Equal(expected, values[expectedName], comparer);
}
[TestMethod]
public void ParseGitConfigPartiallyQuoted()
{
const string input = @"
[core ""oneQuote]
autocrlf = ""false
";
var values = TestParseGitConfig(input);
Assert.AreEqual("false", values["core.oneQuote.autocrlf"]);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
[TestMethod]
public void ParseGitConfigSampleFile()
[Fact]
public void GitConfig_ParseSampleFile()
{
var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var me = this.GetType();
@ -66,24 +51,13 @@ namespace Microsoft.Alm.Git.Test
Configuration.ParseGitConfig(sr, values);
}
Assert.AreEqual(36, values.Count);
Assert.AreEqual("\\\"C:/Utils/Compare It!/wincmp3.exe\\\" \\\"$(cygpath -w \\\"$LOCAL\\\")\\\" \\\"$(cygpath -w \\\"$REMOTE\\\")\\\"", values["difftool.cygcompareit.cmd"], "The quotes remained.");
Assert.AreEqual("!f() { git fetch origin && git checkout -b $1 origin/master --no-track; }; f", values["alias.cob"], "The quotes were stripped.");
Assert.Equal(36, values.Count);
Assert.Equal("\\\"C:/Utils/Compare It!/wincmp3.exe\\\" \\\"$(cygpath -w \\\"$LOCAL\\\")\\\" \\\"$(cygpath -w \\\"$REMOTE\\\")\\\"", values["difftool.cygcompareit.cmd"], StringComparer.OrdinalIgnoreCase);
Assert.Equal("!f() { git fetch origin && git checkout -b $1 origin/master --no-track; }; f", values["alias.cob"], StringComparer.OrdinalIgnoreCase);
}
private static Dictionary<string, string> TestParseGitConfig(string input)
{
var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
using (var sr = new StringReader(input))
{
Configuration.ParseGitConfig(sr, values);
}
return values;
}
[TestMethod]
public void ReadThroughPublicMethods()
[Fact]
public void GitConfig_ReadThrough()
{
const string input = "\n" +
"[core]\n" +
@ -114,21 +88,32 @@ namespace Microsoft.Alm.Git.Test
cut = new Configuration.Impl(values);
}
Assert.AreEqual(true, cut.ContainsKey("CoRe.AuToCrLf"));
Assert.AreEqual("false", cut["CoRe.AuToCrLf"]);
Assert.True(cut.ContainsKey("CoRe.AuToCrLf"));
Assert.Equal("false", cut["CoRe.AuToCrLf"], StringComparer.OrdinalIgnoreCase);
Configuration.Entry entry;
Assert.AreEqual(true, cut.TryGetEntry("core", (string)null, "autocrlf", out entry));
Assert.AreEqual("false", entry.Value);
Assert.True(cut.TryGetEntry("core", (string)null, "autocrlf", out entry));
Assert.Equal("false", entry.Value, StringComparer.OrdinalIgnoreCase);
Assert.AreEqual(true, cut.TryGetEntry("credential", new Uri("https://microsoft.visualstudio.com"), "authority", out entry));
Assert.AreEqual("AAD", entry.Value);
Assert.True(cut.TryGetEntry("credential", new Uri("https://microsoft.visualstudio.com"), "authority", out entry));
Assert.Equal("AAD", entry.Value, StringComparer.OrdinalIgnoreCase);
Assert.AreEqual(true, cut.TryGetEntry("credential", new Uri("https://mseng.visualstudio.com"), "authority", out entry));
Assert.AreEqual("MSA", entry.Value);
Assert.True(cut.TryGetEntry("credential", new Uri("https://mseng.visualstudio.com"), "authority", out entry));
Assert.Equal("MSA", entry.Value, StringComparer.OrdinalIgnoreCase);
Assert.AreEqual(true, cut.TryGetEntry("credential", new Uri("https://ntlm.visualstudio.com"), "authority", out entry));
Assert.AreEqual("NTLM", entry.Value);
Assert.True(cut.TryGetEntry("credential", new Uri("https://ntlm.visualstudio.com"), "authority", out entry));
Assert.Equal("NTLM", entry.Value, StringComparer.OrdinalIgnoreCase);
}
private static Dictionary<string, string> TestParseGitConfig(string input)
{
var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
using (var sr = new StringReader(input))
{
Configuration.ParseGitConfig(sr, values);
}
return values;
}
}
}

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

@ -1,18 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Microsoft.Alm.Git.Test
{
/// <summary>
/// A class to test <see cref="GitInstallation"/>.
/// </summary>
[TestClass]
public class GitInstallationTests
{
[TestMethod]
public void CaseInsensitiveComparison()
[Fact]
public void GitInstallation_CaseInsensitiveComparison()
{
List<GitInstallation> list = new List<GitInstallation>
{
@ -37,27 +36,27 @@ namespace Microsoft.Alm.Git.Test
HashSet<GitInstallation> set = new HashSet<GitInstallation>(list);
Assert.AreEqual(15, list.Count);
Assert.AreEqual(5, set.Count);
Assert.Equal(15, list.Count);
Assert.Equal(5, set.Count);
Assert.AreEqual(6, list.Where(x => x.Version == KnownGitDistribution.GitForWindows32v1).Count());
Assert.AreEqual(6, list.Where(x => x.Version == KnownGitDistribution.GitForWindows32v2).Count());
Assert.AreEqual(3, list.Where(x => x.Version == KnownGitDistribution.GitForWindows64v2).Count());
Assert.Equal(6, list.Where(x => x.Version == KnownGitDistribution.GitForWindows32v1).Count());
Assert.Equal(6, list.Where(x => x.Version == KnownGitDistribution.GitForWindows32v2).Count());
Assert.Equal(3, list.Where(x => x.Version == KnownGitDistribution.GitForWindows64v2).Count());
Assert.AreEqual(2, set.Where(x => x.Version == KnownGitDistribution.GitForWindows32v1).Count());
Assert.AreEqual(2, set.Where(x => x.Version == KnownGitDistribution.GitForWindows32v2).Count());
Assert.AreEqual(1, set.Where(x => x.Version == KnownGitDistribution.GitForWindows64v2).Count());
Assert.Equal(2, set.Where(x => x.Version == KnownGitDistribution.GitForWindows32v1).Count());
Assert.Equal(2, set.Where(x => x.Version == KnownGitDistribution.GitForWindows32v2).Count());
Assert.Equal(1, set.Where(x => x.Version == KnownGitDistribution.GitForWindows64v2).Count());
foreach (var v in Enum.GetValues(typeof(KnownGitDistribution)))
{
KnownGitDistribution kgd = (KnownGitDistribution)v;
var a = list.Where(x => x.Version == kgd);
Assert.IsTrue(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Cmd, a.First().Cmd)));
Assert.IsTrue(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Config, a.First().Config)));
Assert.IsTrue(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Git, a.First().Git)));
Assert.IsTrue(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Libexec, a.First().Libexec)));
Assert.IsTrue(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Sh, a.First().Sh)));
Assert.True(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Cmd, a.First().Cmd)));
Assert.True(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Config, a.First().Config)));
Assert.True(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Git, a.First().Git)));
Assert.True(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Libexec, a.First().Libexec)));
Assert.True(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Sh, a.First().Sh)));
}
}
}

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

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -9,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Alm.Git.Test</RootNamespace>
<AssemblyName>Microsoft.Alm.Git.Test</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
@ -45,22 +46,30 @@
<CodeAnalysisRuleSet>..\analysisRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.1.0\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.7.63.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.7.63\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework">
<Private>False</Private>
</Reference>
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="ConfigurationTests.cs" />
<Compile Include="GitInstallationTests.cs" />
@ -79,32 +88,18 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="xunit.runner.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

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

@ -1,45 +1,59 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Microsoft.Alm.Git.Test
{
[TestClass]
public class WhereTests
{
private static StringComparer PathComparer = StringComparer.InvariantCultureIgnoreCase;
[TestMethod]
public void FindApp()
public static object[] FindAppData
{
string[] apps = new[] { "cmd", "notepad", "calc", "powershell", "git" };
foreach (string app in apps)
get
{
string path1;
Assert.IsTrue(CmdWhere(app, out path1));
string path2;
Assert.IsTrue(Where.FindApp(app, out path2));
var data = new List<object[]>()
{
new object[] { "cmd" },
new object[] { "notepad" },
new object[] { "calc" },
new object[] { "powershell" },
new object[] { "git" },
};
Assert.IsTrue(PathComparer.Equals(path1, path2));
return data.ToArray();
}
}
[TestMethod]
public void FindGit()
[Theory]
[MemberData(nameof(FindAppData))]
public void Where_FindApp(string app)
{
string path1;
Assert.True(CmdWhere(app, out path1));
string path2;
Assert.True(Where.FindApp(app, out path2));
Assert.True(PathComparer.Equals(path1, path2));
}
[Fact]
public void Where_FindGit()
{
string gitPath;
if (!Where.FindApp("git", out gitPath))
Assert.Inconclusive();
throw new Exception("Git not found on system");
List<GitInstallation> installations;
Assert.IsTrue(Where.FindGitInstallations(out installations));
Assert.IsTrue(installations.Count > 0);
Assert.IsTrue(PathComparer.Equals(installations[0].Git, gitPath));
Assert.True(Where.FindGitInstallations(out installations));
Assert.True(installations.Count > 0);
Assert.True(PathComparer.Equals(installations[0].Git, gitPath));
GitInstallation installation;
Assert.IsTrue(Where.FindGitInstallation(installations[0].Path, installations[0].Version, out installation));
Assert.IsTrue(installations[0] == installation);
Assert.True(Where.FindGitInstallation(installations[0].Path, installations[0].Version, out installation));
Assert.True(installations[0] == installation);
}
private static bool CmdWhere(string app, out string path)

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

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="xunit.longRunningTestSeconds" value="2.0"/>
<add key="xunit.maxParallelThreads" value="0"/>
<add key="xunit.methodDisplay" value="method"/>
<add key="xunit.parallelizeAssembly" value="false"/>
<add key="xunit.parallelizeTestCollections" value="true"/>
<add key="xunit.preEnumerateTheories" value="true"/>
</appSettings>
</configuration>

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

@ -1,4 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="2.0.1" targetFramework="net452" developmentDependency="true" />
</packages>
<package id="Castle.Core" version="4.1.0" targetFramework="net452" />
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net452" developmentDependency="true" />
<package id="Moq" version="4.7.63" targetFramework="net452" />
<package id="xunit" version="2.2.0" targetFramework="net452" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net452" />
<package id="xunit.assert" version="2.2.0" targetFramework="net452" />
<package id="xunit.core" version="2.2.0" targetFramework="net452" />
<package id="xunit.extensibility.core" version="2.2.0" targetFramework="net452" />
<package id="xunit.extensibility.execution" version="2.2.0" targetFramework="net452" />
<package id="xunit.runner.visualstudio" version="2.2.0" targetFramework="net452" developmentDependency="true" />
</packages>

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

@ -0,0 +1,7 @@
{
"appDomain": "denied",
"diagnosticMessages": true,
"methodDisplay": "method",
"parallelizeAssembly": true,
"preEnumerateTheories": true
}

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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<ProjectGuid>{19770407-5C58-406D-AB3F-3700BB0D06FE}</ProjectGuid>
@ -69,7 +69,7 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

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

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="2.0.1" targetFramework="net451" developmentDependency="true" />
</packages>
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net451" developmentDependency="true" />
</packages>

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

@ -1,6 +1,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Microsoft.Alm.Authentication.Test
{
@ -20,7 +20,7 @@ namespace Microsoft.Alm.Authentication.Test
public async Task<Token> InteractiveAcquireToken(TargetUri targetUri, string clientId, string resource, Uri redirectUri, string queryParameters = null)
{
Assert.AreEqual(this.ExpectedQueryParameters, queryParameters);
Assert.Equal(this.ExpectedQueryParameters, queryParameters);
return await Task.Run(() => { return new Token("token-access", TokenType.Access); });
}

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

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -9,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Alm.Authentication.Test</RootNamespace>
<AssemblyName>Microsoft.Vsts.Authentication.Test</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
@ -39,20 +40,27 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.1.0\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.7.63.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.7.63\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="AuthenticationTests.cs" />
<Compile Include="AuthorityFake.cs" />
@ -78,31 +86,14 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

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

@ -1,16 +1,15 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Microsoft.Alm.Authentication.Test
{
[TestClass]
public class VstsAadTests: AuthenticationTests
{
public VstsAadTests()
: base()
{ }
[TestMethod]
[Fact]
public void VstsAadDeleteCredentialsTest()
{
TargetUri targetUri = DefaultTargetUri;
@ -19,50 +18,50 @@ namespace Microsoft.Alm.Authentication.Test
aadAuthentication.PersonalAccessTokenStore.WriteCredentials(targetUri, DefaultPersonalAccessToken);
aadAuthentication.DeleteCredentials(targetUri);
Assert.IsNull(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri), "Personal Access Tokens were not deleted as expected");
Assert.Null(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri));
aadAuthentication.DeleteCredentials(targetUri);
Assert.IsNull(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri), "Personal Access Tokens were not deleted as expected");
Assert.Null(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri));
}
[TestMethod]
[Fact]
public void VstsAadGetCredentialsTest()
{
TargetUri targetUri = DefaultTargetUri;
VstsAadAuthentication aadAuthentication = GetVstsAadAuthentication("aad-get");
Assert.IsNull(aadAuthentication.GetCredentials(targetUri), "Credentials were retrieved unexpectedly.");
Assert.Null(aadAuthentication.GetCredentials(targetUri));
aadAuthentication.PersonalAccessTokenStore.WriteCredentials(targetUri, DefaultPersonalAccessToken);
Assert.IsNotNull(aadAuthentication.GetCredentials(targetUri), "Credentials were not retrieved as expected.");
Assert.NotNull(aadAuthentication.GetCredentials(targetUri));
}
[TestMethod]
[Fact]
public void VstsAadInteractiveLogonTest()
{
TargetUri targetUri = DefaultTargetUri;
VstsAadAuthentication aadAuthentication = GetVstsAadAuthentication("aad-logon");
Assert.IsNull(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri), "Personal Access Token found in store unexpectedly.");
Assert.Null(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri));
Assert.IsNotNull(aadAuthentication.InteractiveLogon(targetUri, false).Result, "Interactive logon failed unexpectedly.");
Assert.NotNull(aadAuthentication.InteractiveLogon(targetUri, false).Result);
Assert.IsNotNull(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri), "Personal Access Token not found in store as expected.");
Assert.NotNull(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri));
}
[TestMethod]
[Fact]
public void VstsAadNoninteractiveLogonTest()
{
TargetUri targetUri = DefaultTargetUri;
VstsAadAuthentication aadAuthentication = GetVstsAadAuthentication("aad-noninteractive");
Assert.IsNotNull(Task.Run(async () => { return await aadAuthentication.NoninteractiveLogon(targetUri, false); }).Result, "Non-interactive logon unexpectedly failed.");
Assert.NotNull(Task.Run(async () => { return await aadAuthentication.NoninteractiveLogon(targetUri, false); }).Result);
Assert.IsNotNull(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri), "Personal Access Token not found in store as expected.");
Assert.NotNull(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri));
}
[TestMethod]
[Fact]
public void VstsAadSetCredentialsTest()
{
TargetUri targetUri = DefaultTargetUri;
@ -71,32 +70,32 @@ namespace Microsoft.Alm.Authentication.Test
aadAuthentication.SetCredentials(targetUri, credentials);
Assert.IsNull(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri), "Personal Access Token unexpectedly found in store.");
Assert.IsNull(credentials = aadAuthentication.GetCredentials(targetUri), "Credentials were retrieved unexpectedly.");
Assert.Null(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri));
Assert.Null(credentials = aadAuthentication.GetCredentials(targetUri));
}
[TestMethod]
[Fact]
public void VstsAadValidateCredentialsTest()
{
VstsAadAuthentication aadAuthentication = GetVstsAadAuthentication("aad-validate");
Credential credentials = null;
Assert.IsFalse(Task.Run(async () => { return await aadAuthentication.ValidateCredentials(DefaultTargetUri, credentials); }).Result, "Credential validation unexpectedly failed.");
Assert.False(Task.Run(async () => { return await aadAuthentication.ValidateCredentials(DefaultTargetUri, credentials); }).Result, "Credential validation unexpectedly failed.");
credentials = DefaultCredentials;
Assert.IsTrue(Task.Run(async () => { return await aadAuthentication.ValidateCredentials(DefaultTargetUri, credentials); }).Result, "Credential validation unexpectedly failed.");
Assert.True(Task.Run(async () => { return await aadAuthentication.ValidateCredentials(DefaultTargetUri, credentials); }).Result, "Credential validation unexpectedly failed.");
}
[TestMethod]
[Fact]
public void VstsAadValidateLoginHintTest()
{
TargetUri targetUri = DefaultTargetUri;
VstsAadAuthentication aadAuthentication = GetVstsAadAuthentication("aad-loginhint");
Assert.IsNotNull(Task.Run(async () => { return await aadAuthentication.NoninteractiveLogon(targetUri, false); }).Result, "Non-interactive logon unexpectedly failed.");
Assert.NotNull(Task.Run(async () => { return await aadAuthentication.NoninteractiveLogon(targetUri, false); }).Result);
Assert.IsNotNull(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri), "Personal Access Token not found in store as expected.");
Assert.NotNull(aadAuthentication.PersonalAccessTokenStore.ReadCredentials(targetUri));
}
private static VstsAadAuthentication GetVstsAadAuthentication(string @namespace)

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

@ -1,16 +1,15 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Microsoft.Alm.Authentication.Test
{
[TestClass]
public class VstsMsaTests: AuthenticationTests
{
public VstsMsaTests()
: base()
{ }
[TestMethod]
[Fact]
public void VstsMsaDeleteCredentialsTest()
{
TargetUri targetUri = DefaultTargetUri;
@ -19,65 +18,60 @@ namespace Microsoft.Alm.Authentication.Test
msaAuthority.PersonalAccessTokenStore.WriteCredentials(targetUri, DefaultPersonalAccessToken);
msaAuthority.DeleteCredentials(targetUri);
Assert.IsNull(msaAuthority.PersonalAccessTokenStore.ReadCredentials(targetUri), "Personal Access Tokens were not deleted as expected"); ;
Assert.Null(msaAuthority.PersonalAccessTokenStore.ReadCredentials(targetUri));
msaAuthority.DeleteCredentials(targetUri);
Assert.IsNull(msaAuthority.PersonalAccessTokenStore.ReadCredentials(targetUri), "Personal Access Tokens were not deleted as expected"); ;
Assert.Null(msaAuthority.PersonalAccessTokenStore.ReadCredentials(targetUri));
}
[TestMethod]
[Fact]
public void VstsMsaGetCredentialsTest()
{
TargetUri targetUri = DefaultTargetUri;
VstsMsaAuthentication msaAuthority = GetVstsMsaAuthentication("msa-get");
Assert.IsNull(msaAuthority.GetCredentials(targetUri), "Credentials were retrieved unexpectedly.");
Assert.Null(msaAuthority.GetCredentials(targetUri));
msaAuthority.PersonalAccessTokenStore.WriteCredentials(targetUri, DefaultPersonalAccessToken);
Assert.IsNotNull(msaAuthority.GetCredentials(targetUri), "Credentials were not retrieved as expected.");
Assert.NotNull(msaAuthority.GetCredentials(targetUri));
}
[TestMethod]
[Fact]
public void VstsMsaInteractiveLogonTest()
{
TargetUri targetUri = DefaultTargetUri;
VstsMsaAuthentication msaAuthority = GetVstsMsaAuthentication("msa-logon");
Assert.IsNull(msaAuthority.PersonalAccessTokenStore.ReadCredentials(targetUri), "Personal Access Token found in store unexpectedly.");
Assert.Null(msaAuthority.PersonalAccessTokenStore.ReadCredentials(targetUri));
Assert.IsNotNull(msaAuthority.InteractiveLogon(targetUri, false).Result, "Interactive logon failed unexpectedly.");
Assert.NotNull(msaAuthority.InteractiveLogon(targetUri, false).Result);
Assert.IsNotNull(msaAuthority.PersonalAccessTokenStore.ReadCredentials(targetUri), "Personal Access Token not found in store as expected.");
Assert.NotNull(msaAuthority.PersonalAccessTokenStore.ReadCredentials(targetUri));
}
[TestMethod]
[Fact]
public void VstsMsaSetCredentialsTest()
{
TargetUri targetUri = DefaultTargetUri;
VstsMsaAuthentication msaAuthority = GetVstsMsaAuthentication("msa-set");
try
{
msaAuthority.SetCredentials(targetUri, DefaultCredentials);
Assert.Fail("Credentials were unexpectedly set.");
}
catch { }
msaAuthority.SetCredentials(targetUri, DefaultCredentials);
Assert.IsNull(msaAuthority.PersonalAccessTokenStore.ReadCredentials(targetUri), "Personal Access Token unexpectedly found in store.");
Assert.Null(msaAuthority.PersonalAccessTokenStore.ReadCredentials(targetUri));
}
[TestMethod]
[Fact]
public void VstsMsaValidateCredentialsTest()
{
VstsMsaAuthentication msaAuthority = GetVstsMsaAuthentication("msa-validate");
Credential credentials = null;
Assert.IsFalse(Task.Run(async () => { return await msaAuthority.ValidateCredentials(DefaultTargetUri, credentials); }).Result, "Credential validation unexpectedly failed.");
Assert.False(Task.Run(async () => { return await msaAuthority.ValidateCredentials(DefaultTargetUri, credentials); }).Result, "Credential validation unexpectedly failed.");
credentials = DefaultCredentials;
Assert.IsTrue(Task.Run(async () => { return await msaAuthority.ValidateCredentials(DefaultTargetUri, credentials); }).Result, "Credential validation unexpectedly failed.");
Assert.True(Task.Run(async () => { return await msaAuthority.ValidateCredentials(DefaultTargetUri, credentials); }).Result, "Credential validation unexpectedly failed.");
}
private static VstsMsaAuthentication GetVstsMsaAuthentication(string @namespace)

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

@ -1,59 +1,58 @@
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Microsoft.Alm.Authentication.Test
{
[TestClass]
public class VstsTokenScopeTests
{
[TestMethod]
[Fact]
public void AddOperator()
{
var val = VstsTokenScope.BuildAccess + VstsTokenScope.TestRead;
Assert.AreEqual(val.Value, VstsTokenScope.BuildAccess.Value + " " + VstsTokenScope.TestRead.Value);
Assert.Equal(val.Value, VstsTokenScope.BuildAccess.Value + " " + VstsTokenScope.TestRead.Value);
val += VstsTokenScope.ProfileRead;
Assert.AreEqual(val.Value, VstsTokenScope.BuildAccess.Value + " " + VstsTokenScope.TestRead.Value + " " + VstsTokenScope.ProfileRead);
Assert.Equal(val.Value, VstsTokenScope.BuildAccess.Value + " " + VstsTokenScope.TestRead.Value + " " + VstsTokenScope.ProfileRead);
}
[TestMethod]
[Fact]
public void AndOperator()
{
var val = (VstsTokenScope.BuildAccess & VstsTokenScope.BuildAccess);
Assert.AreEqual(VstsTokenScope.BuildAccess, val);
Assert.Equal(VstsTokenScope.BuildAccess, val);
val = VstsTokenScope.ProfileRead + VstsTokenScope.PackagingWrite + VstsTokenScope.BuildAccess;
Assert.IsTrue((val & VstsTokenScope.ProfileRead) == VstsTokenScope.ProfileRead);
Assert.IsTrue((val & VstsTokenScope.PackagingWrite) == VstsTokenScope.PackagingWrite);
Assert.IsTrue((val & VstsTokenScope.BuildAccess) == VstsTokenScope.BuildAccess);
Assert.IsFalse((val & VstsTokenScope.PackagingManage) == VstsTokenScope.PackagingManage);
Assert.IsTrue((val & VstsTokenScope.PackagingManage) == VstsTokenScope.None);
Assert.True((val & VstsTokenScope.ProfileRead) == VstsTokenScope.ProfileRead);
Assert.True((val & VstsTokenScope.PackagingWrite) == VstsTokenScope.PackagingWrite);
Assert.True((val & VstsTokenScope.BuildAccess) == VstsTokenScope.BuildAccess);
Assert.False((val & VstsTokenScope.PackagingManage) == VstsTokenScope.PackagingManage);
Assert.True((val & VstsTokenScope.PackagingManage) == VstsTokenScope.None);
}
[TestMethod]
[Fact]
public void Equality()
{
Assert.AreEqual(VstsTokenScope.CodeWrite, VstsTokenScope.CodeWrite);
Assert.AreEqual(VstsTokenScope.None, VstsTokenScope.None);
Assert.Equal(VstsTokenScope.CodeWrite, VstsTokenScope.CodeWrite);
Assert.Equal(VstsTokenScope.None, VstsTokenScope.None);
Assert.AreNotEqual(VstsTokenScope.BuildAccess, VstsTokenScope.CodeRead);
Assert.AreNotEqual(VstsTokenScope.BuildAccess, VstsTokenScope.None);
Assert.NotEqual(VstsTokenScope.BuildAccess, VstsTokenScope.CodeRead);
Assert.NotEqual(VstsTokenScope.BuildAccess, VstsTokenScope.None);
Assert.AreEqual(VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead | VstsTokenScope.PackagingWrite, VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead | VstsTokenScope.PackagingWrite);
Assert.AreEqual(VstsTokenScope.PackagingWrite | VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead, VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead | VstsTokenScope.PackagingWrite);
Assert.Equal(VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead | VstsTokenScope.PackagingWrite, VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead | VstsTokenScope.PackagingWrite);
Assert.Equal(VstsTokenScope.PackagingWrite | VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead, VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead | VstsTokenScope.PackagingWrite);
Assert.AreNotEqual(VstsTokenScope.PackagingManage | VstsTokenScope.ServiceHookRead | VstsTokenScope.PackagingWrite, VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead | VstsTokenScope.PackagingWrite);
Assert.AreNotEqual(VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead | VstsTokenScope.PackagingWrite, VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead);
Assert.NotEqual(VstsTokenScope.PackagingManage | VstsTokenScope.ServiceHookRead | VstsTokenScope.PackagingWrite, VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead | VstsTokenScope.PackagingWrite);
Assert.NotEqual(VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead | VstsTokenScope.PackagingWrite, VstsTokenScope.PackagingManage | VstsTokenScope.PackagingRead);
}
[TestMethod]
[Fact]
public void HashCode()
{
HashSet<int> hashCodes = new HashSet<int>();
foreach (var item in VstsTokenScope.EnumerateValues())
{
Assert.IsTrue(hashCodes.Add(item.GetHashCode()));
Assert.True(hashCodes.Add(item.GetHashCode()));
}
int loop1 = 0;
@ -65,11 +64,11 @@ namespace Microsoft.Alm.Authentication.Test
{
if (loop1 < loop2)
{
Assert.IsTrue(hashCodes.Add((item1 | item2).GetHashCode()));
Assert.True(hashCodes.Add((item1 | item2).GetHashCode()));
}
else
{
Assert.IsFalse(hashCodes.Add((item1 | item2).GetHashCode()));
Assert.False(hashCodes.Add((item1 | item2).GetHashCode()));
}
loop2++;
@ -79,48 +78,48 @@ namespace Microsoft.Alm.Authentication.Test
}
}
[TestMethod]
[Fact]
public void OrOperator()
{
var val1 = (VstsTokenScope.BuildAccess | VstsTokenScope.BuildAccess);
Assert.AreEqual(VstsTokenScope.BuildAccess, val1);
Assert.Equal(VstsTokenScope.BuildAccess, val1);
val1 = VstsTokenScope.ProfileRead + VstsTokenScope.PackagingWrite + VstsTokenScope.BuildAccess;
var val2 = val1 | VstsTokenScope.ProfileRead;
Assert.AreEqual(val1, val2);
Assert.Equal(val1, val2);
val2 = VstsTokenScope.ProfileRead | VstsTokenScope.PackagingWrite | VstsTokenScope.BuildAccess;
Assert.AreEqual(val1, val2);
Assert.IsTrue((val2 & VstsTokenScope.ProfileRead) == VstsTokenScope.ProfileRead);
Assert.IsTrue((val2 & VstsTokenScope.PackagingWrite) == VstsTokenScope.PackagingWrite);
Assert.IsTrue((val2 & VstsTokenScope.BuildAccess) == VstsTokenScope.BuildAccess);
Assert.IsFalse((val2 & VstsTokenScope.PackagingManage) == VstsTokenScope.PackagingManage);
Assert.Equal(val1, val2);
Assert.True((val2 & VstsTokenScope.ProfileRead) == VstsTokenScope.ProfileRead);
Assert.True((val2 & VstsTokenScope.PackagingWrite) == VstsTokenScope.PackagingWrite);
Assert.True((val2 & VstsTokenScope.BuildAccess) == VstsTokenScope.BuildAccess);
Assert.False((val2 & VstsTokenScope.PackagingManage) == VstsTokenScope.PackagingManage);
}
[TestMethod]
[Fact]
public void MinusOperator()
{
var val1 = VstsTokenScope.BuildAccess | VstsTokenScope.BuildExecute | VstsTokenScope.ChatWrite;
var val2 = val1 - VstsTokenScope.ChatWrite;
Assert.AreEqual(val2, VstsTokenScope.BuildAccess | VstsTokenScope.BuildExecute);
Assert.Equal(val2, VstsTokenScope.BuildAccess | VstsTokenScope.BuildExecute);
var val3 = val1 - val2;
Assert.AreEqual(val3, VstsTokenScope.ChatWrite);
Assert.Equal(val3, VstsTokenScope.ChatWrite);
var val4 = val3 - VstsTokenScope.ChatManage;
Assert.AreEqual(val3, val4);
Assert.Equal(val3, val4);
var val5 = (VstsTokenScope.BuildAccess + VstsTokenScope.BuildExecute) - (VstsTokenScope.BuildExecute | VstsTokenScope.CodeManage | VstsTokenScope.CodeWrite);
Assert.AreEqual(val5, VstsTokenScope.BuildAccess);
Assert.Equal(val5, VstsTokenScope.BuildAccess);
}
[TestMethod]
[Fact]
public void XorOperator()
{
var val1 = VstsTokenScope.ChatWrite + VstsTokenScope.CodeRead;
var val2 = VstsTokenScope.CodeRead + VstsTokenScope.PackagingRead;
var val3 = val1 ^ val2;
Assert.AreEqual(val3, VstsTokenScope.ChatWrite | VstsTokenScope.PackagingRead);
Assert.Equal(val3, VstsTokenScope.ChatWrite | VstsTokenScope.PackagingRead);
}
}
}

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

@ -1,4 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="2.0.1" targetFramework="net451" developmentDependency="true" />
</packages>
<package id="Castle.Core" version="4.1.0" targetFramework="net452" />
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net452" developmentDependency="true" />
<package id="Moq" version="4.7.63" targetFramework="net452" />
<package id="xunit" version="2.2.0" targetFramework="net452" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net452" />
<package id="xunit.assert" version="2.2.0" targetFramework="net452" />
<package id="xunit.core" version="2.2.0" targetFramework="net452" />
<package id="xunit.extensibility.core" version="2.2.0" targetFramework="net452" />
<package id="xunit.extensibility.execution" version="2.2.0" targetFramework="net452" />
<package id="xunit.runner.visualstudio" version="2.2.0" targetFramework="net451" developmentDependency="true" />
</packages>

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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<ProjectGuid>{19770407-D7D8-4A37-914C-F552FF4B90D4}</ProjectGuid>
@ -44,13 +44,11 @@
<CodeAnalysisRuleSet>..\analysisRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.13.8.999, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.13.9.1126, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.9\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.13.8.999, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.13.9.1126, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.9\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -93,7 +91,6 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- Produce a nuget package of this assembly -->
<Import Project="..\packages\MSBuildTasks.*\tools\MSBuild.Community.Tasks.Targets" />
<Import Project="..\packages\MSBuildTasks.1.5.0.196\build\MSBuildTasks.Targets" Condition="Exists('..\packages\MSBuildTasks.1.5.0.196\build\MSBuildTasks.Targets')" />
<PropertyGroup>
<In>$([System.IO.File]::ReadAllText('$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs'))</In>
<Pattern>^\s*\[assembly:\s*AssemblyVersion\s*\(\s*"\s*([^"]+)\s*"\s*\)</Pattern>
@ -124,7 +121,8 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSBuildTasks.1.5.0.196\build\MSBuildTasks.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSBuildTasks.1.5.0.196\build\MSBuildTasks.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.0.1\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<Import Project="..\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets" Condition="Exists('..\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets')" />
</Project>

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

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.13.8" targetFramework="net451" />
<package id="Microsoft.Net.Compilers" version="2.0.1" targetFramework="net451" developmentDependency="true" />
</packages>
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.13.9" targetFramework="net451" />
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net451" developmentDependency="true" />
<package id="MSBuildTasks" version="1.5.0.235" targetFramework="net452" developmentDependency="true" />
</packages>