public void IsNullOrEmpty_ForNewSafeBytesInstance_returnsTrue() { //Arrange var sut = GetSut(); //Act var isEmpty = SafeBytes.IsNullOrEmpty(sut); //Assert Assert.That(isEmpty, Is.True); }
public void IsNullOrEmpty_ForNullSafeBytesObject_returnsTrue() { //Arrange ISafeBytes nullBytes = null; //Act var isNull = SafeBytes.IsNullOrEmpty(nullBytes); //Assert Assert.That(isNull, Is.True); }
public void IsNullOrEmpty_ForObjectHoldingSingleByte_returnsFalse([Random(0, 256, 1)] byte b) { //Arrange var sut = GetSut(); sut.Append(b); //Act var isEmpty = SafeBytes.IsNullOrEmpty(sut); //Assert Assert.That(isEmpty, Is.False); }
public void IsNullOrEmpty_ForDisposedSafeBytesObject_returnsTrue([Random(0, 256, 1)] byte b) { //Arrange var sut = GetSut(); sut.Append(b); sut.Dispose(); //Act var isNull = SafeBytes.IsNullOrEmpty(sut); //Assert Assert.That(isNull, Is.True); }
public void IsNullOrEmpty_ForObjectHoldingMultipleBytes_returnsFalse([Random(0, 256, 1)] byte b1, [Random(0, 256, 1)] byte b2, [Random(0, 256, 1)] byte b3) { //Arrange var sut = GetSut(); sut.Append(b1); sut.Append(b2); sut.Append(b3); //Act var isNull = SafeBytes.IsNullOrEmpty(sut); //Assert Assert.That(isNull, Is.False); }
/// <inheritdoc /> /// <inheritdoc cref="DisposableBase.ThrowIfDisposed"/> /// <exception cref="ArgumentNullException"> <paramref name="character" /> is <see langword="null" />. </exception> /// <exception cref="ArgumentOutOfRangeException"> <paramref name="character" /> is null or empty. </exception> public async Task InsertAsync(int position, ISafeBytes character, Encoding encoding = Encoding.Utf16LittleEndian) { ThrowIfDisposed(); if (position < 0 || position > Length) { throw new ArgumentOutOfRangeException(nameof(position)); } if (SafeBytes.IsNullOrEmpty(character)) { throw new ArgumentNullException(nameof(character)); } if (encoding != InnerEncoding) { character = await ConvertEncodingAsync(character, encoding, InnerEncoding) .ConfigureAwait(false); } _charBytesList.Insert(position, character); }
/// <exception cref="ArgumentNullException"> /// <paramref name="character" /> is <see langword="null" />. /// </exception> /// <exception cref="ObjectDisposedException"> /// Throws if the SafeString instance is disposed. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Throws if <paramref name="character" /> is less than zero or higher than the length. /// </exception> public void Insert(int position, ISafeBytes character, Encoding encoding = Encoding.Utf16LittleEndian) { EnsureNotDisposed(); if ((position < 0) || (position > Length)) { throw new ArgumentOutOfRangeException(nameof(position)); } if (SafeBytes.IsNullOrEmpty(character)) { throw new ArgumentNullException(nameof(character)); } if (encoding == InnerEncoding) { _charBytesList.Insert(position, character); return; } //Convert encoding var buffer = character.ToByteArray(); try { buffer = _textService.Convert(encoding, InnerEncoding, buffer); var safeBytes = _safeBytesFactory.Create(); for (var i = 0; i < buffer.Length; i++) { //Append safeBytes.Append(buffer[i]); buffer[i] = 0x0; } _charBytesList.Insert(position, safeBytes); } finally { Array.Clear(buffer, 0, buffer.Length); } }