Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop: (23 commits)
  Increased timeout
  Updated TestCaseSource syntax, related to NUnit3
  Avoid executing tests multiple times
  Enable all tests
  Execute only a subset of tests
  Send real time test results to AppVeyor
  Fixed test execution directory
  Updated test Nuget packages. Removed Fiddler usage and switch to nunit3
  Fixed some async UTs
  Style refactoring to match StyleCop guidelines
  - Replaced Upload(string filename, INode parent) signature to UploadFile(string filename, INode parent) - Used IProgress interface to report progression for async methods - Added MegaApiClient.ReportProgressChunkSize to customize the threshold between each progression report - Added new UTs for DownloadAsync/UploadAsync methods
  Used partial classes instead define to integrate async methods
  Fixed UT issue
  Updated nuspec file to include net45. Added UT for async methods
  #21 Renamed UT and fix it to support anonymous and authenticated modes
  Cleanup code after PR #26. Introduced IProgress<int>. Test project targets 4.5 now Removed Coverity configuration
  #21 Added method GetNodeFromLink to retrieve Name and Size from a public download link
  #28 Trim deserialized attributes to first null terminated character if any
  Bump 1.2.0
  Fixed async download progress reporting
  ...
  • Loading branch information
gpailler committed Feb 27, 2016
2 parents 4ea5481 + d3b3fe8 commit 827fe12
Show file tree
Hide file tree
Showing 39 changed files with 2,829 additions and 2,154 deletions.
15 changes: 4 additions & 11 deletions MegaApiClient-3.5/MegaApiClient-3.5.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\MegaApiClient.XML</DocumentationFile>
Expand All @@ -46,16 +46,6 @@
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Coverity|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Coverity\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\MegaApiClient.XML</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
Expand Down Expand Up @@ -85,6 +75,9 @@
<Compile Include="..\MegaApiClient\Extensions.cs">
<Link>Extensions.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\IMegaApiClient.cs">
<Link>IMegaApiClient.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\INode.cs">
<Link>INode.cs</Link>
</Compile>
Expand Down
17 changes: 5 additions & 12 deletions MegaApiClient-4.0/MegaApiClient-4.0.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<WarningLevel>1</WarningLevel>
<DocumentationFile>bin\Debug\MegaApiClient.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
Expand All @@ -46,16 +46,6 @@
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Coverity|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Coverity\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\MegaApiClient.XML</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
Expand Down Expand Up @@ -85,6 +75,9 @@
<Compile Include="..\MegaApiClient\Extensions.cs">
<Link>Extensions.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\IMegaApiClient.cs">
<Link>IMegaApiClient.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\INode.cs">
<Link>INode.cs</Link>
</Compile>
Expand Down
6 changes: 6 additions & 0 deletions MegaApiClient-4.5/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
126 changes: 126 additions & 0 deletions MegaApiClient-4.5/MegaApiClient-4.5.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.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>
<ProjectGuid>{19D28272-9DDB-4868-93E7-D98DCFAE08E9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CG.Web.MegaApiClient</RootNamespace>
<AssemblyName>MegaApiClient</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">.\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>1</WarningLevel>
<DocumentationFile>bin\Debug\MegaApiClient.XML</DocumentationFile>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\MegaApiClient.xml</DocumentationFile>
<NoWarn>1591</NoWarn>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<None Include="..\key.snk">
<Link>Properties\key.snk</Link>
</None>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\MegaApiClient\BigInteger.cs">
<Link>BigInteger.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\Crypto.cs">
<Link>Crypto.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\Exceptions.cs">
<Link>Exceptions.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\Extensions.cs">
<Link>Extensions.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\IMegaApiClient.cs">
<Link>IMegaApiClient.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\IMegaApiClientAsync.cs">
<Link>IMegaApiClientAsync.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\INode.cs">
<Link>INode.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\IWebClient.cs">
<Link>IWebClient.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\JsonSerialization.cs">
<Link>JsonSerialization.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\MegaAesCtrStream.cs">
<Link>MegaAesCtrStream.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\MegaApiClient.cs">
<Link>MegaApiClient.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\MegaApiClientAsync.cs">
<Link>MegaApiClientAsync.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\Node.cs">
<Link>Node.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\ProgressionStream.cs">
<Link>ProgressionStream.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\MegaApiClient\WebClient.cs">
<Link>WebClient.cs</Link>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
4 changes: 4 additions & 0 deletions MegaApiClient-4.5/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
</packages>
58 changes: 35 additions & 23 deletions MegaApiClient.Tests/DownloadUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Moq;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using NUnit.Framework.Interfaces;

namespace CG.Web.MegaApiClient.Tests
{
Expand All @@ -17,7 +18,7 @@ protected DownloadUpload(Options options)
{
}

[TestCaseSource("GetInvalidUploadStreamParameters")]
[TestCaseSource(typeof(DownloadUpload), nameof(GetInvalidUploadStreamParameters))]
public void UploadStream_InvalidParameters_Throws(Stream stream, string name, INode parent, IResolveConstraint constraint)
{
Assert.That(
Expand Down Expand Up @@ -64,11 +65,11 @@ public void UploadStream_ValidateContent_Succeeds(int dataSize)
var node = this.Client.Upload(stream, "test", parent);

stream.Position = 0;
this.AreStreamsEquals(this.Client.Download(node), stream);
this.AreStreamsEquivalent(this.Client.Download(node), stream);
}
}

[TestCaseSource("GetDownloadLinkInvalidParameter")]
[TestCaseSource(typeof(DownloadUpload), nameof(GetDownloadLinkInvalidParameter))]
public void DownloadLink_ToStream_InvalidParameter_Throws(Uri uri, IResolveConstraint constraint)
{
Assert.That(
Expand All @@ -81,7 +82,7 @@ public void DownloadLink_ToStream_Succeeds(string link, string expectedResultFil
{
using (Stream stream = new FileStream(expectedResultFile, FileMode.Open))
{
this.AreStreamsEquals(this.Client.Download(new Uri(link)), stream);
this.AreStreamsEquivalent(this.Client.Download(new Uri(link)), stream);
}
}

Expand All @@ -103,7 +104,7 @@ public void Download_ValidateStream_Succeeds(string link)
}
}

[TestCaseSource("GetDownloadLinkToFileInvalidParameter")]
[TestCaseSource(typeof(DownloadUpload), nameof(GetDownloadLinkToFileInvalidParameter))]
public void DownloadLink_ToFile_InvalidParameter_Throws(Uri uri, string outFile, IResolveConstraint constraint)
{
Assert.That(
Expand All @@ -123,7 +124,32 @@ public void DownloadLink_ToFile_Succeeds(string link, string expectedResultFile)
Is.EqualTo(File.ReadAllBytes(expectedResultFile)));
}

protected IEnumerable<TestCaseData> GetInvalidUploadStreamParameters()
protected void AreStreamsEquivalent(Stream stream1, Stream stream2)
{
byte[] stream1data = new byte[stream1.Length];
byte[] stream2data = new byte[stream2.Length];

int readStream1 = stream1.Read(stream1data, 0, stream1data.Length);
Assert.That(readStream1, Is.EqualTo(stream1data.Length));

int readStream2 = stream2.Read(stream2data, 0, stream2data.Length);
Assert.That(readStream2, Is.EqualTo(stream2data.Length));

Assert.That(stream1data, Is.EqualTo(stream2data));
}

protected void AreFileEquivalent(string file1, string file2)
{
using (Stream stream1 = new FileStream(file1, FileMode.Open))
{
using (Stream stream2 = new FileStream(file2, FileMode.Open))
{
this.AreStreamsEquivalent(stream1, stream2);
}
}
}

private static IEnumerable<TestCaseData> GetInvalidUploadStreamParameters()
{
INode nodeDirectory = Mock.Of<INode>(x => x.Type == NodeType.Directory);
INode nodeFile = Mock.Of<INode>(x => x.Type == NodeType.File);
Expand All @@ -143,7 +169,7 @@ protected IEnumerable<TestCaseData> GetInvalidUploadStreamParameters()
yield return new TestCaseData(stream, "name", nodeFile, Throws.TypeOf<ArgumentException>());
}

protected IEnumerable<ITestCaseData> GetDownloadLinkInvalidParameter()
private static IEnumerable<ITestCaseData> GetDownloadLinkInvalidParameter()
{
yield return new TestCaseData(null, Throws.TypeOf<ArgumentNullException>());
yield return new TestCaseData(new Uri("http://www.example.com"), Throws.TypeOf<ArgumentException>());
Expand All @@ -152,7 +178,7 @@ protected IEnumerable<ITestCaseData> GetDownloadLinkInvalidParameter()
yield return new TestCaseData(new Uri("https://mega.co.nz/#!axYS1TLL!"), Throws.TypeOf<ArgumentException>());
}

protected IEnumerable<ITestCaseData> GetDownloadLinkToFileInvalidParameter()
private static IEnumerable<ITestCaseData> GetDownloadLinkToFileInvalidParameter()
{
string outFile = Path.GetTempFileName();

Expand All @@ -165,22 +191,8 @@ protected IEnumerable<ITestCaseData> GetDownloadLinkToFileInvalidParameter()
yield return new TestCaseData(new Uri("https://mega.co.nz/#!axYS1TLL!GJNtvGJXjdD1YZYqTj5SXQ8HtFvfocoSrtBSdbgeSLM"), null, Throws.TypeOf<ArgumentNullException>());
yield return new TestCaseData(new Uri("https://mega.co.nz/#!axYS1TLL!GJNtvGJXjdD1YZYqTj5SXQ8HtFvfocoSrtBSdbgeSLM"), string.Empty, Throws.TypeOf<ArgumentNullException>());


yield return new TestCaseData(new Uri("https://mega.co.nz/#!axYS1TLL!GJNtvGJXjdD1YZYqTj5SXQ8HtFvfocoSrtBSdbgeSLM"), outFile, Throws.TypeOf<IOException>());
}

protected void AreStreamsEquals(Stream stream1, Stream stream2)
{
byte[] stream1data = new byte[stream1.Length];
byte[] stream2data = new byte[stream2.Length];

int readStream1 = stream1.Read(stream1data, 0, stream1data.Length);
Assert.That(readStream1, Is.EqualTo(stream1data.Length));

int readStream2 = stream2.Read(stream2data, 0, stream2data.Length);
Assert.That(readStream2, Is.EqualTo(stream2data.Length));

Assert.That(stream1data, Is.EqualTo(stream2data));
yield return new TestCaseData(new Uri("https://mega.co.nz/#!axYS1TLL!GJNtvGJXjdD1YZYqTj5SXQ8HtFvfocoSrtBSdbgeSLM"), outFile, Throws.TypeOf<IOException>());
}
}
}
18 changes: 12 additions & 6 deletions MegaApiClient.Tests/DownloadUploadAuthenticated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
using Moq;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using NUnit.Framework.Interfaces;

namespace CG.Web.MegaApiClient.Tests
{
[TestFixture]
public class DownloadUploadAuthenticated : DownloadUpload
{
public DownloadUploadAuthenticated()
: base(Options.LoginAuthenticated | Options.Clean)
: this(null)
{
}

protected DownloadUploadAuthenticated(Options? options)
: base(Options.LoginAuthenticated | Options.Clean | options.GetValueOrDefault())
{
}

Expand All @@ -26,12 +32,12 @@ public void DownloadNode_ToStream_Succeeds()
{
using (Stream expectedStream = new FileStream(ExpectedFile, FileMode.Open))
{
this.AreStreamsEquals(stream, expectedStream);
this.AreStreamsEquivalent(stream, expectedStream);
}
}
}

[TestCaseSource("GetGetDownloadLinkInvalidParameter")]
[TestCaseSource(typeof(DownloadUploadAuthenticated), nameof(GetGetDownloadLinkInvalidParameter))]
public void GetDownloadLink_InvalidNode_Throws(INode node, IResolveConstraint constraint)
{
Assert.That(
Expand All @@ -55,7 +61,7 @@ public void UploadStream_DownloadLink_Succeeds()
Uri uri = this.Client.GetDownloadLink(node);

stream.Position = 0;
this.AreStreamsEquals(this.Client.Download(uri), stream);
this.AreStreamsEquivalent(this.Client.Download(uri), stream);
}
}

Expand All @@ -69,10 +75,10 @@ public void DownloadLink_Succeeds(string expectedLink)
Is.EqualTo(new Uri(expectedLink)));
}

private IEnumerable<ITestCaseData> GetGetDownloadLinkInvalidParameter()
private static IEnumerable<ITestCaseData> GetGetDownloadLinkInvalidParameter()
{
yield return new TestCaseData(null, Throws.TypeOf<ArgumentNullException>());

foreach (NodeType nodeType in new[] { NodeType.Inbox, NodeType.Root, NodeType.Trash })
{
Mock<INode> nodeMock = new Mock<INode>();
Expand Down
Loading

0 comments on commit 827fe12

Please sign in to comment.