Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }));
Ejemplo n.º 11
0
        public void ToDashboardViewModel_WhenByteArrayIsNull_ThrowsArgumentNullException()
        {
            IContentHelper sut = CreateSut();

            sut.ToDashboardViewModel(null);
        }