Merge pull request #289 from knocte/nunitSupport

Tests: add NUnit support
This commit is contained in:
Ilya Pirozhenko 2016-11-17 09:20:07 +03:00 committed by GitHub
commit 6b3c96eaa6
9 changed files with 384 additions and 63 deletions

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -8,14 +9,8 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TLSharp.Tests</RootNamespace>
<AssemblyName>TLSharp.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -38,18 +33,6 @@
<Reference Include="System" />
<Reference Include="System.Configuration" />
</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="TLSharpTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@ -73,25 +56,6 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</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" />
<!-- 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.

View file

@ -7,8 +7,6 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TeleSharp.TL;
using TeleSharp.TL.Messages;
using TLSharp.Core;
@ -17,7 +15,6 @@ using TLSharp.Core.Utils;
namespace TLSharp.Tests
{
[TestClass]
public class TLSharpTests
{
private string NumberToSendMessage { get; set; }
@ -40,9 +37,27 @@ namespace TLSharp.Tests
private int ApiId { get; set; }
[TestInitialize]
public void Init()
class Assert
{
static internal void IsNotNull(object obj)
{
IsNotNullHanlder(obj);
}
static internal void IsTrue(bool cond)
{
IsTrueHandler(cond);
}
}
internal static Action<object> IsNotNullHanlder;
internal static Action<bool> IsTrueHandler;
protected void Init(Action<object> notNullHandler, Action<bool> trueHandler)
{
IsNotNullHanlder = notNullHandler;
IsTrueHandler = trueHandler;
// Setup your API settings and phone numbers in app.config
GatherTestConfiguration();
}
@ -103,8 +118,7 @@ namespace TLSharp.Tests
Debug.WriteLine(appConfigMsgWarning, nameof(NumberToAddToChat));
}
[TestMethod]
public async Task AuthUser()
public virtual async Task AuthUser()
{
var client = NewClient();
@ -139,8 +153,7 @@ namespace TLSharp.Tests
Assert.IsTrue(client.IsUserAuthorized());
}
[TestMethod]
public async Task SendMessageTest()
public virtual async Task SendMessageTest()
{
NumberToSendMessage = ConfigurationManager.AppSettings[nameof(NumberToSendMessage)];
if (string.IsNullOrWhiteSpace(NumberToSendMessage))
@ -172,8 +185,7 @@ namespace TLSharp.Tests
await client.SendMessageAsync(new TLInputPeerUser() { user_id = user.id }, "TEST");
}
[TestMethod]
public async Task SendMessageToChannelTest()
public virtual async Task SendMessageToChannelTest()
{
var client = NewClient();
@ -188,8 +200,7 @@ namespace TLSharp.Tests
await client.SendMessageAsync(new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value }, "TEST MSG");
}
[TestMethod]
public async Task SendPhotoToContactTest()
public virtual async Task SendPhotoToContactTest()
{
var client = NewClient();
@ -206,8 +217,7 @@ namespace TLSharp.Tests
await client.SendUploadedPhoto(new TLInputPeerUser() { user_id = user.id }, fileResult, "kitty");
}
[TestMethod]
public async Task SendBigFileToContactTest()
public virtual async Task SendBigFileToContactTest()
{
var client = NewClient();
@ -230,8 +240,7 @@ namespace TLSharp.Tests
new TLVector<TLAbsDocumentAttribute>());
}
[TestMethod]
public async Task DownloadFileFromContactTest()
public virtual async Task DownloadFileFromContactTest()
{
var client = NewClient();
@ -269,9 +278,7 @@ namespace TLSharp.Tests
Assert.IsTrue(resFile.bytes.Length > 0);
}
[TestMethod]
public async Task DownloadFileFromWrongLocationTest()
public virtual async Task DownloadFileFromWrongLocationTest()
{
var client = NewClient();
@ -299,8 +306,7 @@ namespace TLSharp.Tests
Assert.IsTrue(resFile.bytes.Length > 0);
}
[TestMethod]
public async Task SignUpNewUser()
public virtual async Task SignUpNewUser()
{
var client = NewClient();
await client.ConnectAsync();
@ -316,8 +322,7 @@ namespace TLSharp.Tests
Assert.IsNotNull(loggedInUser);
}
[TestMethod]
public async Task CheckPhones()
public virtual async Task CheckPhones()
{
var client = NewClient();
await client.ConnectAsync();