Commits

Anonymous committed ed0b730

Rolling abck

  • Participants
  • Parent commits f559c85

Comments (0)

Files changed (2)

File DataStoreChallenge/DataStore.cs

 using System;
+using System.Collections.Generic;
 using System.Linq;
 using Microsoft.FSharp.Collections;
 using Microsoft.FSharp.Core;
         /// </summary>
         private FSharpMap<TKey, TValue> m_Data = new FSharpMap<TKey, TValue>(Enumerable.Empty<Tuple<TKey, TValue>>());
 
+        private readonly Stack<FSharpMap<TKey, TValue>> m_Transactions = new Stack<FSharpMap<TKey, TValue>>();
+
         public void Set(TKey key, TValue value)
         {
             m_Data = m_Data.Add(key, value);
         {
             m_Data = m_Data.Remove(key);
         }
+
+        public void Begin()
+        {
+            m_Transactions.Push(m_Data);
+        }
+
+        public void Rollback()
+        {
+            m_Data = m_Transactions.Pop();
+        }
     }
 }

File DataStoreChallenge/Tests/DataStoreTests.cs

             m_DataStore.UnSet("hello");
             Assert.That(m_DataStore.Get("hello"), Is.Null);
         }
+
+        [Test]
+        public void TransactionRollback()
+        {
+            m_DataStore.Begin();
+            m_DataStore.Set("hello", "world");
+            Assert.That(m_DataStore.Get("hello"), Is.EqualTo("world"));
+            m_DataStore.Rollback();
+            Assert.That(m_DataStore.Get("hello"), Is.Null);
+        }
     }
 }