public void Store(VaultRecord record) { if (vault.ContainsKey(record.Title)) { throw new TitleAlreadyPresentException(record.Title); } vault.Add(record.Title, record); }
public void Store(VaultRecord record) { var result = RetrieveVaultRecord(record.Title); if (result != null) { throw new TitleAlreadyPresentException(record.Title); } using (var sw = File.AppendText(VaultLocation)) { sw.WriteLine($"{record.Title}@{record.CipherPassword}@{record.Sign}"); } }
public void VaultsFunctionalityTest(IVault vault) { var titles = vault.GetTitles(); Assert.Empty(titles); var title = "Test"; var cipherPassword = "******"; var sign = "jo1h23o7tb120d301823801"; var record = new VaultRecord { Title = title, CipherPassword = cipherPassword, Sign = sign }; vault.Store(record); titles = vault.GetTitles(); Assert.True(titles.Count() == 1); Assert.True(titles.ElementAt(0) == title); Assert.Throws <TitleAlreadyPresentException>(() => vault.Store(record)); record = vault.Get(title); Assert.Equal(title, record.Title); Assert.Equal(cipherPassword, record.CipherPassword); Assert.Equal(sign, record.Sign); Assert.Throws <TitleNotFoundException>(() => vault.Get("Title not present")); var resultRemove = vault.Remove(title); titles = vault.GetTitles(); Assert.True(resultRemove); Assert.True(titles.Count() == 0); }