Skip to content

Instantly share code, notes, and snippets.

@rockarts
Created August 7, 2016 21:37
Show Gist options
  • Select an option

  • Save rockarts/5350ed95b1de8c861eea0fa574283861 to your computer and use it in GitHub Desktop.

Select an option

Save rockarts/5350ed95b1de8c861eea0fa574283861 to your computer and use it in GitHub Desktop.
Simple In-Memory Repo for Testing
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
namespace UnitTestProject1
{
[TestClass]
public class UrlRepositoryTest
{
[TestMethod]
public void ShouldAddKeyAndRetrieveKey()
{
UrlRepository repository = new UrlRepository();
int key = repository.Add("http://www.github.com");
Assert.IsTrue(key == 1);
UrlRepository repo2 = new UrlRepository();
int key2 = repository.Add("https://gist.github.com/rockarts/0c2539a8c64dc81e1c903133ab4b3e05");
Assert.IsTrue(key2 == 2);
Assert.AreEqual("http://www.github.com", repo2.Get(1));
}
}
public class UrlRepository
{
private static Dictionary<int, string> database = new Dictionary<int, string>();
public int Add(string url)
{
int key = database.Count + 1;
database.Add(key, url);
return key;
}
public string Get(int key)
{
return database[key];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment