using System;
using LeafWeb.Core.Utility;
using NUnit.Framework;

namespace LeafWeb.Core.Tests.Utility
{
	[TestFixture]
	public class MemoizerTests
	{
		[Test]
		public void ThreadsafeMemoize_Test()
		{
			Func<string, int, string> func = (a1, a2) => a1 + a2.ToString();

			var funcMem = Memoizer.ThreadsafeMemoize(func);

			var result = funcMem("hi", 1);
			Assert.That(result, Is.EqualTo("hi1"));

			var resultAgain = funcMem("hi", 1);
			Assert.That(resultAgain, Is.EqualTo("hi1"));

			var differentResult = funcMem("this", 2);
			Assert.That(differentResult, Is.EqualTo("this2"));
		}
	}
}
