Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

Why Certificate Dialogs Don't Show in Unit Tests

$
0
0

Hello All,

I found what seems to be a bug, but I'm not sure.  I have several Unit tests that I ported from VS 2010 and some of them prompt the user for certificate credentials (meaning choosing a cert and granting the Unit Test permission to sing/decrypt data). 

My issue is now that I am using VS 2012, running on Windows 2012, I don't see the dialog anymore and the test method halts indefinitely.  No error information is shown at all. 

Any idea why this new behavior exists in VS 2012 and/or Windows 2012? 

Example Code

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Security.Cryptography.X509Certificates;

namespace UnitTestProject1 {

	[TestClass]
	public class UnitTest1 {

		[TestMethod]
		public void TestMethod1() {

			var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
			store.Open(OpenFlags.ReadOnly);
			var selectedCertificates = X509Certificate2UI
				.SelectFromCollection(store.Certificates, "Select Certificate", "Please select a certificate.", X509SelectionFlag.SingleSelection);

			// never gets here because UI is frozen
			Assert.IsTrue(selectedCertificates.Count > 0);
		}
	}
}

Assumptions

  1. You have at least one cert in your My store
  2. You added the System.Security.dll to your unit test project


- Rashad Rivera www.omegusprime.com



Viewing all articles
Browse latest Browse all 21115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>