public async Task SafeString_MultipleCharsAdded_MarshalsToExpected() { // Arrange const string expected = "test"; var sut = new SafeString(); // Act await sut.AppendAsync("t"); await sut.AppendAsync("es"); await sut.AppendAsync('t'); // Assert var actual = (await sut.RevealDecryptedStringAsync()).String; Assert.That(actual, Is.EqualTo(expected)); }
public async Task SafeString_TextCanBeRevealedTwice() { // Arrange const string expected = "test"; var sut = new SafeString(); await sut.AppendAsync(expected); // Act var revealed = await RevealAsync(sut); var revealedAgain = await RevealAsync(sut); // Assert Assert.AreEqual(expected, revealed); Assert.AreEqual(expected, revealedAgain);
public async Task EqualsAsync_TwoStringsWithDifferentLength_ReturnsFalse() { // Arrange var sut1 = new SafeString(); await sut1.AppendAsync("hej"); var sut2 = new SafeString(); await sut2.AppendAsync("sp"); // Act var equality = await sut1.EqualsAsync(sut2); var equalityOpposite = await sut2.EqualsAsync(sut1); // Assert Assert.False(equality); Assert.False(equalityOpposite); }
public async Task SafeString_ModifiedByAnotherThread_ModifiesAsExpected() { // Arrange var sut = new SafeString(); await sut.AppendAsync("test"); // Act var thread = new Thread(() => { sut.Remove(1); sut.Remove(1); }); thread.Start(); thread.Join(); // Assert var actual = (await sut.RevealDecryptedStringAsync()).String; Assert.That(actual, Is.EqualTo("tt")); }