Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from odeits/master

Basic Functionality
  • Loading branch information...
commit 483bcd17f090663ac06b05550f19412e56c1def3 2 parents a4ae349 + 509e1d7
@edsrzf edsrzf authored
Showing with 51,631 additions and 1 deletion.
  1. +56 −1 .gitignore
  2. +104 −0 IronCache/Client.cs
  3. +18 −0 IronCache/Data/Cache.cs
  4. +21 −0 IronCache/Data/CacheItem.cs
  5. +15 −0 IronCache/Data/Error.cs
  6. +40 −0 IronCache/Data/Item.cs
  7. +155 −0 IronCache/IronCache.cs
  8. +68 −0 IronCache/IronCache.csproj
  9. +36 −0 IronCache/IronCache.sln
  10. BIN  IronCache/IronCache.sln.docstates.suo
  11. BIN  IronCache/IronCache.suo
  12. +6 −0 IronCache/IronCache.vsmdi
  13. +7 −0 IronCache/IronCacheTests/App.config
  14. +164 −0 IronCache/IronCacheTests/IronCacheTest.cs
  15. +80 −0 IronCache/IronCacheTests/IronCacheTests.csproj
  16. +35 −0 IronCache/IronCacheTests/Properties/AssemblyInfo.cs
  17. +10 −0 IronCache/Local.testsettings
  18. +36 −0 IronCache/Properties/AssemblyInfo.cs
  19. +9 −0 IronCache/TraceAndTestImpact.testsettings
  20. +4 −0 IronCache/packages.config
  21. BIN  IronCache/packages/Newtonsoft.Json.4.5.5/Newtonsoft.Json.4.5.5.nupkg
  22. BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/net20/Newtonsoft.Json.dll
  23. +8,181 −0 IronCache/packages/Newtonsoft.Json.4.5.5/lib/net20/Newtonsoft.Json.xml
  24. BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/net35/Newtonsoft.Json.dll
  25. +7,317 −0 IronCache/packages/Newtonsoft.Json.4.5.5/lib/net35/Newtonsoft.Json.xml
  26. BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/net40/Newtonsoft.Json.dll
  27. +7,560 −0 IronCache/packages/Newtonsoft.Json.4.5.5/lib/net40/Newtonsoft.Json.xml
  28. BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/sl3-wp/Newtonsoft.Json.dll
  29. +6,860 −0 IronCache/packages/Newtonsoft.Json.4.5.5/lib/sl3-wp/Newtonsoft.Json.xml
  30. BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/sl4-windowsphone71/Newtonsoft.Json.dll
  31. +6,860 −0 IronCache/packages/Newtonsoft.Json.4.5.5/lib/sl4-windowsphone71/Newtonsoft.Json.xml
  32. BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/sl4/Newtonsoft.Json.dll
  33. +6,882 −0 IronCache/packages/Newtonsoft.Json.4.5.5/lib/sl4/Newtonsoft.Json.xml
  34. BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/winrt45/Newtonsoft.Json.dll
  35. +7,103 −0 IronCache/packages/Newtonsoft.Json.4.5.5/lib/winrt45/Newtonsoft.Json.xml
  36. +4 −0 IronCache/packages/repositories.config
View
57 .gitignore
@@ -3,4 +3,59 @@ bin
obj
# mstest test results
-TestResults
+TestResults
+
+#OS junk files
+[Tt]humbs.db
+*.DS_Store
+
+#Visual Studio files
+*.[Oo]bj
+*.user
+*.aps
+*.pch
+*.vspscc
+*.vssscc
+*_i.c
+*_p.c
+*.ncb
+*.suo
+*.tlb
+*.tlh
+*.bak
+*.[Cc]ache
+*.ilk
+*.log
+*.lib
+*.sbr
+*.sdf
+*.opensdf
+*.unsuccessfulbuild
+ipch/
+obj/
+[Bb]in
+[Dd]ebug*/
+[Rr]elease*/
+Ankh.NoLoad
+
+#MonoDevelop
+*.pidb
+*.userprefs
+
+#Tooling
+_ReSharper*/
+*.resharper
+[Tt]est[Rr]esult*
+
+#Project files
+[Bb]uild/
+
+#Subversion files
+.svn
+
+# Office Temp Files
+~$*
+
+#ncrunch
+*ncrunch*
+*crunch*.local.xml
View
104 IronCache/Client.cs
@@ -0,0 +1,104 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+using io.iron.ironcache.Data;
+using Newtonsoft.Json;
+
+namespace io.iron.ironcache
+{
+ public class Client
+ {
+ private const string PROTO = "https";
+ private const string HOST = "mq-aws-us-east-1.iron.io";
+ private const int PORT = 443;
+ private const string API_VERSION = "1";
+
+ private string projectId = string.Empty;
+ private string token = string.Empty;
+
+ public string Host { get; private set; }
+
+ public int Port { get; private set; }
+
+ private JsonSerializerSettings settings = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None, DefaultValueHandling = DefaultValueHandling.Ignore };
+
+ /// <summary>
+ /// Constructs a new Client using the specified project ID and token.
+ /// The network is not accessed during construction and this call will
+ /// succeed even if the credentials are invalid.
+ /// </summary>
+ /// <param name="projectId">projectId A 24-character project ID.</param>
+ /// <param name="token">token An OAuth token.</param>
+ public Client(string projectId, string token, string host = HOST, int port = PORT)
+ {
+ this.projectId = projectId;
+ this.token = token;
+ this.Host = host;
+ this.Port = port;
+ }
+
+ public string delete(string endpoint)
+ {
+ return request("DELETE", endpoint, null);
+ }
+
+ public string get(string endpoint)
+ {
+ return request("GET", endpoint, null);
+ }
+
+ public string post(string endpoint, string body)
+ {
+ return request("POST", endpoint, body);
+ }
+
+ public string put(string endpoint, string body)
+ {
+ return request("PUT", endpoint, body);
+ }
+
+ private string request(string method, string endpoint, string body)
+ {
+ string path = "/" + API_VERSION + "/projects/" + projectId + "/" + endpoint;
+ string uri = PROTO + "://" + this.Host + ":" + this.Port + path;
+ HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
+ request.ContentType = "application/json";
+ request.Headers.Add("Authorization", "OAuth " + token);
+ request.UserAgent = "IronMQ .Net Client";
+ request.Method = method;
+ if (body != null)
+ {
+ using (System.IO.StreamWriter write = new System.IO.StreamWriter(request.GetRequestStream()))
+ {
+ write.Write(body);
+ write.Flush();
+ }
+ }
+ HttpWebResponse response;
+ try
+ {
+ response = (HttpWebResponse)request.GetResponse();
+ }
+ catch (WebException we)
+ {
+ if (we.Response != null)
+ response = (HttpWebResponse)we.Response;
+ else
+ throw we;
+ }
+ string json = string.Empty;
+ using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()))
+ {
+ json = reader.ReadToEnd();
+ }
+ if (response.StatusCode != HttpStatusCode.OK)
+ {
+ Error error = JsonConvert.DeserializeObject<Error>(json);
+ throw new System.Web.HttpException((int)response.StatusCode, error.Message);
+ }
+ return json;
+ }
+ }
+}
View
18 IronCache/Data/Cache.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Newtonsoft.Json;
+
+namespace io.iron.ironcache.Data
+{
+ [JsonObject(MemberSerialization.OptOut)]
+ public class Cache
+ {
+ [JsonProperty("project_id")]
+ public string ProjectId { get; set; }
+
+ [JsonProperty("name")]
+ public string Name { get; set; }
+ }
+}
View
21 IronCache/Data/CacheItem.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Newtonsoft.Json;
+
+namespace io.iron.ironcache.Data
+{
+ [JsonObject(MemberSerialization.OptOut)]
+ internal class CacheItem<T>
+ {
+ public string Cache { get; set; }
+
+ public string Key { get; set; }
+
+ public T Value { get; set; }
+
+ [JsonProperty("cas")]
+ public long CheckAndSet { get; set; }
+ }
+}
View
15 IronCache/Data/Error.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Newtonsoft.Json;
+
+namespace io.iron.ironcache.Data
+{
+ [JsonObject(MemberSerialization.OptOut)]
+ public class Error
+ {
+ [JsonProperty("msg")]
+ public string Message { get; set; }
+ }
+}
View
40 IronCache/Data/Item.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using Newtonsoft.Json;
+
+namespace io.iron.ironcache.Data
+{
+ [JsonObject(MemberSerialization.OptOut)]
+ internal class Item<T>
+ {
+ /// <summary>
+ /// The item’s data
+ /// </summary>
+ [JsonProperty("body")]
+ public T Body { get; set; }
+
+ /// <summary>
+ /// How long in seconds to keep the item in the cache before it is deleted. Default is 604,800 seconds (7 days). Maximum is 2,592,000 seconds (30 days).
+ /// </summary>
+ [JsonProperty("expires_in")]
+ [DefaultValue(0)]
+ public long ExpiresIn { get; set; }
+
+ /// <summary>
+ /// If set to true, only set the item if the item is already in the cache. If the item is not in the cache, do not create it.
+ /// </summary>
+ [JsonProperty("replace")]
+ [DefaultValue(false)]
+ public bool Replace { get; set; }
+
+ /// <summary>
+ /// If set to true, only set the item if the item is not already in the cache. If the item is in the cache, do not overwrite it.
+ /// </summary>
+ [JsonProperty("add")]
+ [DefaultValue(false)]
+ public bool Add { get; set; }
+ }
+}
View
155 IronCache/IronCache.cs
@@ -0,0 +1,155 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using io.iron.ironcache.Data;
+using Newtonsoft.Json;
+
+namespace io.iron.ironcache
+{
+ public class IronCache
+ {
+ private Client _client;
+ private static string _core = "caches";
+
+ public IronCache(string projectId, string token)
+ {
+ _client = new Client(projectId, token, "cache-aws-us-east-1.iron.io");
+ }
+
+ public IList<Cache> Caches()
+ {
+ string method = _core;
+ var response = _client.get(method);
+ var caches = JsonConvert.DeserializeObject<List<Cache>>(response) ?? new List<Cache>();
+ return caches as IList<Cache>;
+ }
+
+ /// <summary>
+ /// Only set the item if the item is not already in the cache. If the item is in the cache, do not overwrite it.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="cache">Name of the cache</param>
+ /// <param name="key">The key to store the item under in the cache</param>
+ /// <param name="value">Item to be stored</param>
+ /// <param name="expiresIn"> How long in seconds to keep the item in the cache before it is deleted. Default is 604,800 seconds (7 days). Maximum is 2,592,000 seconds (30 days).</param>
+ public void Add<T>(string cache, string key, T value, int expiresIn = 0)
+ {
+ Put<T>(cache, key, value, true, false, expiresIn);
+ }
+
+ /// <summary>
+ /// Sets the value at the key in the cache
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="cache">Name of the cache</param>
+ /// <param name="key">The key to store the item under in the cache</param>
+ /// <param name="value">Item to be stored</param>
+ /// <param name="expiresIn"> How long in seconds to keep the item in the cache before it is deleted. Default is 604,800 seconds (7 days). Maximum is 2,592,000 seconds (30 days).</param>
+ public void Set<T>(string cache, string key, T value, int expiresIn = 0)
+ {
+ Put<T>(cache, key, value, false, false, expiresIn);
+ }
+
+ /// <summary>
+ /// Only set the item if the item is already in the cache. If the item is not in the cache, do not create it.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="cache"></param>
+ /// <param name="key">The key to store the item under in the cache</param>
+ /// <param name="value">Item to be stored</param>
+ /// <param name="expiresIn"> How long in seconds to keep the item in the cache before it is deleted. Default is 604,800 seconds (7 days). Maximum is 2,592,000 seconds (30 days).</param>
+ public void Replace<T>(string cache, string key, T value, int expiresIn = 0)
+ {
+ Put<T>(cache, key, value, false, true, expiresIn);
+ }
+
+ /// <summary>
+ /// Puts a value into the cache for the provided key.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="cache">Name of the cache</param>
+ /// <param name="key">The key to store the item under in the cache</param>
+ /// <param name="value">Item to be stored</param>
+ /// <param name="add">If set to true, only set the item if the item is not already in the cache. If the item is in the cache, do not overwrite it.</param>
+ /// <param name="replace">If set to true, only set the item if the item is already in the cache. If the item is not in the cache, do not create it.</param>
+ /// <param name="expiresIn"> How long in seconds to keep the item in the cache before it is deleted. Default is 604,800 seconds (7 days). Maximum is 2,592,000 seconds (30 days).</param>
+ public void Put<T>(string cache, string key, T value, bool add = false, bool replace = false, int expiresIn = 0)
+ {
+ if (add && replace) throw new ArgumentException("add and replace cannot both be true.");
+ string endpoint = string.Format("{0}/{1}/items/{2}", _core, cache, key);
+ var item = new Item<T>() { Body = value, Add = add, Replace = replace, ExpiresIn = expiresIn };
+ var body = JsonConvert.SerializeObject(item);
+ var response = _client.put(endpoint, body);
+ }
+
+ /// <summary>
+ /// Internal Get method
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="cache"> The name of the cache the item belongs to.</param>
+ /// <param name="key">The key the item is stored under in the cache.</param>
+ /// <param name="defaultValue">Value to return if not found</param>
+ /// <returns>Value at the key or the default value if not found</returns>
+ public T Get<T>(string cache, string key, T defaultValue = default(T))
+ {
+ string endpoint = string.Format("{0}/{1}/items/{2}", _core, cache, key);
+ try
+ {
+ var response = _client.get(endpoint);
+ var item = JsonConvert.DeserializeObject<CacheItem<T>>(response);
+ return item.Value;
+ }
+ catch (System.Web.HttpException we)
+ {
+ if (we.GetHttpCode() == 404)
+ {
+ return defaultValue;
+ }
+ throw we;
+ }
+ }
+
+ public void Remove(string cache, string key)
+ {
+ string endpoint = string.Format("{0}/{1}/items/{2}", _core, cache, key);
+
+ var response = _client.delete(endpoint);
+ }
+
+ /// <summary>
+ /// Increment an existing integer
+ /// </summary>
+ /// <param name="cache">Cache Name</param>
+ /// <param name="key">Key to lookkup</param>
+ /// <param name="amount">amount to increment (decrement) value at the specified key</param>
+ /// <returns>value after increment</returns>
+ /// <exception cref="System.Collections.Generic.KeyNotFoundException"></exception>
+ /// <exception cref="System.InvalidOperationException"></exception>
+ public int Increment(string cache, string key, int amount)
+ {
+ string endpoint = string.Format("{0}/{1}/items/{2}/increment", _core, cache, key);
+
+ var body = "{" + string.Format("\"amount\": {0}", amount) + "}";
+ try
+ {
+ var response = _client.post(endpoint, body);
+
+ var increment = JsonConvert.DeserializeObject<Dictionary<string, string>>(response);
+ return int.Parse(increment["value"]);
+ }
+ catch (System.Web.HttpException e)
+ {
+ if (e.GetHttpCode() == 404)
+ {
+ throw new KeyNotFoundException(e.Message);
+ }
+ if (e.GetHttpCode() == 400)
+ {
+ throw new InvalidOperationException(e.Message);
+ }
+ throw e;
+ }
+ }
+ }
+}
View
68 IronCache/IronCache.csproj
@@ -0,0 +1,68 @@
+<?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>{B4154E3E-0BDD-43C3-887C-A4595C062EA6}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>io.iron.ironcache</RootNamespace>
+ <AssemblyName>IronCache</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="Newtonsoft.Json">
+ <HintPath>packages\Newtonsoft.Json.4.5.5\lib\net40\Newtonsoft.Json.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Configuration" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Web" />
+ <Reference Include="System.Web.Extensions" />
+ <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="Client.cs" />
+ <Compile Include="Data\Cache.cs" />
+ <Compile Include="Data\CacheItem.cs" />
+ <Compile Include="Data\Error.cs" />
+ <Compile Include="Data\Item.cs" />
+ <Compile Include="IronCache.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </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>
View
36 IronCache/IronCache.sln
@@ -0,0 +1,36 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronCache", "IronCache.csproj", "{B4154E3E-0BDD-43C3-887C-A4595C062EA6}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2897D61D-3603-4CCD-8C4E-EC457A8A612C}"
+ ProjectSection(SolutionItems) = preProject
+ IronCache.vsmdi = IronCache.vsmdi
+ Local.testsettings = Local.testsettings
+ TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
+ EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronCacheTests", "IronCacheTests\IronCacheTests.csproj", "{39330314-089C-46AE-A46C-7E3E73DCFC11}"
+EndProject
+Global
+ GlobalSection(TestCaseManagementSettings) = postSolution
+ CategoryFile = IronCache.vsmdi
+ EndGlobalSection
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B4154E3E-0BDD-43C3-887C-A4595C062EA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B4154E3E-0BDD-43C3-887C-A4595C062EA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B4154E3E-0BDD-43C3-887C-A4595C062EA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B4154E3E-0BDD-43C3-887C-A4595C062EA6}.Release|Any CPU.Build.0 = Release|Any CPU
+ {39330314-089C-46AE-A46C-7E3E73DCFC11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {39330314-089C-46AE-A46C-7E3E73DCFC11}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {39330314-089C-46AE-A46C-7E3E73DCFC11}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {39330314-089C-46AE-A46C-7E3E73DCFC11}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
View
BIN  IronCache/IronCache.sln.docstates.suo
Binary file not shown
View
BIN  IronCache/IronCache.suo
Binary file not shown
View
6 IronCache/IronCache.vsmdi
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
+ <TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
+ <RunConfiguration id="4b7c68e4-423e-42d0-8179-93df3efa5ed5" name="Local" storage="local.testsettings" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ </TestList>
+</TestLists>
View
7 IronCache/IronCacheTests/App.config
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <appSettings>
+ <add key="IRONIO_PROJECT_ID" value="" />
+ <add key="IRONIO_TOKEN" value="" />
+ </appSettings>
+</configuration>
View
164 IronCache/IronCacheTests/IronCacheTest.cs
@@ -0,0 +1,164 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+using io.iron.ironcache;
+using io.iron.ironcache.Data;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace IronCacheTests
+{
+ /// <summary>
+ ///This is a test class for IronCacheTest and is intended
+ ///to contain all IronCacheTest Unit Tests
+ ///</summary>
+ [TestClass()]
+ public class IronCacheTest
+ {
+ string _projectId, _token;
+
+ public IronCacheTest()
+ {
+ _projectId = ConfigurationManager.AppSettings["IRONIO_PROJECT_ID"];
+ _token = ConfigurationManager.AppSettings["IRONIO_TOKEN"];
+ }
+
+ private TestContext testContextInstance;
+
+ /// <summary>
+ ///Gets or sets the test context which provides
+ ///information about and functionality for the current test run.
+ ///</summary>
+ public TestContext TestContext
+ {
+ get
+ {
+ return testContextInstance;
+ }
+ set
+ {
+ testContextInstance = value;
+ }
+ }
+
+ #region Additional test attributes
+
+ #endregion Additional test attributes
+
+ /// <summary>
+ ///A test for IronCache Constructor
+ ///</summary>
+ [TestMethod()]
+ public void IronCacheConstructorTest()
+ {
+ string projectId = _projectId;
+ string token = _token;
+ IronCache target = new IronCache(projectId, token);
+
+ Assert.IsNotNull(target);
+ }
+
+ /// <summary>
+ ///A test for Caches
+ ///</summary>
+ [TestMethod()]
+ public void CachesTest()
+ {
+ string projectId = _projectId;
+ string token = _token;
+ IronCache target = new IronCache(projectId, token);
+ var expected = 1;
+ IList<Cache> actual;
+ actual = target.Caches();
+ Assert.IsNotNull(actual);
+ Assert.AreEqual(expected, actual.Count);
+ }
+
+ [TestMethod()]
+ public void AddGetTest()
+ {
+ string projectId = _projectId;
+ string token = _token;
+ IronCache target = new IronCache(projectId, token);
+
+ string value = "this is some arbitrary text";
+ string key = "this is an arbitrary key";
+ string cache = "test_cache";
+
+ target.Put(cache, key, value);
+ var actual = target.Get<string>(cache, key);
+
+ Assert.IsNotNull(actual);
+ Assert.AreEqual(value, actual);
+ }
+
+ [TestMethod()]
+ public void AddGetIntTest()
+ {
+ string projectId = _projectId;
+ string token = _token;
+ IronCache target = new IronCache(projectId, token);
+
+ int value = 10;
+ string key = "this is an arbitrary key";
+ string cache = "test_cache";
+
+ target.Put(cache, key, value);
+ var actual = target.Get<int?>(cache, key);
+
+ Assert.IsNotNull(actual);
+ Assert.AreEqual(value, actual);
+ }
+
+ [TestMethod()]
+ public void GetMissingValueTest()
+ {
+ string projectId = _projectId;
+ string token = _token;
+ IronCache target = new IronCache(projectId, token);
+
+ string key = "this is an arbitrary key";
+ string cache = "test_cache";
+
+ target.Remove(cache, key);
+ var actual = target.Get<string>(cache, key);
+ Assert.IsNull(actual);
+ }
+
+ [TestMethod()]
+ public void IncrementNonExistingTest()
+ {
+ string projectId = _projectId;
+ string token = _token;
+ IronCache target = new IronCache(projectId, token);
+
+ string key = "82de17a0-cab9-45a5-a851-bccb210a9e1f";
+ string cache = "test_cache";
+ target.Remove(cache, key);
+ try
+ {
+ var actual = target.Increment(cache, key, 1);
+ Assert.Fail();
+ }
+ catch (KeyNotFoundException knf)
+ {
+ }
+ }
+
+ [TestMethod()]
+ public void IncrementExistingIntegerTest()
+ {
+ string projectId = _projectId;
+ string token = _token;
+ IronCache target = new IronCache(projectId, token);
+
+ string key = "cf435dc2-7f12-4f37-94c2-26077b3cd414"; // random unique identifier
+ string cache = "test_cache";
+ target.Remove(cache, key);
+ target.Put(cache, key, 0, false, false, 10);
+ var expected = 1;
+ var actual = target.Increment(cache, key, 1);
+ Assert.AreEqual(expected, actual);
+ }
+ }
+}
View
80 IronCache/IronCacheTests/IronCacheTests.csproj
@@ -0,0 +1,80 @@
+<?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>{39330314-089C-46AE-A46C-7E3E73DCFC11}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>IronCacheTests</RootNamespace>
+ <AssemblyName>IronCacheTests</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.CSharp" />
+ <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ <Reference Include="Newtonsoft.Json">
+ <HintPath>..\packages\Newtonsoft.Json.4.5.5\lib\net40\Newtonsoft.Json.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Configuration" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="System.Web" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Xml.Linq" />
+ </ItemGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="IronCacheTest.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\IronCache.csproj">
+ <Project>{B4154E3E-0BDD-43C3-887C-A4595C062EA6}</Project>
+ <Name>IronCache</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config">
+ <SubType>Designer</SubType>
+ </None>
+ </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
35 IronCache/IronCacheTests/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
+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("IronCacheTests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("IronCacheTests")]
+[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("88f04a76-000a-431d-84e3-0377ba63d98a")]
+
+// 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.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
View
10 IronCache/Local.testsettings
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TestSettings name="Local" id="4b7c68e4-423e-42d0-8179-93df3efa5ed5" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
+ <Description>These are default test settings for a local test run.</Description>
+ <Deployment enabled="false" />
+ <Execution>
+ <TestTypeSpecific />
+ <AgentRule name="Execution Agents">
+ </AgentRule>
+ </Execution>
+</TestSettings>
View
36 IronCache/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("IronCache")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("IronCache")]
+[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("c04effbd-a29b-40f6-91e0-24237a7dbc89")]
+
+// 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")]
View
9 IronCache/TraceAndTestImpact.testsettings
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TestSettings name="Trace and Test Impact" id="b68caf66-6a12-4ceb-9282-e0153ec2ed6e" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
+ <Description>These are test settings for Trace and Test Impact.</Description>
+ <Execution>
+ <TestTypeSpecific />
+ <AgentRule name="Execution Agents">
+ </AgentRule>
+ </Execution>
+</TestSettings>
View
4 IronCache/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Newtonsoft.Json" version="4.5.5" />
+</packages>
View
BIN  IronCache/packages/Newtonsoft.Json.4.5.5/Newtonsoft.Json.4.5.5.nupkg
Binary file not shown
View
BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/net20/Newtonsoft.Json.dll
Binary file not shown
View
8,181 IronCache/packages/Newtonsoft.Json.4.5.5/lib/net20/Newtonsoft.Json.xml
8,181 additions, 0 deletions not shown
View
BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/net35/Newtonsoft.Json.dll
Binary file not shown
View
7,317 IronCache/packages/Newtonsoft.Json.4.5.5/lib/net35/Newtonsoft.Json.xml
7,317 additions, 0 deletions not shown
View
BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/net40/Newtonsoft.Json.dll
Binary file not shown
View
7,560 IronCache/packages/Newtonsoft.Json.4.5.5/lib/net40/Newtonsoft.Json.xml
7,560 additions, 0 deletions not shown
View
BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/sl3-wp/Newtonsoft.Json.dll
Binary file not shown
View
6,860 IronCache/packages/Newtonsoft.Json.4.5.5/lib/sl3-wp/Newtonsoft.Json.xml
6,860 additions, 0 deletions not shown
View
BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/sl4-windowsphone71/Newtonsoft.Json.dll
Binary file not shown
View
6,860 IronCache/packages/Newtonsoft.Json.4.5.5/lib/sl4-windowsphone71/Newtonsoft.Json.xml
6,860 additions, 0 deletions not shown
View
BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/sl4/Newtonsoft.Json.dll
Binary file not shown
View
6,882 IronCache/packages/Newtonsoft.Json.4.5.5/lib/sl4/Newtonsoft.Json.xml
6,882 additions, 0 deletions not shown
View
BIN  IronCache/packages/Newtonsoft.Json.4.5.5/lib/winrt45/Newtonsoft.Json.dll
Binary file not shown
View
7,103 IronCache/packages/Newtonsoft.Json.4.5.5/lib/winrt45/Newtonsoft.Json.xml
7,103 additions, 0 deletions not shown
View
4 IronCache/packages/repositories.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<repositories>
+ <repository path="..\packages.config" />
+</repositories>
Please sign in to comment.
Something went wrong with that request. Please try again.