Moving micasa 1.5 trunk to Novell forge.
This commit is contained in:
123
c_micasad/test/cache/TestKeyChain.cs
vendored
Normal file
123
c_micasad/test/cache/TestKeyChain.cs
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
#if DEBUG
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
//using System.InvalidOperationException;
|
||||
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using sscs.common;
|
||||
|
||||
namespace sscs.cache
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestKeyChain
|
||||
{
|
||||
|
||||
Secret mysec;
|
||||
KeyChain mykc;
|
||||
string secval;
|
||||
byte[] secbyte;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Init()
|
||||
{
|
||||
|
||||
mykc = new KeyChain("TestingID");
|
||||
|
||||
secval= "novell123";
|
||||
secbyte = Encoding.ASCII.GetBytes(secval);
|
||||
mysec = new Secret();
|
||||
mysec.SetKey("testkey");
|
||||
mysec.SetValue(secbyte);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestAddSecret()
|
||||
{
|
||||
mykc.AddSecret(mysec);
|
||||
Secret returnsecret = mykc.GetSecret("testkey");
|
||||
|
||||
Assert.AreEqual("novell123", Encoding.ASCII.GetString(returnsecret.GetValue("testkey")));
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestAddSecretWithDup()
|
||||
{
|
||||
//Add one more with same secret id
|
||||
byte[] newvalue = Encoding.ASCII.GetBytes("miCASA");
|
||||
mysec.SetValue(newvalue);
|
||||
|
||||
mykc.AddSecret(mysec);
|
||||
Secret returnsecret = mykc.GetSecret("testkey");
|
||||
|
||||
Assert.AreEqual("miCASA", Encoding.ASCII.GetString(returnsecret.GetValue("testkey")));
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(SecretNotFoundException))]
|
||||
public void TestRemoveSecret()
|
||||
{
|
||||
|
||||
mykc.RemoveSecret("testkey");
|
||||
|
||||
//Try and get the same.
|
||||
//Secret sec = mykc.GetSecret("testkey");
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(InvalidOperationException))]
|
||||
public void TestGetAllSecretsWhenNone()
|
||||
{
|
||||
// IDictionaryEnumerator myenum = (IDictionaryEnumerator)mykc.GetAllSecrets();
|
||||
//Object temp = myenum.Current;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetAllSecrets()
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
byte[] val1 = Encoding.ASCII.GetBytes("val1");
|
||||
byte[] val2 = Encoding.ASCII.GetBytes("val2");
|
||||
byte[] val3 = Encoding.ASCII.GetBytes("val3");
|
||||
|
||||
Secret sec1 = new Secret("key1", val1);
|
||||
Secret sec2 = new Secret("key2", val2);
|
||||
Secret sec3 = new Secret("key3", val3);
|
||||
|
||||
mykc.AddSecret(sec1);
|
||||
mykc.AddSecret(sec2);
|
||||
mykc.AddSecret(sec3);
|
||||
|
||||
IDictionaryEnumerator myenum =(IDictionaryEnumerator) mykc.GetAllSecrets();
|
||||
|
||||
while(myenum.MoveNext())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
Assert.AreEqual(3, mykc.GetNumSecrets());
|
||||
Assert.AreEqual(3, count);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user