diff API/Factories/AbstractNativeWarFoundryFactoryTest.cs @ 165:453640610ef9

Re #94: Loading files is too slow * Add unit test to check loading time - we'll allow failure to be 10x slower
author IBBoard <dev@ibboard.co.uk>
date Tue, 06 Sep 2011 20:28:17 +0100
parents
children 6b9e86d4be95
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Factories/AbstractNativeWarFoundryFactoryTest.cs	Tue Sep 06 20:28:17 2011 +0100
@@ -0,0 +1,34 @@
+// This file (AbstractNativeWarFoundryFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
+// 
+// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using NUnit.Framework;
+using IBBoard.WarFoundry.API.Factories.Mock;
+using System.Diagnostics;
+using NUnit.Framework.SyntaxHelpers;
+using System.IO;
+
+namespace IBBoard.WarFoundry.API.Factories
+{
+	[TestFixture]
+	public class AbstractNativeWarFoundryFactoryTest
+	{
+		[Test]
+		public void Bug94TestLoadingTimesForNonZipFiles()
+		{
+			MockNativeWarFoundryFactory factory = new MockNativeWarFoundryFactory();
+			Stopwatch sw = Stopwatch.StartNew();
+			factory.CreateObjectsFromFile(new FileInfo("testdata/Test.race"));
+			sw.Stop();
+			long successElapsed = sw.ElapsedMilliseconds;
+			sw.Reset();
+			sw.Start();
+			factory.CreateObjectsFromFile(new FileInfo("testdata/TextFileWithWrongExtension.race"));
+			sw.Stop();
+			long failedElapsed = sw.ElapsedMilliseconds;
+			long timeRatio = failedElapsed / successElapsed;
+			Assert.That(timeRatio, Is.LessThan(10));
+		}
+	}
+}
+