Esempio n. 1
0
		public void CanHandleSpecialFieldValuesForUrls()
		{
			const string urlFieldName = "URL";

			var objectClass = new ObjectClassMock(1, "testtable");

			objectClass.AddField(urlFieldName, esriFieldType.esriFieldTypeString);
			int urlFieldIndex = objectClass.FindField(urlFieldName);
			Assert.IsTrue(urlFieldIndex >= 0);

			IObject rowWithEmptyValue = CreateRow(objectClass, 1, urlFieldIndex, string.Empty);
			IObject rowWithNullValue = CreateRow(objectClass, 2, urlFieldIndex, null);
			IObject rowWithBlanksOnlyValue = CreateRow(objectClass, 3, urlFieldIndex, "  ");

			var errorCount = 0;

			using (
				var webServer = new WebServer(SendHeadResponse,
				                              "http://localhost:8080/doesnotmatter/"))
			{
				webServer.Run();

				var test = new QaValidUrls(objectClass, urlFieldName);
				var runner = new QaTestRunner(test);

				errorCount += runner.Execute(rowWithEmptyValue);
				errorCount += runner.Execute(rowWithNullValue);
				errorCount += runner.Execute(rowWithBlanksOnlyValue);
			}

			Assert.AreEqual(0, errorCount);
			Assert.AreEqual(0, _webRequestCounts);
		}
Esempio n. 2
0
		public void CrashesIfInvalidExpression()
		{
			const string url = "http://localhost:8080/test/";

			var objectClass = new ObjectClassMock(1, "testtable");

			QaValidUrls test = null;
			using (var webServer = new WebServer(SendHeadResponse, url))
			{
				webServer.Run();

				try
				{
					test = new QaValidUrls(objectClass, "blah(blah)");

					Assert.Fail("Exception expected for invalid expression");
				}
				catch (ArgumentException e)
				{
					Console.WriteLine(e);
				}
			}

			Assert.IsNull(test);
		}
Esempio n. 3
0
		public void CrashesIfUnexistingField()
		{
			const string url = "http://localhost:8080/test/";

			var objectClass = new ObjectClassMock(1, "testtable");

			QaValidUrls test = null;
			using (var webServer = new WebServer(SendHeadResponse, url))
			{
				webServer.Run();

				try
				{
					test = new QaValidUrls(objectClass, "doesnotexist");

					Assert.Fail("Exception expected for non-existing field");
				}
				catch (ArgumentException e)
				{
					Console.WriteLine(e);
				}
			}

			Assert.IsNull(test);
		}
Esempio n. 4
0
		public void CanCheckOnlyDistinctUrls()
		{
			const string urlRoot = "http://localhost:8080/";
			const string urlInfixExisting = "test/";
			const string existingPrefix = urlRoot + urlInfixExisting;
			const string helloWorldHtml = "hello_world.html";
			const string urlFieldName = "URL_SUFFIX";

			var objectClass = new ObjectClassMock(1, "testtable");
			objectClass.AddField(FieldUtils.CreateTextField(urlFieldName, 500));

			int urlFieldIndex = objectClass.FindField(urlFieldName);
			Assert.IsTrue(urlFieldIndex >= 0);

			IObject rowWithExistingUrl = CreateRow(objectClass, 1, urlFieldIndex,
			                                       helloWorldHtml);

			string urlExpression = $"'{existingPrefix}' + [{urlFieldName}]";

			var errorCount = 0;
			using (var webServer = new WebServer(SendHeadResponse, existingPrefix))
			{
				webServer.Run();

				var test = new QaValidUrls(objectClass, urlExpression);
				var runner = new QaTestRunner(test);

				errorCount += runner.Execute(rowWithExistingUrl);
				errorCount += runner.Execute(rowWithExistingUrl);
				errorCount += runner.Execute(rowWithExistingUrl);
			}

			Assert.AreEqual(0, errorCount);
			Assert.AreEqual(1, _webRequestCounts);
		}
Esempio n. 5
0
		public void CanHandleHttpAndSimpleFieldExpression()
		{
			const string urlFieldName = "URL";
			const string urlRoot = "http://localhost:8080/";

			const string urlInfixExisting = "test/";
			const string urlInfixNotExisting = "doesnotexist/";
			const string existingPrefix = urlRoot + urlInfixExisting;

			var objectClass = new ObjectClassMock(1, "testtable");
			objectClass.AddField(FieldUtils.CreateTextField(urlFieldName, 500));

			int urlFieldIndex = objectClass.FindField(urlFieldName);
			Assert.IsTrue(urlFieldIndex >= 0);

			// ok as long as prefix matches:
			const string urlExistingPage = urlRoot + urlInfixExisting + "pagexy.html";

			// not ok since prefix does not match:
			const string urlNonExistingPage =
				urlRoot + urlInfixNotExisting + "doesnotexist.html";

			IObject rowWithExistingUrl = CreateRow(objectClass, 1, urlFieldIndex,
			                                       urlExistingPage);
			IObject rowWithNonExistingUrl = CreateRow(objectClass, 2, urlFieldIndex,
			                                          urlNonExistingPage);
			IObject rowWithNullUrl = CreateRow(objectClass, 2, urlFieldIndex, null);

			// the expression contains no blanks - this checks for correct tokenization
			string urlExpression = $"TRIM({urlFieldName})";

			var errorCount = 0;
			using (var webServer = new WebServer(SendHeadResponse, existingPrefix))
			{
				webServer.Run();

				var test = new QaValidUrls(objectClass, urlExpression);
				var runner = new QaTestRunner(test);

				errorCount += runner.Execute(rowWithExistingUrl);
				errorCount += runner.Execute(rowWithNonExistingUrl);
				errorCount += runner.Execute(rowWithNullUrl);
			}

			Assert.AreEqual(1, errorCount);
		}
Esempio n. 6
0
		public void CanCheckFtpServer()
		{
			// Explanation how to set up a ftp server with IIS comes here.

			const string urlFieldName = "URL";

			var objectClass = new ObjectClassMock(1, "testtable");
			objectClass.AddField(FieldUtils.CreateTextField(urlFieldName, 500));

			int urlFieldIndex = objectClass.FindField(urlFieldName);
			Assert.IsTrue(urlFieldIndex >= 0);

			const string url = "ftp://thisisnotimplementedyet.ch/test/";
			IObject ftpUrl = CreateRow(objectClass, 1, urlFieldIndex, url);

			var errorCount = 0;

			var test = new QaValidUrls(objectClass, urlFieldName);

			var runner = new QaTestRunner(test);
			errorCount += runner.Execute(ftpUrl);

			Assert.AreEqual(1, errorCount);
		}
Esempio n. 7
0
		public void CanCheckFeatureClassParallel()
		{
			const string urlRoot = "http://*****:*****@"{0:N0} ms", stopWatch.ElapsedMilliseconds);
			}

			Assert.AreEqual(4, runner.Errors.Count);
			Assert.AreEqual(32, _webRequestCounts); // 404 responses are not counted
		}
Esempio n. 8
0
		public void CanCheckFileSystem()
		{
			const string urlFieldName = "URL";
			const string nameNonExistingFile = "doesnotexist.txt";
			const string nameExistingFile = "_testfile.txt";

			// C:\Users\<USER>\AppData\Local\Temp\
			string pathNonExistingFile = Path.Combine(Path.GetTempPath(), nameNonExistingFile);
			string pathExistingFile = Path.Combine(Path.GetTempPath(), nameExistingFile);

			string uncPathExistingFile =
				Path.Combine(
					string.Format(@"\\{0}\C$\Users\{1}\AppData\Local\Temp",
					              Environment.MachineName, Environment.UserName),
					nameExistingFile);
			string uncPathExistingDirectory =
				string.Format(@"\\{0}\C$\Users", Environment.MachineName);

			string filePathExistingFile = string.Format("file:///{0}",
			                                            Path.Combine(Path.GetTempPath(),
			                                                         nameExistingFile));

			CreateTextFile(pathExistingFile);

			try
			{
				var objectClass = new ObjectClassMock(1, "testtable");
				objectClass.AddField(FieldUtils.CreateTextField(urlFieldName, 500));

				int urlFieldIndex = objectClass.FindField(urlFieldName);
				Assert.IsTrue(urlFieldIndex >= 0);

				IObject rowNonExistingFile = CreateRow(objectClass, 1, urlFieldIndex,
				                                       pathNonExistingFile);
				IObject rowExistingFile = CreateRow(objectClass, 2, urlFieldIndex,
				                                    pathExistingFile);
				IObject rowExistingFileUncPath = CreateRow(objectClass, 3, urlFieldIndex,
				                                           uncPathExistingFile);
				IObject rowExistingFilePath = CreateRow(objectClass, 4, urlFieldIndex,
				                                        filePathExistingFile);
				IObject rowExistingDirectoryPath = CreateRow(objectClass, 5, urlFieldIndex,
				                                             uncPathExistingDirectory);

				var errorCount = 0;
				var test = new QaValidUrls(objectClass, urlFieldName);
				var runner = new QaTestRunner(test);

				errorCount += runner.Execute(rowNonExistingFile);
				errorCount += runner.Execute(rowExistingFile);
				errorCount += runner.Execute(rowExistingFileUncPath);
				errorCount += runner.Execute(rowExistingFilePath);
				errorCount += runner.Execute(rowExistingDirectoryPath);

				// NOTE: 3 errors when offline (unc path to C$ on local machine cannot be resolved)
				Assert.AreEqual(1, errorCount);
				Assert.AreEqual(0, _webRequestCounts); // no http requests expected
			}
			finally
			{
				File.Delete(pathExistingFile);
			}
		}