Skip to content

Commit

Permalink
Initial import of test project with Get operation tests.
Browse files Browse the repository at this point in the history
Change-Id: I39a50070ae711c8d1a48db7d76157c6a356c12a1
  • Loading branch information
jzablocki committed Apr 23, 2012
1 parent 4508698 commit 46433cb
Show file tree
Hide file tree
Showing 11 changed files with 11,234 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/Couchbase.Tests/Couchbase.Tests.csproj
@@ -0,0 +1,71 @@
<?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>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B286E960-FC97-4ED5-97C1-BDB44DECD3A3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Couchbase.Tests</RootNamespace>
<AssemblyName>Couchbase.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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="nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CouchbaseClientGetTests.cs" />
<Compile Include="CouchbaseClientTestsBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\lib\EnyimMemcached\Enyim.Caching\Enyim.Caching.csproj">
<Project>{D438C0B3-A168-40B8-BDDD-61F0939DFF35}</Project>
<Name>Enyim.Caching</Name>
</ProjectReference>
<ProjectReference Include="..\Couchbase\Couchbase.csproj">
<Project>{708A2350-A26C-444D-B975-8164263951A7}</Project>
<Name>Couchbase</Name>
</ProjectReference>
</ItemGroup>
<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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
102 changes: 102 additions & 0 deletions src/Couchbase.Tests/CouchbaseClientGetTests.cs
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Couchbase.Tests
{
[TestFixture]
public class MemcachedClientGetTests : CouchbaseClientTestsBase
{

[Test]
public void When_Getting_Existing_Item_Value_Is_Not_Null_And_Result_Is_Successful()
{
var key = GetUniqueKey("get");
var value = GetRandomString();
var storeResult = Store(key: key, value: value);
StoreAssertPass(storeResult);

var getResult = _Client.ExecuteGet(key);
GetAssertPass(getResult, value);
}

[Test]
public void When_Getting_Item_For_Invalid_Key_HasValue_Is_False_And_Result_Is_Not_Successful()
{
var key = GetUniqueKey("get");

var getResult = _Client.ExecuteGet(key);
GetAssertFail(getResult);
}

[Test]
public void When_TryGetting_Existing_Item_Value_Is_Not_Null_And_Result_Is_Successful()
{
var key = GetUniqueKey("get");
var value = GetRandomString();
var storeResult = Store(key: key, value: value);
StoreAssertPass(storeResult);

object temp;
var getResult = _Client.ExecuteTryGet(key, out temp);
GetAssertPass(getResult, temp);
}

[Test]
public void When_Generic_Getting_Existing_Item_Value_Is_Not_Null_And_Result_Is_Successful()
{
var key = GetUniqueKey("get");
var value = GetRandomString();
var storeResult = Store(key: key, value: value);
StoreAssertPass(storeResult);

var getResult = _Client.ExecuteGet<string>(key);
Assert.That(getResult.Success, Is.True, "Success was false");
Assert.That(getResult.Cas, Is.GreaterThan(0), "Cas value was 0");
Assert.That(getResult.StatusCode, Is.EqualTo(0).Or.Null, "StatusCode was neither 0 nor null");
Assert.That(getResult.Value, Is.EqualTo(value), "Actual value was not expected value: " + getResult.Value);
}

[Test]
public void When_Getting_Multiple_Keys_Result_Is_Successful()
{
var keys = GetUniqueKeys().Distinct();
foreach (var key in keys)
{
Store(key: key, value: "Value for" + key);
}

var dict = _Client.ExecuteGet(keys);
Assert.That(dict.Keys.Count, Is.EqualTo(keys.Count()), "Keys count did not match results count");

foreach (var key in dict.Keys)
{
Assert.That(dict[key].Success, Is.True, "Get failed for key: " + key);
}
}
}
}

#region [ License information ]
/* ************************************************************
*
* @author Couchbase <info@couchbase.com>
* @copyright 2012 Couchbase, Inc.
* @copyright 2012 Attila Kiskó, enyim.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ************************************************************/
#endregion
151 changes: 151 additions & 0 deletions src/Couchbase.Tests/CouchbaseClientTestsBase.cs
@@ -0,0 +1,151 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Enyim.Caching.Configuration;
using Enyim.Caching.Memcached.Results;
using Enyim.Caching.Memcached;
using Couchbase.Configuration;

namespace Couchbase.Tests
{

[TestFixture]
public abstract class CouchbaseClientTestsBase
{

protected CouchbaseClient _Client;

[SetUp]
public void SetUp()
{
var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://localhost:8091/pools/default"));
config.Bucket = "default";

_Client = new CouchbaseClient(config);
}

protected string GetUniqueKey(string prefix = null)
{
return (!string.IsNullOrEmpty(prefix) ? prefix + "_" : "") +
"unit_test_" + DateTime.Now.Ticks;
}

protected IEnumerable<string> GetUniqueKeys(string prefix = null, int max = 5)
{

var keys = new List<string>(max);
for (int i = 0; i < max; i++)
{
keys.Add(GetUniqueKey(prefix));
}

return keys;
}

protected string GetRandomString()
{
var rand = new Random((int)DateTime.Now.Ticks).Next();
return "unit_test_value_" + rand;
}

protected IStoreOperationResult Store(StoreMode mode = StoreMode.Set, string key = null, string value = null)
{
if (string.IsNullOrEmpty(key))
{
key = GetUniqueKey("store");
}

if (value == null)
{
value = GetRandomString();
}
return _Client.ExecuteStore(mode, key, value);
}

protected void StoreAssertPass(IStoreOperationResult result)
{
Assert.That(result.Success, Is.True, "Success was false");
Assert.That(result.Cas, Is.GreaterThan(0), "Cas value was 0");
Assert.That(result.StatusCode, Is.EqualTo(0), "StatusCode was not 0");
}

protected void StoreAssertFail(IStoreOperationResult result)
{
Assert.That(result.Success, Is.False, "Success was true");
Assert.That(result.Cas, Is.EqualTo(0), "Cas value was not 0");
Assert.That(result.StatusCode, Is.GreaterThan(0), "StatusCode not greater than 0");
Assert.That(result.InnerResult, Is.Not.Null, "InnerResult was null");
}

protected void GetAssertPass(IGetOperationResult result, object expectedValue)
{
Assert.That(result.Success, Is.True, "Success was false");
Assert.That(result.Cas, Is.GreaterThan(0), "Cas value was 0");
Assert.That(result.StatusCode, Is.EqualTo(0).Or.Null, "StatusCode was neither 0 nor null");
Assert.That(result.Value, Is.EqualTo(expectedValue), "Actual value was not expected value: " + result.Value);
}

protected void GetAssertFail(IGetOperationResult result)
{
Assert.That(result.Success, Is.False, "Success was true");
Assert.That(result.Cas, Is.EqualTo(0), "Cas value was not 0");
Assert.That(result.StatusCode, Is.Null.Or.GreaterThan(0), "StatusCode not greater than 0");
Assert.That(result.HasValue, Is.False, "HasValue was true");
Assert.That(result.Value, Is.Null, "Value was not null");
}

protected void MutateAssertPass(IMutateOperationResult result, ulong expectedValue)
{
Assert.That(result.Success, Is.True, "Success was false");
Assert.That(result.Value, Is.EqualTo(expectedValue), "Value was not expected value: " + expectedValue);
Assert.That(result.Cas, Is.GreaterThan(0), "Cas was not greater than 0");
Assert.That(result.StatusCode, Is.Null.Or.EqualTo(0), "StatusCode was not null or 0");
}

protected void MutateAssertFail(IMutateOperationResult result)
{
Assert.That(result.Success, Is.False, "Success was true");
Assert.That(result.Cas, Is.EqualTo(0), "Cas 0");
Assert.That(result.StatusCode, Is.Null.Or.Not.EqualTo(0), "StatusCode was 0");
}

protected void ConcatAssertPass(IConcatOperationResult result)
{
Assert.That(result.Success, Is.True, "Success was false");
Assert.That(result.Cas, Is.GreaterThan(0), "Cas value was 0");
Assert.That(result.StatusCode, Is.EqualTo(0), "StatusCode was not 0");
}

protected void ConcatAssertFail(IConcatOperationResult result)
{
Assert.That(result.Success, Is.False, "Success was true");
Assert.That(result.Cas, Is.EqualTo(0), "Cas value was not 0");
Assert.That(result.StatusCode, Is.Null.Or.GreaterThan(0), "StatusCode not greater than 0");
}
}
}

#region [ License information ]
/* ************************************************************
*
* @author Couchbase <info@couchbase.com>
* @copyright 2012 Couchbase, Inc.
* @copyright 2012 Attila Kiskó, enyim.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ************************************************************/
#endregion
36 changes: 36 additions & 0 deletions src/Couchbase.Tests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Couchbase.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Couchbase.Tests")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("bbecf901-486f-40f8-8b06-55f871cfb4aa")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
4 changes: 4 additions & 0 deletions src/Couchbase.Tests/packages.config
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.0.12054" />
</packages>
6 changes: 6 additions & 0 deletions src/Couchbase.sln
Expand Up @@ -5,6 +5,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Couchbase", "Couchbase\Couc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enyim.Caching", "..\lib\EnyimMemcached\Enyim.Caching\Enyim.Caching.csproj", "{D438C0B3-A168-40B8-BDDD-61F0939DFF35}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Couchbase.Tests", "Couchbase.Tests\Couchbase.Tests.csproj", "{B286E960-FC97-4ED5-97C1-BDB44DECD3A3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -19,6 +21,10 @@ Global
{D438C0B3-A168-40B8-BDDD-61F0939DFF35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D438C0B3-A168-40B8-BDDD-61F0939DFF35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D438C0B3-A168-40B8-BDDD-61F0939DFF35}.Release|Any CPU.Build.0 = Release|Any CPU
{B286E960-FC97-4ED5-97C1-BDB44DECD3A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B286E960-FC97-4ED5-97C1-BDB44DECD3A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B286E960-FC97-4ED5-97C1-BDB44DECD3A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B286E960-FC97-4ED5-97C1-BDB44DECD3A3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 46433cb

Please sign in to comment.