Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Little file upload refactoring for improved unit testing

  • Loading branch information...
commit 373063f5c7e824a38870b84e2df89a83392f436a 1 parent 0972db6
@MichaelPereira MichaelPereira authored
View
126 DropNet.Tests/DropNet.Tests.csproj
@@ -1,67 +1,73 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>
- </ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{06B6BC2F-94D5-456A-ABA7-F73FB28B4703}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>DropNet.Tests</RootNamespace>
- <AssemblyName>DropNet.Tests</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
- <Reference Include="System" />
- <Reference Include="System.Core">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- </ItemGroup>
- <ItemGroup>
- <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
- <Visible>False</Visible>
- </CodeAnalysisDependentAssemblyPaths>
- </ItemGroup>
- <ItemGroup>
- <Compile Include="FileTests.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="UserTests.cs" />
- <Compile Include="TestVariables.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\DropNet\DropNet.csproj">
- <Project>{E9580EFC-6014-4D3B-82A8-5F6D57213CE4}</Project>
- <Name>DropNet</Name>
- </ProjectReference>
- </ItemGroup>
- <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>
+ </ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{06B6BC2F-94D5-456A-ABA7-F73FB28B4703}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>DropNet.Tests</RootNamespace>
+ <AssemblyName>DropNet.Tests</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ <Reference Include="Moq">
+ <HintPath>..\Lib\Moq.dll</HintPath>
+ </Reference>
+ <Reference Include="Ploeh.AutoFixture">
+ <HintPath>..\Lib\Ploeh.AutoFixture.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="FileTests.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="UserTests.cs" />
+ <Compile Include="TestVariables.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\DropNet\DropNet.csproj">
+ <Project>{E9580EFC-6014-4D3B-82A8-5F6D57213CE4}</Project>
+ <Name>DropNet</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
- -->
+ -->
</Project>
View
25 DropNet.Tests/FileTests.cs
@@ -1,5 +1,7 @@
using System.IO;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+using Ploeh.AutoFixture;
namespace DropNet.Tests
{
@@ -9,14 +11,15 @@ namespace DropNet.Tests
[TestClass]
public class FileTests
{
- DropNetClient _client;
-
+ DropNetClient _client;
+ Fixture fixture;
public FileTests()
{
//
// TODO: Add constructor logic here
//
- _client = new DropNetClient(TestVariables.ApiKey, TestVariables.ApiSecret);
+ _client = new DropNetClient(TestVariables.ApiKey, TestVariables.ApiSecret);
+ fixture = new Fixture();
}
private TestContext testContextInstance;
@@ -85,9 +88,17 @@ public void Can_Get_File_And_Save()
[TestMethod]
public void Can_Upload_File()
{
- _client.Login(TestVariables.Email, TestVariables.Password);
- var localFile = new FileInfo("C:\\Temp\\Test.txt");
- var uploaded = _client.UploadFile("/", localFile);
+ _client.Login(TestVariables.Email, TestVariables.Password);
+
+ var localFile = new FileInfo(fixture.CreateAnonymous<string>());
+ var localContent = fixture.CreateAnonymous<string>();
+
+ File.WriteAllText(localFile.FullName, localContent, System.Text.Encoding.UTF8);
+ Assert.IsTrue(File.Exists(localFile.FullName));
+ byte[] content = _client.GetFileContentFromFS(localFile);
+ File.Delete(localFile.FullName);
+
+ var uploaded = _client.UploadFile("/", localFile.Name, content);
Assert.IsTrue(uploaded);
}
View
7 DropNet/Client/Files.Sync.cs
@@ -66,12 +66,11 @@ public byte[] GetFile(string path)
}
/// <summary>
- /// Uploads a File to Dropbox from the local file system to the specified folder
+ /// Retrieve the content of a file in the local file system
/// </summary>
- /// <param name="path">The path of the folder to upload to</param>
/// <param name="localFile">The local file to upload</param>
/// <returns>True on success</returns>
- public bool UploadFile(string path, FileInfo localFile)
+ public byte[] GetFileContentFromFS(FileInfo localFile)
{
//Get the file stream
byte[] bytes = null;
@@ -80,7 +79,7 @@ public bool UploadFile(string path, FileInfo localFile)
long numBytes = localFile.Length;
bytes = br.ReadBytes((int)numBytes);
- return UploadFile(path, localFile.Name, bytes);
+ return bytes;
}
/// <summary>
Please sign in to comment.
Something went wrong with that request. Please try again.