Ejemplo n.º 1
0
        public void ToDashboardSettingsViewModel_WhenByteArrayCannotBeDeserialized_AssertCreateProtectorWasCalledOnDataProtectionProviderWithSettingsProtection()
        {
            IContentHelper sut = CreateSut();

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

            _dataProtectionProviderMock.Verify(m => m.CreateProtector(It.Is <string>(value => string.CompareOrdinal(value, "SettingsProtection") == 0)), Times.Once);
        }
Ejemplo n.º 2
0
        public void ToDashboardSettingsViewModel_WhenBase64StringCannotBeDeserialized_ReturnsNull()
        {
            IContentHelper sut = CreateSut();

            string base64String = Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString("D")));
            DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(base64String);

            Assert.IsNull(result);
        }
Ejemplo n.º 3
0
        public void ToDashboardSettingsViewModel_WhenByteArrayCannotBeDeserialized_ReturnsNull()
        {
            IContentHelper sut = CreateSut();

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

            Assert.IsNull(result);
        }
Ejemplo n.º 4
0
        public void ToDashboardSettingsViewModel_WhenByteArrayCanBeDeserialized_AssertCreateProtectorWasCalledOnDataProtectionProviderWithSettingsProtection()
        {
            IContentHelper sut = CreateSut();

            byte[] byteArray = BuildDashboardSettingsViewModelAsByteArray();
            sut.ToDashboardSettingsViewModel(byteArray);

            _dataProtectionProviderMock.Verify(m => m.CreateProtector(It.Is <string>(value => string.CompareOrdinal(value, "SettingsProtection") == 0)), Times.Exactly(2));
        }
Ejemplo n.º 5
0
        public void ToDashboardSettingsViewModel_WhenBase64StringIsNotBase64String_ReturnsNull()
        {
            IContentHelper sut = CreateSut();

            string base64String = Guid.NewGuid().ToString("D");
            DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(base64String);

            Assert.IsNull(result);
        }
Ejemplo n.º 6
0
        public void ToDashboardSettingsViewModel_WhenByteArrayCanBeDeserialized_AssertUnprotectWasCalledOnDataProtector()
        {
            IContentHelper sut = CreateSut();

            byte[] byteArray = BuildDashboardSettingsViewModelAsByteArray();
            sut.ToDashboardSettingsViewModel(byteArray);

            _dataProtectorMock.Verify(m => m.Unprotect(It.Is <byte[]>(value => value != null && value.Length > 0)), Times.Once);
        }
Ejemplo n.º 7
0
        public void ToDashboardSettingsViewModel_WhenByteArrayCannotBeDeserialized_AssertUnprotectWasCalledOnDataProtector()
        {
            IContentHelper sut = CreateSut();

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

            _dataProtectorMock.Verify(m => m.Unprotect(It.Is <byte[]>(value => value != null && value.Length > 0)), Times.Once);
        }
Ejemplo n.º 8
0
        public void ToDashboardSettingsViewModel_WhenBase64StringCanBeDeserializedAndCryptographicExceptionWasThrown_ReturnsNull()
        {
            CryptographicException exception = new CryptographicException();
            IContentHelper         sut       = CreateSut(exception);

            string base64String = BuildDashboardSettingsViewModelAsBase64String();
            DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(base64String);

            Assert.IsNull(result);
        }
Ejemplo n.º 9
0
        public void ToDashboardSettingsViewModel_WhenByteArrayCanBeDeserializedAndCryptographicExceptionWasThrown_ReturnsNull()
        {
            CryptographicException exception = new CryptographicException();
            IContentHelper         sut       = CreateSut(exception);

            byte[] byteArray = BuildDashboardSettingsViewModelAsByteArray();
            DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(byteArray);

            Assert.IsNull(result);
        }
Ejemplo n.º 10
0
        public void ToDashboardSettingsViewModel_WhenBase64StringCanBeDeserialized_AssertUnprotectWasCalledOnDataProtector()
        {
            IContentHelper sut = CreateSut();

            string base64String = BuildDashboardSettingsViewModelAsBase64String();

            sut.ToDashboardSettingsViewModel(base64String);

            _dataProtectorMock.Verify(m => m.Unprotect(It.Is <byte[]>(value => value != null && string.CompareOrdinal(Convert.ToBase64String(value), base64String) == 0)), Times.Once);
        }
Ejemplo n.º 11
0
        public void ToDashboardSettingsViewModel_WhenBase64StringIsNotBase64String_AssertUnprotectWasNotCalledOnDataProtector()
        {
            IContentHelper sut = CreateSut();

            string base64String = Guid.NewGuid().ToString("D");

            sut.ToDashboardSettingsViewModel(base64String);

            _dataProtectorMock.Verify(m => m.Unprotect(It.IsAny <byte[]>()), Times.Never);
        }
Ejemplo n.º 12
0
        public void ToDashboardSettingsViewModel_WhenBase64StringIsNotBase64String_AssertCreateProtectorNotWasCalledOnDataProtectionProviderWithSettingsProtection()
        {
            IContentHelper sut = CreateSut();

            string base64String = Guid.NewGuid().ToString("D");

            sut.ToDashboardSettingsViewModel(base64String);

            _dataProtectionProviderMock.Verify(m => m.CreateProtector(It.Is <string>(value => string.CompareOrdinal(value, "SettingsProtection") == 0)), Times.Never);
        }
Ejemplo n.º 13
0
        public void ToDashboardSettingsViewModel_WhenBase64StringCanBeDeserialized_ReturnsDashboardSettingsViewModelWithDeserializedExportData()
        {
            IContentHelper sut = CreateSut();

            bool   exportData   = _random.Next(100) > 0;
            string base64String = BuildDashboardSettingsViewModelAsBase64String(exportData: exportData);
            DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(base64String);

            Assert.IsNotNull(result);
            Assert.AreEqual(exportData, result.ExportData);
        }
Ejemplo n.º 14
0
        public void ToDashboardSettingsViewModel_WhenBase64StringCanBeDeserialized_ReturnsDashboardSettingsViewModelWithDeserializedOnlyNsfwContent()
        {
            IContentHelper sut = CreateSut();

            bool   onlyNsfwContent            = _random.Next(100) > 0;
            string base64String               = BuildDashboardSettingsViewModelAsBase64String(onlyNsfwContent: onlyNsfwContent);
            DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(base64String);

            Assert.IsNotNull(result);
            Assert.AreEqual(onlyNsfwContent, result.OnlyNsfwContent);
        }
Ejemplo n.º 15
0
        public void ToDashboardSettingsViewModel_WhenBase64StringCanBeDeserialized_ReturnsDashboardSettingsViewModelWithDeserializedNumberOfNews()
        {
            IContentHelper sut = CreateSut();

            int    numberOfNews = _random.Next(25, 50);
            string base64String = BuildDashboardSettingsViewModelAsBase64String(numberOfNews);
            DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(base64String);

            Assert.IsNotNull(result);
            Assert.AreEqual(numberOfNews, result.NumberOfNews);
        }
Ejemplo n.º 16
0
        public void ToDashboardSettingsViewModel_WhenBase64StringCanBeDeserialized_ReturnsDashboardSettingsViewModelWithDeserializedRedditAccessToken()
        {
            IContentHelper sut = CreateSut();

            string redditAccessToken          = Guid.NewGuid().ToString("D");
            string base64String               = BuildDashboardSettingsViewModelAsBase64String(redditAccessToken: redditAccessToken);
            DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(base64String);

            Assert.IsNotNull(result);
            Assert.AreEqual(redditAccessToken, result.RedditAccessToken);
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Build(string dashboardSettings)
        {
            if (string.IsNullOrWhiteSpace(dashboardSettings))
            {
                throw new ArgumentNullException(nameof(dashboardSettings));
            }

            DashboardSettingsViewModel dashboardSettingsViewModel = _contentHelper.ToDashboardSettingsViewModel(dashboardSettings);

            if (dashboardSettingsViewModel == null)
            {
                return(BadRequest());
            }

            IDashboard dashboard = await _dashboardFactory.BuildAsync(dashboardSettingsViewModel.ToDashboardSettings());

            DashboardViewModel dashboardViewModel = await _dashboardViewModelBuilder.BuildAsync(dashboard);

            return(PartialView("_MainContentPartial", dashboardViewModel));
        }
Ejemplo n.º 18
0
        public void ToDashboardSettingsViewModel_WhenByteArrayCanBeDeserialized_ReturnsDashboardSettingsViewModelWithDeserializedIncludeNsfwContent()
        {
            IContentHelper sut = CreateSut();

            bool includeNsfwContent = _random.Next(100) > 0;

            byte[] byteArray = BuildDashboardSettingsViewModelAsByteArray(includeNsfwContent: includeNsfwContent);
            DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(byteArray);

            Assert.IsNotNull(result);
            Assert.AreEqual(includeNsfwContent, result.IncludeNsfwContent);
        }
Ejemplo n.º 19
0
 public DashboardSettingsViewModel ToDashboardSettingsViewModel()
 {
     return(RestoreFromCookie <DashboardSettingsViewModel>(DashboardSettingsViewModel.CookieName, cookieValue => _contentHelper.ToDashboardSettingsViewModel(cookieValue)));
 }
Ejemplo n.º 20
0
        public void ToDashboardSettingsViewModel_WhenBase64StringIsWhiteSpaces_ThrowsArgumentNullException()
        {
            IContentHelper sut = CreateSut();

            sut.ToDashboardSettingsViewModel("  ");
        }
Ejemplo n.º 21
0
        public void ToDashboardSettingsViewModel_WhenBase64StringIsEmpty_ThrowsArgumentNullException()
        {
            IContentHelper sut = CreateSut();

            sut.ToDashboardSettingsViewModel(string.Empty);
        }
Ejemplo n.º 22
0
        public void ToDashboardSettingsViewModel_WhenByteArrayIsNull_ThrowsArgumentNullException()
        {
            IContentHelper sut = CreateSut();

            sut.ToDashboardSettingsViewModel((byte[])null);
        }