Commits

Anonymous committed 93d3a0b

Basic set and get

Comments (0)

Files changed (3)

DataStoreChallenge/DataStore.cs

 using System;
-using System.Collections.Generic;
 using System.Linq;
-using System.Text;
+using Microsoft.FSharp.Collections;
+using Microsoft.FSharp.Core;
 
 namespace DataStoreChallenge
 {
     class DataStore
     {
+        private FSharpMap<string, string> m_Data = new FSharpMap<string, string>(Enumerable.Empty<Tuple<string, string>>());
+
+        public void Set(string key, string value)
+        {
+            m_Data = m_Data.Add(key, value);
+        }
+
+        /// <summary>
+        /// Returns null if the key didn't exist
+        /// </summary>
+        public string Get(string key)
+        {
+            FSharpOption<string> maybeValue = m_Data.TryFind(key);
+            return maybeValue == FSharpOption<string>.None ? null : maybeValue.Value;
+        }
     }
 }

DataStoreChallenge/DataStoreChallenge.csproj

   </PropertyGroup>
   <ItemGroup>
     <Reference Include="FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+    <Reference Include="nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>lib\nunit.framework.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
     <Compile Include="DataStore.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Tests\DataStoreTests.cs" />
   </ItemGroup>
+  <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.

DataStoreChallenge/Tests/DataStoreTests.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+
+namespace DataStoreChallenge.Tests
+{
+    [TestFixture]
+    class DataStoreTests
+    {
+        private DataStore m_DataStore;
+
+        [SetUp]
+        public void SetUp()
+        {
+            m_DataStore = new DataStore();
+        }
+
+        [Test]
+        public void SetAndGet()
+        {
+            m_DataStore.Set("hello", "world");
+            Assert.That(m_DataStore.Get("hello"), Is.EqualTo("world"));
+        }
+    }
+}