public void ApplyRules(IDashboardRules rules, ICookieHelper cookieHelper) { if (rules == null) { throw new ArgumentNullException(nameof(rules)); } if (cookieHelper == null) { throw new ArgumentNullException(nameof(cookieHelper)); } try { AllowNsfwContent = rules.AllowNsfwContent; if (AllowNsfwContent) { return; } IncludeNsfwContent = null; OnlyNsfwContent = null; } finally { cookieHelper.ToCookie(this); } }
public void AllowNsfwContent_WhenRedditAuthenticatedUserIsNull_ReturnsFalse() { const IRedditAuthenticatedUser redditAuthenticatedUser = null; IDashboardRules sut = CreateSut(redditAuthenticatedUser); Assert.IsFalse(sut.AllowNsfwContent); }
public void ApplyRules_WhenCookieHelperIsNull_ThrowsArgumentNullException() { IDashboardRules dashboardRules = CreateDashboardRules(); OSDevGrp.MyDashboard.Web.Models.DashboardSettingsViewModel sut = CreateSut(); sut.ApplyRules(dashboardRules, null); }
public void ApplyRules_WhenDashboardRulesIsNull_ThrowsArgumentNullException() { const IDashboardRules dashboardRules = null; OSDevGrp.MyDashboard.Web.Models.DashboardSettingsViewModel sut = CreateSut(); sut.ApplyRules(dashboardRules, _cookieHelperMock.Object); }
public void AllowNsfwContent_WhenRedditAuthenticatedUserIsOver18_ReturnsTrue() { const bool over18 = true; IRedditAuthenticatedUser redditAuthenticatedUser = CreateRedditAuthenticatedUser(over18: over18); IDashboardRules sut = CreateSut(redditAuthenticatedUser); Assert.IsTrue(sut.AllowNsfwContent); }
public void AllowNsfwContent_WhenRedditAuthenticatedUserIsNotNull_AssertOver18WasCalledOnRedditAuthenticatedUser() { Mock <IRedditAuthenticatedUser> redditAuthenticatedUserMock = CreateRedditAuthenticatedUserMock(); IDashboardRules sut = CreateSut(redditAuthenticatedUserMock.Object); bool result = sut.AllowNsfwContent; redditAuthenticatedUserMock.Verify(m => m.Over18, Times.Once); }
public void Rules_WhenCalledMoreThanOnce_ExpectSameInstance() { IDashboard sut = CreateSut(); IDashboardRules instance1 = sut.Rules; IDashboardRules instance2 = sut.Rules; Assert.AreSame(instance1, instance2); }
public void ApplyRules_WhenCalledWhereAllowNsfwContentIsFalseInDasboardRules_AssertToCookieWasCalledOnCookieHelperWithDashboardSettingsViewModel() { const bool allowNsfwContent = false; IDashboardRules dashboardRules = CreateDashboardRules(allowNsfwContent: allowNsfwContent); OSDevGrp.MyDashboard.Web.Models.DashboardSettingsViewModel sut = CreateSut(); sut.ApplyRules(dashboardRules, _cookieHelperMock.Object); _cookieHelperMock.Verify(m => m.ToCookie(It.Is <OSDevGrp.MyDashboard.Web.Models.DashboardSettingsViewModel>(value => value == sut)), Times.Once); }
public void ApplyRules_WhenCalledWhereAllowNsfwContentIsTrueInDasboardRules_ExpectRulesHasBeenApplid() { const bool allowNsfwContent = true; IDashboardRules dashboardRules = CreateDashboardRules(allowNsfwContent: allowNsfwContent); bool includeNsfwContent = _random.Next(100) > 50; bool onlyNsfwContent = _random.Next(100) > 50; OSDevGrp.MyDashboard.Web.Models.DashboardSettingsViewModel sut = CreateSut(includeNsfwContent: includeNsfwContent, onlyNsfwContent: onlyNsfwContent); sut.ApplyRules(dashboardRules, _cookieHelperMock.Object); Assert.IsTrue(sut.AllowNsfwContent); Assert.IsTrue(sut.IncludeNsfwContent.HasValue); Assert.AreEqual(includeNsfwContent, sut.IncludeNsfwContent); Assert.IsTrue(sut.OnlyNsfwContent.HasValue); Assert.AreEqual(onlyNsfwContent, sut.OnlyNsfwContent); }
public void ApplyRules(IDashboardRules rules, ICookieHelper cookieHelper) { if (rules == null) { throw new ArgumentNullException(nameof(rules)); } if (cookieHelper == null) { throw new ArgumentNullException(nameof(cookieHelper)); } if (Settings == null) { return; } Settings.ApplyRules(rules, cookieHelper); }
private Mock <IDashboard> CreateDashboardMock(IEnumerable <INews> newsCollection = null, IEnumerable <ISystemError> systemErrorCollection = null, IDashboardSettings dashboardSettings = null, IRedditAuthenticatedUser redditAuthenticatedUser = null, IEnumerable <IRedditSubreddit> redditSubredditCollection = null, IEnumerable <IRedditLink> redditLinkCollection = null, IDashboardRules dashboardRules = null) { Mock <IDashboard> dashboardMock = new Mock <IDashboard>(); dashboardMock.Setup(m => m.News) .Returns(newsCollection ?? CreateNewsCollection(_random.Next(50, 100))); dashboardMock.Setup(m => m.SystemErrors) .Returns(systemErrorCollection ?? CreateSystemErrorCollection(_random.Next(5, 10))); dashboardMock.Setup(m => m.Settings) .Returns(dashboardSettings); dashboardMock.Setup(m => m.RedditAuthenticatedUser) .Returns(redditAuthenticatedUser); dashboardMock.Setup(m => m.RedditSubreddits) .Returns(redditSubredditCollection ?? CreateRedditSubredditCollection(_random.Next(10, 25))); dashboardMock.Setup(m => m.RedditLinks) .Returns(redditLinkCollection ?? CreateRedditLinkCollection(_random.Next(50, 100))); dashboardMock.Setup(m => m.Rules) .Returns(dashboardRules ?? CreateDashboardRules()); return(dashboardMock); }
private IDashboard CreateDashboard(IEnumerable <INews> newsCollection = null, IEnumerable <ISystemError> systemErrorCollection = null, IDashboardSettings dashboardSettings = null, IRedditAuthenticatedUser redditAuthenticatedUser = null, IEnumerable <IRedditSubreddit> redditSubredditCollection = null, IEnumerable <IRedditLink> redditLinkCollection = null, IDashboardRules dashboardRules = null) { return(CreateDashboardMock(newsCollection, systemErrorCollection, dashboardSettings, redditAuthenticatedUser, redditSubredditCollection, redditLinkCollection, dashboardRules).Object); }