+ xs.Add (cert1);
+ Assert.AreEqual (1, xs.Certificates.Count, "Open");
+ xs.Close ();
+ Assert.AreEqual (0, xs.Certificates.Count, "Close");
+ }
+
+ [Test]
+ public void Open_Invalid ()
+ {
+ X509Store xs = new X509Store ("ReadWriteStore");
+ xs.Open ((OpenFlags) Int32.MinValue);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Open_OpenExistingOnly ()
+ {
+ new X509Store ("doesn't-exists").Open (OpenFlags.OpenExistingOnly);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Open_Store_Null ()
+ {
+ // ctor is valid (see test) but can't be opened
+ new X509Store (null).Open (OpenFlags.ReadOnly);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Open_Store_Empty ()
+ {
+ // ctor is valid (see test) but can't be opened
+ new X509Store (String.Empty).Open (OpenFlags.ReadOnly);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Remove_Null ()
+ {
+ new X509Store ().Remove (null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Remove_NotOpened ()
+ {
+ // Open wasn't called
+ new X509Store ().Remove (cert1);
+ }
+
+ [Test]
+ public void Remove_OpenReadOnly_Unexisting ()
+ {
+ X509Store xs = new X509Store ("ReadOnlyStore");
+ xs.Open (OpenFlags.ReadOnly);
+ // note: cert1 wasn't present, remove "succeed"
+ xs.Remove (cert1);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Remove_OpenReadOnly_Existing ()
+ {
+ X509Store xs = new X509Store ("ReadWriteStore");
+ xs.Open (OpenFlags.ReadWrite);
+ xs.Add (cert1);
+ xs.Close ();
+ xs.Open (OpenFlags.ReadOnly);
+ xs.Remove (cert1);
+ }
+
+ [Test]
+ public void Remove_Empty_Certificate ()
+ {
+ X509Store xs = new X509Store ("ReadWriteStore");
+ xs.Open (OpenFlags.ReadWrite);
+ // note: impossible to add cert_empty, so we add something else
+ // to be sure we'll follow the complete code path (loop) of removal
+ xs.Add (cert1);
+ xs.Remove (cert_empty);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void RemoveRange_Null ()
+ {
+ new X509Store ().RemoveRange (null);
+ }
+
+ [Test]
+ public void RemoveRange_Empty ()
+ {
+ X509Store xs = new X509Store ();
+ xs.RemoveRange (coll_empty);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void RemoveRange_NotOpened ()
+ {
+ // Open wasn't called
+ new X509Store ().RemoveRange (coll);
+ }
+
+ [Test]
+ public void RemoveRange_OpenReadOnly_Unexisting ()
+ {
+ X509Store xs = new X509Store ("ReadOnlyStore");
+ xs.Open (OpenFlags.ReadOnly);
+ // note: cert1 wasn't present, RemoveRange "succeed"
+ xs.RemoveRange (coll);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void RemoveRange_OpenReadOnly_Existing ()
+ {
+ X509Store xs = new X509Store ("ReadWriteStore");
+ xs.Open (OpenFlags.ReadWrite);
+ xs.AddRange (coll);
+ xs.Close ();
+ xs.Open (OpenFlags.ReadOnly);
+ xs.RemoveRange (coll);
+ }
+
+ [Test]
+ public void RemoveRange_Empty_Certificate ()
+ {
+ X509Store xs = new X509Store ("ReadWriteStore");
+ xs.Open (OpenFlags.ReadWrite);
+ // note: impossible to add cert_empty, so we add something else
+ // to be sure we'll follow the complete code path (loop) of removal
+ xs.AddRange (coll);
+ xs.RemoveRange (new X509Certificate2Collection (cert_empty));
+ }
+
+ [Test]
+ public void Collection_Add ()
+ {
+ X509Store xs = new X509Store ("ReadWriteStore");
+ xs.Certificates.Add (cert1);
+ Assert.AreEqual (0, xs.Certificates.Count, "Not Open");