public virtual void CanAddAndGetKey() { using (var uow = DataService.StartUnitOfWork()) { var key = new DataProtectionKeyEntity { FriendlyName = "MyName", XmlData = new XElement("test").ToString() }; uow.DataProtectionKeyRepository.Add(key); Assert.AreEqual(key.FriendlyName, uow.DataProtectionKeyRepository.Get(key.Id).FriendlyName); } }
/// <summary> Adds a top-level XML element to the repository. </summary> /// <remarks> /// The 'friendlyName' parameter must be unique if specified. For instance, it could be the /// id of the key being stored. /// </remarks> /// <param name="element"> The element to add. </param> /// <param name="friendlyName"> An optional name to be associated with the XML element. For /// instance, if this repository stores XML files on disk, the /// friendly name may be used as part of the file name. Repository /// implementations are not required to observe this parameter even /// if it has been provided by the caller. </param> public void StoreElement(XElement element, string friendlyName) { using (var uow = _dataService.StartUnitOfWork()) { var existing = uow.DataProtectionKeyRepository.GetAll().SingleOrDefault(k => k.FriendlyName == friendlyName); if (existing != null) { // just update existing.XmlData = element.ToString(); uow.DataProtectionKeyRepository.Update(existing); } else { // save it var entity = new DataProtectionKeyEntity() { FriendlyName = friendlyName, XmlData = element.ToString() }; uow.DataProtectionKeyRepository.Add(entity); } uow.Commit(); } }