Exemplo n.º 1
0
        public void BasicEnumerateStores()
        {
            string localMachineName =
#if DESKTOP
                @"\\" + Environment.MachineName;
#else
                // Haven't found an easy way to find the local machine name in a portable assembly. You can get the environment variable,
                // but that only works if you run on desktop, not as a Windows Store App. All of the suggested alternatives for WinRT aren't available
                // in the PCL surface area. Manually putting the machine name in works.
                null;
#endif

            var localMachine = CryptoMethods.EnumerateSystemStores(SystemStoreLocation.CERT_SYSTEM_STORE_LOCAL_MACHINE);
            localMachine.Should().NotBeEmpty();

            var localMachineByName = CryptoMethods.EnumerateSystemStores(SystemStoreLocation.CERT_SYSTEM_STORE_LOCAL_MACHINE, localMachineName);

            if (localMachineName != null)
            {
                localMachineByName.Should().OnlyContain(x => x.Name.StartsWith(localMachineName, StringComparison.Ordinal), "when specifying the machine name they should come back with the name");
            }

            localMachineByName.Should().Equal(localMachine, (s1, s2) => s1.Name.EndsWith(s2.Name, StringComparison.Ordinal), "names should be the same whether or not we get local by name");
        }