Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit e60089e8d61fd05c3ba9dc567794912775c317a1 @soitgoes committed Aug 25, 2010
@@ -0,0 +1,29 @@
+
+#ignore thumbnails created by windows
+Thumbs.db
+#Ignore files build by Visual Studio
+*.obj
+*.exe
+*.pdb
+*.user
+*.aps
+*.pch
+*.vspscc
+*_i.c
+*_p.c
+*.ncb
+*.suo
+*.tlb
+*.tlh
+*.bak
+*.cache
+*.ilk
+*.log
+[Bb]in
+[Dd]ebug*/
+*.lib
+*.sbr
+obj/
+[Rr]elease*/
+_ReSharper*/
+[Tt]est[Rr]esult*
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+
+namespace LoveSeat.IntegrationTest
+{
+ [TestFixture]
+ public class CouchClientTest
+ {
+ private CouchClient client;
+
+ [SetUp]
+ public void Setup()
+ {
+ client = new CouchClient("localhost", 5984, "bubba", "password");
+ }
+
+ [Test]
+ public void CanGetSessionCookie()
+ {
+ var cookie = client.GetSession();
+ Assert.IsNotNull(cookie);
+ }
+
+ [Test]
+ public void CanTriggerReplication()
+ {
+ var obj = client.TriggerReplication("http://bubba:password@remotedb.com:5984/remotedb", "local");
+ Assert.IsTrue(obj != null);
+ }
+ }
+}
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{7496CEA9-442C-4468-8350-54F34693F64A}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>LoveSeat.IntegrationTest</RootNamespace>
+ <AssemblyName>LoveSeat.IntegrationTest</AssemblyName>
+ <TargetFrameworkVersion>v3.5</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="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libraries\Newtonsoft.Json.dll</HintPath>
+ </Reference>
+ <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libraries\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data.DataSetExtensions">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="CouchClientTest.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\LoveSeat\LoveSeat.csproj">
+ <Project>{AF987164-0100-4A90-A767-D473F882EA8B}</Project>
+ <Name>LoveSeat</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>
@@ -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("LoveSeat.IntegrationTest")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("LoveSeat.IntegrationTest")]
+[assembly: AssemblyCopyright("Copyright © 2010")]
+[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("9919df81-a6c1-4637-8a8c-f8c694f9543f")]
+
+// 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")]
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoveSeat", "LoveSeat\LoveSeat.csproj", "{AF987164-0100-4A90-A767-D473F882EA8B}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoveSeat.IntegrationTest", "LoveSeat.IntegrationTest\LoveSeat.IntegrationTest.csproj", "{7496CEA9-442C-4468-8350-54F34693F64A}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {AF987164-0100-4A90-A767-D473F882EA8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AF987164-0100-4A90-A767-D473F882EA8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AF987164-0100-4A90-A767-D473F882EA8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AF987164-0100-4A90-A767-D473F882EA8B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7496CEA9-442C-4468-8350-54F34693F64A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7496CEA9-442C-4468-8350-54F34693F64A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7496CEA9-442C-4468-8350-54F34693F64A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7496CEA9-442C-4468-8350-54F34693F64A}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace LoveSeat
+{
+ public class CouchClient
+ {
+ private readonly string host;
+ private readonly int port;
+ private readonly string username;
+ private readonly string password;
+ private readonly CookieContainer cookieContainer;
+ private string baseUri;
+
+ /// <summary>
+ /// Constructs the CouchClient and gets an authentication cookie (10 min)
+ /// </summary>
+ /// <param name="host"></param>
+ /// <param name="port"></param>
+ /// <param name="username"></param>
+ /// <param name="password"></param>
+ public CouchClient(string host, int port, string username, string password)
+ {
+ this.host = host;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ this.baseUri = "http://" + host + ":" + port + "/";
+ this.cookieContainer = new CookieContainer();
+ var cookie = GetSession();
+ if (cookie != null)
+ {
+ this.cookieContainer.Add(cookie);
+ }
+
+ }
+ public Cookie GetSession()
+ {
+ var request = new CouchRequest(baseUri + "_session");
+ var response = request.Post()
+ .ContentType("application/x-www-form-urlencoded")
+ .Data("name=" + username + "&password=" + password)
+ .GetResponse();
+
+ var header = response.Headers.Get("Set-Cookie");
+ if (header != null)
+ {
+ var parts = header.Split(';')[0].Split('=');
+ var authCookie = new Cookie(parts[0], parts[1]);
+ authCookie.Domain = response.Server;
+ return authCookie;
+ }
+ return null;
+ }
+ public JObject TriggerReplication(string source, string target, bool continuous)
+ {
+ var request = new CouchRequest(baseUri + "_replicate");
+ var options = new ReplicationOptions(source, target, continuous);
+ var response = request.Post()
+ .Data(options.ToString())
+ .GetResponse();
+
+ using ( var stream = response.GetResponseStream())
+ {
+ using (var streamReader = new StreamReader(stream))
+ {
+ var result = streamReader.ReadToEnd();
+ return JObject.Parse(result);
+ }
+ }
+ }
+ public JObject TriggerReplication(string source, string target)
+ {
+ return TriggerReplication(source, target, false);
+ }
+
+ }
+}
@@ -0,0 +1,27 @@
+using System;
+using System.Net;
+
+namespace LoveSeat
+{
+ public class CouchException : Exception
+ {
+ private readonly HttpStatusCode statusCode;
+
+ public CouchException(string message, HttpStatusCode statusCode)
+ : base(message)
+ {
+ this.statusCode = statusCode;
+ }
+ public CouchException(HttpStatusCode statusCode)
+ {
+ this.statusCode = statusCode;
+ }
+ public HttpStatusCode StatusCode
+ {
+ get
+ {
+ return statusCode;
+ }
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit e60089e

Please sign in to comment.