Permalink
Browse files

NCBC-203 : Restructure .net unit tests

Removed white spaces and incorporated review comments
Removed wait handle, not required

Change-Id: I63605bafd0e93a6d780cf73e5705ac33ce06d5ee
Reviewed-on: http://review.couchbase.org/23604
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Reviewed-by: Saakshi Manocha <saakshi.manocha@globallogic.com>
Tested-by: Saakshi Manocha <saakshi.manocha@globallogic.com>
  • Loading branch information...
saakshimanocha committed Dec 19, 2012
1 parent dcf9d0b commit 5ba5287ecaaa9c0a35d787fbc0706214fccae6dc
@@ -14,25 +14,34 @@
<section name="httpclient-config-initconn" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
<section name="httpclient-config-noinitconn" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
<sectionGroup name="enyim.com">
<section name="log" type="Enyim.Caching.Configuration.LoggerSection, Enyim.Caching" />
<section name="log" type="Enyim.Caching.Configuration.LoggerSection, Enyim.Caching"/>
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<appSettings>
<add key="CouchbaseServerUrl" value="http://localhost:8091"/>
<add key="DefaultBucketName" value="default"/>
<add key="SaslBucketName" value="authenticated"/>
<add key="SaslBucketPassword" value="password"/>
<add key="UserNameForLoginToCouchbaseServer" value="Administrator"/>
<add key="UserPasswordForLoginToCouchbaseServer" value="password"/>
</appSettings>
<enyim.com>
<log factory="Enyim.Caching.Log4NetFactory, Enyim.Caching.Log4NetAdapter" />
<log factory="Enyim.Caching.Log4NetFactory, Enyim.Caching.Log4NetAdapter"/>
</enyim.com>
<log4net debug="false">
<log4net debug="true">
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender,log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n"/>
</layout>
</appender>
<root>
<priority value="ALL" />
<level value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
<priority value="ALL"/>
<level value="DEBUG"/>
<appender-ref ref="ConsoleAppender"/>
</root>
<logger name="ObserveHandler">
@@ -41,81 +50,82 @@
</log4net>
<couchbase>
<servers bucket="default" bucketPassword="" username="Administrator" password="qwerty" observeTimeout="00:01:00">
<add uri="http://localhost:8091/pools" />
<servers bucket="default" bucketPassword="" username="Administrator" password="password" observeTimeout="00:01:00">
<add uri="http://localhost:8091/pools"/>
</servers>
<documentNameTransformer type="Couchbase.Configuration.ProductionModeNameTransformer, Couchbase" />
<httpClientFactory type="Couchbase.RestSharpHttpClientFactory, Couchbase" />
<socketPool connectionTimeout="00:00:30" />
</couchbase>
<min-config>
<servers bucket="default" bucketPassword="" username="Administrator" password="qwerty">
<add uri="http://localhost:8091/pools" />
<servers bucket="default" bucketPassword="" username="Administrator" password="password">
<add uri="http://localhost:8091/pools"/>
</servers>
</min-config>
<pools-config>
<servers bucket="default">
<add uri="http://localhost:8091/pools" />
<add uri="http://localhost:8091/pools"/>
</servers>
</pools-config>
<pools-default-config>
<servers bucket="default">
<add uri="http://localhost:8091/pools/default" />
<add uri="http://localhost:8091/pools/default"/>
</servers>
</pools-default-config>
<httptimeout-default-config>
<servers bucket="default">
<add uri="http://localhost:8091/pools/default" />
<add uri="http://localhost:8091/pools/default"/>
</servers>
</httptimeout-default-config>
<httptimeout-explicit-config>
<servers bucket="default" httpRequestTimeout="00:00:30">
<add uri="http://localhost:8091/pools/default" />
<add uri="http://localhost:8091/pools/default"/>
</servers>
</httptimeout-explicit-config>
<observe-default-config>
<servers bucket="default">
<add uri="http://localhost:8091/pools/default" />
<add uri="http://localhost:8091/pools/default"/>
</servers>
</observe-default-config>
<observe-explicit-config>
<servers bucket="default" observeTimeout="00:00:30">
<add uri="http://localhost:8091/pools/default" />
<add uri="http://localhost:8091/pools/default"/>
</servers>
</observe-explicit-config>
<heartbeat-config-on>
<servers bucket="default">
<add uri="http://localhost:8091/pools" />
<add uri="http://localhost:8091/pools"/>
</servers>
<heartbeatMonitor uri="http://localhost:8091/pools" enabled="true" interval="30" />
<heartbeatMonitor uri="http://localhost:8091/pools" enabled="true" interval="30"/>
</heartbeat-config-on>
<heartbeat-config-off>
<servers bucket="default">
<add uri="http://localhost:8091/pools" />
<add uri="http://localhost:8091/pools"/>
</servers>
<heartbeatMonitor enabled="false" />
<heartbeatMonitor enabled="false"/>
</heartbeat-config-off>
<httpclient-config-initconn>
<servers bucket="default">
<add uri="http://localhost:8091/pools" />
<add uri="http://localhost:8091/pools"/>
</servers>
<httpClient initializeConnection="false" />
<httpClient initializeConnection="false"/>
</httpclient-config-initconn>
<httpclient-config-noinitconn>
<servers bucket="default">
<add uri="http://localhost:8091/pools" />
<add uri="http://localhost:8091/pools"/>
</servers>
<httpClient initializeConnection="false" timeout="00:00:45"/>
</httpclient-config-noinitconn>
</configuration>
@@ -12,15 +12,15 @@ namespace Couchbase.Tests
[TestFixture]
public class ConfigHelperTests : CouchbaseClientTestsBase
{
/// <summary>
/// @test: Reads the information about available data buckets from pools,
/// generates a random key-value, stores in the available data bucket, and then
/// retrive the value by passing the same key for verification
/// @pre: Add section named "pools-config" in App.config file,
/// configure all the parameters required to initialize Couchbase client like Uri, bucket, etc.
/// mention uri = http://Url_Of_Couchbase_Server/pools
/// @post: Test passes if successfully stores key-value and then able to get value, fails otherwise
/// </summary>
/// <summary>
/// @test: Reads the information about available data buckets from pools,
/// generates a random key-value, stores in the available data bucket, and then
/// retrive the value by passing the same key for verification
/// @pre: Add section named "pools-config" in App.config file,
/// configure all the parameters required to initialize Couchbase client like Uri, bucket, etc.
/// mention uri = http://Url_Of_Couchbase_Server/pools
/// @post: Test passes if successfully stores key-value and then able to get value, fails otherwise
/// </summary>
[Test]
public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Root_Uri()
{
@@ -34,19 +34,19 @@ public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Root_Uri()
GetAssertPass(getResult, value);
}
/// <summary>
/// @test: Reads the information about available data buckets from pools/default,
/// generates a random key-value, stores in the default data bucket, and then
/// retrive the value by passing the same key for verification
/// @pre: Add section named "pools-default-config" in App.config file,
/// configure all the parameters required to initialize Couchbase client like Uri, bucket, etc.
/// mention uri = http://Url_Of_Couchbase_Server/pools/default
/// @post: Test passes if successfully stores key-value and then able to get value, fails otherwise
/// </summary>
/// <summary>
/// @test: Reads the information about available data buckets from pools/default,
/// generates a random key-value, stores in the default data bucket, and then
/// retrive the value by passing the same key for verification
/// @pre: Add section named "pools-default-config" in App.config file,
/// configure all the parameters required to initialize Couchbase client like Uri, bucket, etc.
/// mention uri = http://Url_Of_Couchbase_Server/pools/default
/// @post: Test passes if successfully stores key-value and then able to get value, fails otherwise
/// </summary>
[Test]
public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Default_Root_Uri()
{
var config = ConfigSectionUtils.GetConfigSection<CouchbaseClientSection>("pools-default-config");
var config = ConfigSectionUtils.GetConfigSection<CouchbaseClientSection>("pools-default-config");
var client = new CouchbaseClient(config);
string key = GetUniqueKey(), value = GetRandomString();
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using NUnit.Framework;
@@ -8,59 +9,57 @@
namespace Couchbase.Tests
{
[TestFixture]
public class CouchbaseAuthenticatedViewTests : CouchbaseClientViewTestsBase
{
[TestFixture]
public class CouchbaseAuthenticatedViewTests : CouchbaseClientViewTestsBase
{
/// <summary>
/// @test: Verifies that for the bucket which is authenticated with password, it is able to connect successfully
/// @test: Verifies that for the bucket which is authenticated with password, it is able to connect successfully
/// if correct cedentials are provided and then returns the object representing the view in specfied design document
/// @pre: Provide the bucket name and password in method getClient(),
/// @pre: Provide the bucket name and password in method getClient(),
/// provide correct design name and view name to method GetView()
/// @post: Test passes if connects to client successfully and get the details of View with given data, fails otherwise
/// </summary>
[Test]
public void When_Bucket_Is_Authenticated_View_Returns_Results()
{
var view = getClient("authenticated", "secret").GetView("cities", "by_name");
foreach (var item in view) { }
Assert.That(view.Count(), Is.EqualTo(1), "Row count was not 1");
}
[Test]
public void When_Bucket_Is_Authenticated_View_Returns_Results()
{
var client = getClient(ConfigurationManager.AppSettings["SaslBucketName"], ConfigurationManager.AppSettings["SaslBucketPassword"]);
var view = client.GetView("cities", "by_name");
Assert.That(view.Count(), Is.EqualTo(1), "Row count was not 1");
}
/// <summary>
/// @test: Verifies that for the bucket which is authenticated with password, it throws an error
/// if no credentials are provided and hence cannot return the object representing the view in specfied design document
/// @pre: Provide the bucket name but no password in method getClient(),
/// @pre: Provide the bucket name but no password in method getClient(),
/// provide design name and view name to method GetView()
/// @post: Test passes if the web exception (401) is thrown
/// </summary>
[ExpectedException(typeof(InvalidOperationException))]
[Test]
public void When_Bucket_Is_Authenticated_And_No_Credentials_Are_Provided_Exception_Is_Thrown()
{
var view = getClient("authenticated", "").GetView("cities", "by_name");
var client = getClient(ConfigurationManager.AppSettings["SaslBucketName"], "");
var view = client.GetView("cities", "by_name");
foreach (var item in view) { Console.WriteLine(item); }
}
/// <summary>
/// Connects to couchbase client with given configuration details
/// </summary>
/// <param name="username">Name of bucket to be used</param>
/// <param name="password">Password used to connect to bucket</param>
/// <param name="bucketName">Name of bucket to be used</param>
/// <param name="bucketPassword">Password used to connect to bucket</param>
/// <returns>Couchbase client object</returns>
private CouchbaseClient getClient(string username, string password)
{
var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://localhost:8091/pools"));
config.Bucket = username;
config.BucketPassword = password;
config.DesignDocumentNameTransformer = new DevelopmentModeNameTransformer();
config.HttpClientFactory = new HammockHttpClientFactory();
return new CouchbaseClient(config);
}
}
private CouchbaseClient getClient(string bucketName, string bucketPassword)
{
var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri(ConfigurationManager.AppSettings["CouchbaseServerUrl"] + "/pools"));
config.Bucket = bucketName;
config.BucketPassword = bucketPassword;
config.DesignDocumentNameTransformer = new DevelopmentModeNameTransformer();
config.HttpClientFactory = new HammockHttpClientFactory();
return new CouchbaseClient(config);
}
}
}
#region [ License information ]
@@ -12,11 +12,12 @@ namespace Couchbase.Tests
public class CouchbaseClientCasTests : CouchbaseClientTestsBase
{
/// <summary>
/// @test: Store a randomly generated unique key-value, use he CAS value
/// @test: Store a randomly generated unique key-value, use he CAS value
/// returned from the Store(), then use ExecuteCas() method
/// to compare and set a value using the specified key and return the store operation result
/// @pre: No section required in App.config file
/// @post: Test passes if successfully able to retrieve the same cas value, fails otherwise
/// @post: Test passes if successfully able to add a key-value pair and then retrieve the same cas value,
/// fails otherwise
/// </summary>
[Test]
public void When_Storing_Item_With_Valid_Cas_Result_Is_Successful()
@@ -10,11 +10,10 @@ namespace Couchbase.Tests
public class CouchbaseClientConcatTests : CouchbaseClientTestsBase
{
/// <summary>
/// @test: Store a randomly generated unique key-value, use the different
/// cas value in ExecuteCas() mehod than what is returned by Store() method,
/// the ExecuteCas() fails due to invalid cas passed
/// @pre: No section required in App.config file
/// @post: Test passes if ExecuteCas() fails due to invalid cas, fails if ExecuteCas() passes
/// @test: Store a randomly generated unique key-value, use ExecuteAppend() to append some string
/// to its value and then get the new string after appending
/// @pre: No section required in App.config file, it picks up the default configuration
/// @post: Test passes if ExecuteAppend() passes and Get method returns the new string after appending text to it
/// </summary>
[Test]
public void When_Appending_To_Existing_Value_Result_Is_Successful()
@@ -37,7 +36,7 @@ public void When_Appending_To_Existing_Value_Result_Is_Successful()
/// <summary>
/// @test: Generate a unique key, use ExecuteAppend() to save data in that key,
/// since the key does not exist aleady, append operation would fail, then get value from
/// since the key does not exist already, append operation would fail, then get value from
/// the same key, it will fail again as the key does not exist
/// @pre: Generate a unique key and data to append in that key
/// @post: Test passes if ExecuteAppend() and ExecuteGet() both fail, which is the expected behaviour
@@ -104,10 +103,11 @@ public void When_Prepending_To_Invalid_Key_Result_Is_Not_Successful()
}
/// <summary>
/// @test: Generate a unique key and store it, Prepend some text to that key-value,
/// it should pass, then get the value against the same key, it should pass
/// @test: Generate a unique key and store it, test checks to see that
/// the final output key contains both the 'original' (i.e. "concat") value as well as
/// the appended value. (i.e. "concatTheEnd")
/// @pre: Generate a unique key and data to append in that key
/// @post: Test passes if ExecutePrepend() and ExecuteGet() both pass
/// @post: Test passes if ExecuteAppend() and ExecuteGet() both pass
/// </summary>
[Test]
public void When_Appending_To_Existing_Value_Result_Is_Successful_With_Valid_Cas()
@@ -177,7 +177,7 @@ public void When_Prepending_To_Existing_Value_Result_Is_Successful_With_Valid_Ca
/// @test: Generate a unique key and store it, Append some text and use the different cas key,
/// the test should fail
/// @pre: Generate a unique key and data to append in that key
/// @post: Test passes if ExecuteAppend() passes
/// @post: Test passes if ExecuteAppend() fails since the Cas is invalid
/// </summary>
[Test]
public void When_Prepending_To_Existing_Value_Result_Is_Not_Successful_With_Invalid_Cas()
@@ -14,20 +14,19 @@ public class CouchbaseClientConfigTests
/// <summary>
/// @test: Reads the information about couchbase client configuration from App.Config,
/// and verifies that all properties are set
/// @pre: Add section named "couchbase" in App.config file,
/// @pre: Add section named "couchbase" in App.config file,
/// configure all the parameters required to initialize Couchbase client like Uri, bucket, username, password etc.
/// @post: Test passes if able to retrieve couchbase client configuration, the username and password match with
/// expected details, fails otherwise
/// </summary>
[Test]
public void When_Setting_Username_And_Password_In_Config_Section_Config_Instance_Properties_Are_Set()
{
var config = ConfigurationManager.GetSection("couchbase") as CouchbaseClientSection;
var config = ConfigurationManager.GetSection("couchbase") as CouchbaseClientSection;
Assert.That(config, Is.Not.Null, "Config was null");
Assert.That(config.Servers.Username, Is.StringMatching("Administrator"));
Assert.That(config.Servers.Password, Is.StringMatching("qwerty"));
Assert.That(config.Servers.Username, Is.StringMatching(ConfigurationManager.AppSettings["UserNameForLoginToCouchbaseServer"]));
Assert.That(config.Servers.Password, Is.StringMatching(ConfigurationManager.AppSettings["UserPasswordForLoginToCouchbaseServer"]));
}
}
}
@@ -12,7 +12,7 @@ namespace Couchbase.Tests
public class CouchbaseClientExtensionsTests : CouchbaseClientTestsBase
{
/// <summary>
/// @test: Generate a unique key and store key using StoreJson(), without converting into json
/// @test: Generate a unique key and store key using StoreJson(), without converting into json
/// the store operation would fail
/// @pre: Generate a unique key and data to append in that key
/// @post: Test passes if ExecuteAppend() passes
Oops, something went wrong.

0 comments on commit 5ba5287

Please sign in to comment.