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 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. 3
0
        private static ObjectClassMock CreateObjectClass([NotNull] string textFieldName,
                                                         out int textFieldIndex)
        {
            var result = new ObjectClassMock(1, "testtable");

            result.AddField(FieldUtils.CreateTextField(textFieldName, 500));

            textFieldIndex = result.FindField(textFieldName);
            Assert.GreaterOrEqual(textFieldIndex, 0);

            return(result);
        }
Esempio n. 4
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. 5
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. 6
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);
			}
		}