public void WhenUpdatingAnAccount_ItShouldBeUpdated() { // Given var ciphertextDatastore = CreateReloadedPopulatedWithFakeData(); var fakeCiphertextDto1 = ciphertextDatastore.GetAll().First(); var originalCount = ciphertextDatastore.GetAll().Count(); var updatedCiphertextDto = new CiphertextDto(); // When updatedCiphertextDto.Id = fakeCiphertextDto1.Id; updatedCiphertextDto.Ciphertext = Convert.FromBase64String("rdLQpiBIHfXhZTdZMso8CDrj0KOY9Z+KFsgRjscuSoE="); updatedCiphertextDto.InitializationVector = Convert.FromBase64String("fAnP53b7vCuC2aabHQZvuA=="); updatedCiphertextDto.Salt = Convert.FromBase64String("wu6rj5K00UFiakRwhzlbrHGD3AyK5bzW"); ciphertextDatastore.Save(updatedCiphertextDto); // Then ciphertextDatastore.GetAll(CiphertextStatus.Active) .Should().Contain(account => account.Id == updatedCiphertextDto.Id); ciphertextDatastore.GetAllIds() .Should().HaveCount(originalCount); VerifyThatStoredDataMatches(ciphertextDatastore, updatedCiphertextDto); }
private void VerifyThatStoredDataMatches(CiphertextDatastoreBase ciphertextDatastore, CiphertextDto CiphertextDto) { var accountId = CiphertextDto.Id; ciphertextDatastore.GetAllIds() .Should().Contain(id => id.Equals(accountId)); ciphertextDatastore.GetAll() .Should().Contain(datastoreCiphertextDto => accountId == datastoreCiphertextDto.Id); ciphertextDatastore.Get(accountId).Equals(CiphertextDto) .Should().BeTrue(); ciphertextDatastore.Get(accountId).Deleted .Should().Be(CiphertextDto.Deleted); ciphertextDatastore.Get(accountId).Id .Should().Be(CiphertextDto.Id); ciphertextDatastore.Get(accountId).Ciphertext .Should().Equal(CiphertextDto.Ciphertext); ciphertextDatastore.Get(accountId).InitializationVector .Should().Equal(CiphertextDto.InitializationVector); ciphertextDatastore.Get(accountId).Salt .Should().Equal(CiphertextDto.Salt); }
protected override void InternalSave(CiphertextDto ciphertextDto) { _jsonCiphertexts.Ciphertexts[ciphertextDto.Id] = JsonConvert.SerializeObject(ciphertextDto); lock (this) { _persist(JsonConvert.SerializeObject(_jsonCiphertexts)); } }