public void ToValue_WhenByteArrayCanBeConvertedToUTF8_AssertUnprotectWasCalledOnDataProtector() { IContentHelper sut = CreateSut(); byte[] byteArray = BuildStringValueAsByteArray(Guid.NewGuid().ToString("D")); sut.ToValue(byteArray); _dataProtectorMock.Verify(m => m.Unprotect(It.Is <byte[]>(value => value != null && string.CompareOrdinal(Encoding.UTF8.GetString(value), Encoding.UTF8.GetString(byteArray)) == 0)), Times.Once); }
public void ToValue_WhenBase64StringIsNotBase64String_ReturnsNull() { IContentHelper sut = CreateSut(); string base64String = Guid.NewGuid().ToString("D"); string result = sut.ToValue(base64String); Assert.IsNull(result); }
public void ToValue_WhenByteArrayCanBeConvertedToUTF8_AssertCreateProtectorWasCalledOnDataProtectionProviderWithValueProtection() { IContentHelper sut = CreateSut(); byte[] byteArray = BuildStringValueAsByteArray(Guid.NewGuid().ToString("D")); sut.ToValue(byteArray); _dataProtectionProviderMock.Verify(m => m.CreateProtector(It.Is <string>(value => string.CompareOrdinal(value, "ValueProtection") == 0)), Times.Exactly(2)); }
public void ToValue_WhenByteArrayCanBeConvertedToUTF8AndCryptographicExceptionWasThrown_ReturnsNull() { CryptographicException exception = new CryptographicException(); IContentHelper sut = CreateSut(exception); byte[] byteArray = BuildStringValueAsByteArray(); string result = sut.ToValue(byteArray); Assert.IsNull(result); }
public void ToValue_WhenBase64StringCanBeConvertedToUTF8AndCryptographicExceptionWasThrown_ReturnsNull() { CryptographicException exception = new CryptographicException(); IContentHelper sut = CreateSut(exception); string base64String = BuildStringValueAsBase64String(); string result = sut.ToValue(base64String); Assert.IsNull(result); }
public void ToValue_WhenBase64StringCanBeConvertedToUTF8_AssertUnprotectWasCalledOnDataProtector() { IContentHelper sut = CreateSut(); string base64String = BuildStringValueAsBase64String(Guid.NewGuid().ToString("D")); sut.ToValue(base64String); _dataProtectorMock.Verify(m => m.Unprotect(It.Is <byte[]>(value => value != null && string.CompareOrdinal(Convert.ToBase64String(value), base64String) == 0)), Times.Once); }
public void ToValue_WhenBase64StringIsNotBase64String_AssertUnprotectWasNotCalledOnDataProtector() { IContentHelper sut = CreateSut(); string base64String = Guid.NewGuid().ToString("D"); sut.ToValue(base64String); _dataProtectorMock.Verify(m => m.Unprotect(It.IsAny <byte[]>()), Times.Never); }
public void ToValue_WhenBase64StringIsNotBase64String_AssertCreateProtectorNotWasCalledOnDataProtectionProviderWithValueProtection() { IContentHelper sut = CreateSut(); string base64String = Guid.NewGuid().ToString("D"); sut.ToValue(base64String); _dataProtectionProviderMock.Verify(m => m.CreateProtector(It.Is <string>(value => string.CompareOrdinal(value, "ValueProtection") == 0)), Times.Never); }
public void ToValue_WhenBase64StringCanBeConvertedToUTF8_ReturnsValue() { IContentHelper sut = CreateSut(); string stringValue = Guid.NewGuid().ToString("D"); string base64String = BuildStringValueAsBase64String(stringValue); string result = sut.ToValue(base64String); Assert.IsNotNull(result); Assert.AreEqual(stringValue, result); }
public void ToValue_WhenByteArrayCanBeConvertedToUTF8_ReturnsValue() { IContentHelper sut = CreateSut(); string stringValue = Guid.NewGuid().ToString("D"); byte[] byteArray = BuildStringValueAsByteArray(stringValue); string result = sut.ToValue(byteArray); Assert.IsNotNull(result); Assert.AreEqual(stringValue, result); }
public DashboardViewModel ToDashboardViewModel() { return(RestoreFromCookie <DashboardViewModel>(DashboardViewModel.CookieName, cookieValue => { string memoryCacheKey = _contentHelper.ToValue(cookieValue); if (string.IsNullOrWhiteSpace(memoryCacheKey)) { return null; } if (_memoryCache.TryGetValue(memoryCacheKey, out byte[] memoryCacheValue) == false) { return null; } return _contentHelper.ToDashboardViewModel(memoryCacheValue); }));
public void ToValue_WhenByteArrayIsNull_ThrowsArgumentNullException() { IContentHelper sut = CreateSut(); sut.ToValue((byte[])null); }
public void ToValue_WhenBase64StringIsWhiteSpaces_ThrowsArgumentNullException() { IContentHelper sut = CreateSut(); sut.ToValue(" "); }
public void ToValue_WhenBase64StringIsEmpty_ThrowsArgumentNullException() { IContentHelper sut = CreateSut(); sut.ToValue(string.Empty); }