public void GeSingleByName() { List<Contact> contacts = _dataAccess.GetAll<Contact>(); Assert.IsTrue(contacts.Count == 0); List<MasterLogin> masterLogins = _dataAccess.GetAll<MasterLogin>(); Assert.IsTrue(masterLogins.Count == 0); var hybridEncrypter = new HybridRsaAes(); hybridEncrypter.AssignNewRSAKeys(); var contact = new Contact { Name = "Marcel", PublicKey = hybridEncrypter.GetPublicRSAKey() }; _dataAccess.Insert(contact); hybridEncrypter.AssignNewRSAKeys(); var contact2 = new Contact { Name = "Mario", PublicKey = hybridEncrypter.GetPublicRSAKey() }; _dataAccess.Insert(contact2); contacts = _dataAccess.GetAll<Contact>(); Assert.IsTrue(contacts.Count == 2); var contact3 = _dataAccess.GetSingleByName<Contact>("Marcel"); Assert.IsTrue(contact3 != null); Assert.IsTrue(contact3.Name == "Marcel"); var salt = PBKDF2Impl.GenerateSalt(); hybridEncrypter = new HybridRsaAes(); hybridEncrypter.AssignNewRSAKeys(); var materLogin = new MasterLogin { Name = "MasterMan", Password = PBKDF2Impl.HashPassword(Encoding.UTF8.GetBytes("password123"), salt), Salt = salt, PrivateKey = hybridEncrypter.GetPrivateRSAKeyAsXml(), PublicKey = hybridEncrypter.GetPublicRSAKey() }; _dataAccess.Insert(materLogin); masterLogins = _dataAccess.GetAll<MasterLogin>(); Assert.IsTrue(masterLogins.Count == 1); var materLogin2 = _dataAccess.GetSingleByName<MasterLogin>("MasterMan"); Assert.IsTrue(materLogin2 != null); Assert.IsTrue(materLogin2.Name == "MasterMan"); }
private void Save(object obj) { _logger.Info("save contact"); if (_importKeyFileSuccess) { _logger.Info("check database for contact"); var contact = _database.GetSingleByName<Contact>(OriginalName); if (contact != null) { _logger.Info("contact exists"); contact.Name = Name; contact.PublicKey = PublicKey; _logger.Info("update in database"); _database.Update(contact); } else { _logger.Info("contact do not exists -> create new one"); contact = new Contact { Name = Name, PublicKey = PublicKey }; _logger.Info("insert in database"); _database.Insert(contact); } _messenger.Send(new SaveContactMsg()); _logger.Info("try to close view"); var view = obj as ICloseable; if (view != null) { view.Close(); _logger.Info("view closed"); } } else { _logger.Error("something went wrong with the public key"); } }
public void Update() { List<Contact> contacts = _dataAccess.GetAll<Contact>(); Assert.IsTrue(contacts.Count == 0); var hybridEncrypter = new HybridRsaAes(); hybridEncrypter.AssignNewRSAKeys(); var contact = new Contact { Name = "Marcel", PublicKey = hybridEncrypter.GetPublicRSAKey() }; _dataAccess.Insert(contact); contacts = _dataAccess.GetAll<Contact>(); Assert.IsTrue(contacts.Count == 1); Contact contact2 = contacts[0]; hybridEncrypter.AssignNewRSAKeys(); contact2.Name = "Marcel.Elz"; contact2.PublicKey = hybridEncrypter.GetPublicRSAKey(); _dataAccess.Update(contact2); contacts = _dataAccess.GetAll<Contact>(); Assert.IsTrue(contacts.Count == 1); Assert.IsTrue(contacts[0].Name == "Marcel.Elz"); }
public ContactSelectedMsg(Contact contact) { Contact = contact; }