public async Task Block_Subverse_Toggle() { string userName = "******"; var user = TestHelper.SetPrincipal(userName); using (var db = new Voat.Data.Repository(user)) { string name = "whatever"; await db.Block(DomainType.Subverse, name, SubscriptionAction.Toggle); var blocks = await db.GetBlockedSubverses(userName); Assert.IsNotNull(blocks); Assert.IsTrue(blocks.Any(x => x.Name == name && x.Type == DomainType.Subverse)); await db.Block(DomainType.Subverse, name, SubscriptionAction.Toggle); blocks = await db.GetBlockedSubverses(userName); Assert.IsNotNull(blocks); Assert.IsFalse(blocks.Any(x => x.Name == name && x.Type == DomainType.Subverse)); } }
public void Block_Subverse_SubverseDoesNotExist() { using (var db = new Voat.Data.Repository()) { TestHelper.SetPrincipal("TestUser1"); db.Block(DomainType.Subverse, "happyhappyjoyjoy"); } }
public void Block_Subverse_NoAuthentication() { TestHelper.SetPrincipal(null); using (var db = new Voat.Data.Repository()) { db.Block(DomainType.Subverse, "test"); } }
public async Task Block_Subverse_NoAuthentication() { await VoatAssert.ThrowsAsync <VoatSecurityException>(() => { var user = TestHelper.SetPrincipal(null); using (var db = new Voat.Data.Repository(user)) { return(db.Block(DomainType.Subverse, "test")); } }); }
public async Task Block_Subverse_SubverseDoesNotExist() { string userName = "******"; var user = TestHelper.SetPrincipal(userName); await VoatAssert.ThrowsAsync <VoatNotFoundException>(() => { using (var db = new Voat.Data.Repository(user)) { return(db.Block(DomainType.Subverse, "happyhappyjoyjoy")); } }); }
public void Block_Subverse_Toggle() { using (var db = new Voat.Data.Repository()) { string name = "whatever"; string userName = "******"; TestHelper.SetPrincipal(userName); db.Block(DomainType.Subverse, name, null); var blocks = db.GetBlockedSubverses(userName); Assert.IsNotNull(blocks); Assert.IsTrue(blocks.Any(x => x.Name == name && x.Type == DomainType.Subverse)); db.Block(DomainType.Subverse, name, null); blocks = db.GetBlockedSubverses(userName); Assert.IsNotNull(blocks); Assert.IsFalse(blocks.Any(x => x.Name == name && x.Type == DomainType.Subverse)); } }
public async Task Block_Subverse() { string name = "whatever"; string userName = "******"; var user = TestHelper.SetPrincipal(userName); //Sets Thread.CurrentPrincipal using (var db = new Voat.Data.Repository(user)) { await db.Block(DomainType.Subverse, name); ////After call returns, principal information on the thread is lost, thus this second assert will fail when it should pass as it did with full .net ////This seems to only happen when the call returns after await ////I have tried various changes: .ConfigureAwait(true|false), Task.Run(...), t.Wait(), etc. and ////I can't seem to figure out how to get the security context associated with Thread.CurrentPrincipal to ////sync after an await call or any Task execution for that matter. //Assert.AreEqual(userName, UserIdentity.UserName, "Port Issue: Lost User Context After"); ////We need to figure out if this is a bug, an issue with changes between .net framework and core/standard, or if this is an MSTest issue ////We can not make calls to var user = TestHelper.SetPrincipal(userName); repeatedly as this will not guarantee tests pass in API or UI as these areas often ////issue multiple commands as part of an action var blocks = await db.GetBlockedSubverses(userName); Assert.IsNotNull(blocks); Assert.IsTrue(blocks.Any(x => x.Name == name && x.Type == DomainType.Subverse)); await db.Unblock(DomainType.Subverse, name); blocks = await db.GetBlockedSubverses(userName); Assert.IsNotNull(blocks); Assert.IsFalse(blocks.Any(x => x.Name == name && x.Type == DomainType.Subverse)); } }