public void ToByteArray_WhenCalledWithDashboardSettingsViewModel_AssertProtectWasCalledOnDataProtector() { IContentHelper sut = CreateSut(); DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(); sut.ToByteArray(dashboardSettingsViewModel); _dataProtectorMock.Verify(m => m.Protect(It.Is <byte[]>(value => value != null && value.Length > 0)), Times.Once); }
public void ToByteArray_WhenCalledWithDashboardViewModel_AssertCreateProtectorWasCalledOnDataProtectionProviderWithDashboardProtection() { IContentHelper sut = CreateSut(); DashboardViewModel dashboardViewModel = BuildDashboardViewModel(); sut.ToByteArray(dashboardViewModel); _dataProtectionProviderMock.Verify(m => m.CreateProtector(It.Is <string>(value => string.CompareOrdinal(value, "DashboardProtection") == 0)), Times.Once); }
public void ToByteArray_WhenCalledWithStringValue_AssertProtectWasCalledOnDataProtector() { IContentHelper sut = CreateSut(); string stringValue = Guid.NewGuid().ToString("D"); sut.ToByteArray(stringValue); _dataProtectorMock.Verify(m => m.Protect(It.Is <byte[]>(value => value != null && string.CompareOrdinal(Encoding.UTF8.GetString(value), stringValue) == 0)), Times.Once); }
public void ToByteArray_WhenCalledWithStringValue_AssertCreateProtectorWasCalledOnDataProtectionProviderWithValueProtection() { IContentHelper sut = CreateSut(); string stringValue = Guid.NewGuid().ToString("D"); sut.ToByteArray(stringValue); _dataProtectionProviderMock.Verify(m => m.CreateProtector(It.Is <string>(value => string.CompareOrdinal(value, "ValueProtection") == 0)), Times.Once); }
public void ToByteArray_WhenCalledWithDashboardSettingsViewModel_ReturnsByteArray() { IContentHelper sut = CreateSut(); DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(); byte[] result = sut.ToByteArray(dashboardSettingsViewModel); Assert.IsNotNull(result); Assert.IsTrue(result.Length > 0); }
public void ToByteArray_WhenCalledWithStringValue_ReturnsByteArray() { IContentHelper sut = CreateSut(); string stringValue = Guid.NewGuid().ToString("D"); byte[] result = sut.ToByteArray(stringValue); Assert.IsNotNull(result); Assert.IsTrue(result.Length > 0); }
public void ToCookie(DashboardViewModel dashboardViewModel) { if (dashboardViewModel == null) { throw new ArgumentNullException(nameof(dashboardViewModel)); } DateTime expires = DateTime.Now.AddSeconds(30); StoreCookie(DashboardViewModel.CookieName, dashboardViewModel, viewModel => { byte[] dashboardViewModelAsByteArray = _contentHelper.ToByteArray(viewModel); if (dashboardViewModelAsByteArray == null) { return(null); } string memoryCacheKey = $"{DashboardViewModel.CookieName}.{Guid.NewGuid().ToString("D")}"; using (ICacheEntry cacheEntry = _memoryCache.CreateEntry(memoryCacheKey)) { if (cacheEntry == null) { return(null); } cacheEntry.Value = dashboardViewModelAsByteArray; cacheEntry.AbsoluteExpiration = expires; } return(_contentHelper.ToBase64String(memoryCacheKey)); }, (viewModel, secureHttpRequest) => new CookieOptions { Expires = expires, Secure = secureHttpRequest, SameSite = SameSiteMode.None }); }
public void ToByteArray_WhenDashboardViewModelIsNull_ThrowsArgumentNullException() { IContentHelper sut = CreateSut(); sut.ToByteArray((DashboardViewModel)null); }
public void ToByteArray_WhenStringValueIsWhiteSpaces_ThrowsArgumentNullException() { IContentHelper sut = CreateSut(); sut.ToByteArray(" "); }
public void ToByteArray_WhenStringValueIsEmpty_ThrowsArgumentNullException() { IContentHelper sut = CreateSut(); sut.ToByteArray(string.Empty); }