Beispiel #1
0
        public void ToDashboardViewModel_WhenByteArrayCanBeDeserialized_AssertUnprotectWasCalledOnDataProtector()
        {
            IContentHelper sut = CreateSut();

            byte[] byteArray = BuildDashboardViewModelAsByteArray();
            sut.ToDashboardViewModel(byteArray);

            _dataProtectorMock.Verify(m => m.Unprotect(It.Is <byte[]>(value => value != null && value.Length > 0)), Times.Once);
        }
Beispiel #2
0
        public void ToDashboardViewModel_WhenByteArrayCannotBeDeserialized_ReturnsNull()
        {
            IContentHelper sut = CreateSut();

            byte[]             byteArray = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString("D"));
            DashboardViewModel result    = sut.ToDashboardViewModel(byteArray);

            Assert.IsNull(result);
        }
Beispiel #3
0
        public void ToDashboardViewModel_WhenByteArrayCanBeDeserialized_AssertCreateProtectorWasCalledOnDataProtectionProviderWithDashboardProtection()
        {
            IContentHelper sut = CreateSut();

            byte[] byteArray = BuildDashboardViewModelAsByteArray();
            sut.ToDashboardViewModel(byteArray);

            _dataProtectionProviderMock.Verify(m => m.CreateProtector(It.Is <string>(value => string.CompareOrdinal(value, "DashboardProtection") == 0)), Times.Exactly(2));
        }
Beispiel #4
0
        public void ToDashboardViewModel_WhenByteArrayCannotBeDeserialized_AssertCreateProtectorWasCalledOnDataProtectionProviderWithDashboardProtection()
        {
            IContentHelper sut = CreateSut();

            byte[] byteArray = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString("D"));
            sut.ToDashboardViewModel(byteArray);

            _dataProtectionProviderMock.Verify(m => m.CreateProtector(It.Is <string>(value => string.CompareOrdinal(value, "DashboardProtection") == 0)), Times.Once);
        }
Beispiel #5
0
        public void ToDashboardViewModel_WhenByteArrayCannotBeDeserialized_AssertUnprotectWasCalledOnDataProtector()
        {
            IContentHelper sut = CreateSut();

            byte[] byteArray = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString("D"));
            sut.ToDashboardViewModel(byteArray);

            _dataProtectorMock.Verify(m => m.Unprotect(It.Is <byte[]>(value => value != null && value.Length > 0)), Times.Once);
        }
Beispiel #6
0
        public void ToDashboardViewModel_WhenByteArrayCanBeDeserializedAndCryptographicExceptionWasThrown_ReturnsNull()
        {
            CryptographicException exception = new CryptographicException();
            IContentHelper         sut       = CreateSut(exception);

            byte[]             byteArray = BuildDashboardViewModelAsByteArray();
            DashboardViewModel result    = sut.ToDashboardViewModel(byteArray);

            Assert.IsNull(result);
        }
Beispiel #7
0
        public void ToDashboardViewModel_WhenByteArrayCanBeDeserialized_ReturnsDashboardViewModelWithDeserializedRedditAuthenticatedUser()
        {
            IContentHelper sut = CreateSut();

            byte[]             byteArray = BuildDashboardViewModelAsByteArray();
            DashboardViewModel result    = sut.ToDashboardViewModel(byteArray);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.RedditAuthenticatedUser);
        }
Beispiel #8
0
        public void ToDashboardViewModel_WhenByteArrayCanBeDeserialized_ReturnsDashboardViewModelWithDeserializedRedditSubreddits()
        {
            IContentHelper sut = CreateSut();

            byte[]             byteArray = BuildDashboardViewModelAsByteArray();
            DashboardViewModel result    = sut.ToDashboardViewModel(byteArray);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.RedditSubreddits);
            Assert.AreEqual(1, result.RedditSubreddits.Count);
        }
Beispiel #9
0
        public void ToDashboardViewModel_WhenByteArrayCanBeDeserialized_ReturnsDashboardViewModelWithDeserializedLatestInformationsWithImage()
        {
            IContentHelper sut = CreateSut();

            byte[]             byteArray = BuildDashboardViewModelAsByteArray();
            DashboardViewModel result    = sut.ToDashboardViewModel(byteArray);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.LatestInformationsWithImage);
            Assert.AreEqual(1, result.LatestInformationsWithImage.Count);
        }
Beispiel #10
0
        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);
            }));
Beispiel #11
0
        public void ToDashboardViewModel_WhenByteArrayIsNull_ThrowsArgumentNullException()
        {
            IContentHelper sut = CreateSut();

            sut.ToDashboardViewModel(null);
        }