public void Query_Ctor_SingleArg_SetsAuthenticationType_ToDefaultExternalCookie() { var claimType = FakeData.String(); var query = new ExternalCookieClaim(claimType); query.AuthenticationType.ShouldEqual(DefaultAuthenticationTypes.ExternalCookie); }
public void Handler_ReturnsNonNullClaim_WhenExists() { const string authenticationType = DefaultAuthenticationTypes.ApplicationCookie; const string claimType = ClaimTypes.GivenName; string claimValue = FakeData.String(); var data = new[] { new Claim(ClaimTypes.Email, FakeData.Email()), new Claim(ClaimTypes.NameIdentifier, FakeData.Id() .ToString(CultureInfo.InvariantCulture)), new Claim(claimType, claimValue), }; var queries = new Mock <IProcessQueries>(MockBehavior.Strict); Expression <Func <ExternalCookieClaims, bool> > expectedQuery = x => x.AuthenticationType == authenticationType; queries.Setup(x => x.Execute(It.Is(expectedQuery))) .Returns(Task.FromResult(data as IEnumerable <Claim>)); var handler = new HandleExternalCookieClaimQuery(queries.Object); var query = new ExternalCookieClaim(ClaimTypes.GivenName, authenticationType); Claim result = handler.Handle(query).Result; Assert.NotNull(result); result.Type.ShouldEqual(claimType); result.Value.ShouldEqual(claimValue); queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once); }
public void Query_Ctor_SingleArg_SetsClaimType() { var claimType = FakeData.String(); var query = new ExternalCookieClaim(claimType); query.ClaimType.ShouldEqual(claimType); }
public void Query_Ctor_SingleArg_SetsClaimType() { var claimType = Guid.NewGuid().ToString(); var query = new ExternalCookieClaim(claimType); query.ClaimType.ShouldEqual(claimType); }
public async Task <Claim> Handle(ExternalCookieClaim query) { var claims = await _queries.Execute(new ExternalCookieClaims(query.AuthenticationType)) .ConfigureAwait(false); return(claims.FirstOrDefault(x => x.Type == query.ClaimType)); }
public void Query_Ctor_SecondArg_SetsAuthenticationType() { var claimType = FakeData.String(); var authenticationType = FakeData.String(); var query = new ExternalCookieClaim(claimType, authenticationType); query.AuthenticationType.ShouldEqual(authenticationType); }
public void Handler_ReturnsNullClaim_WhenDoesNotExist() { const string authenticationType = DefaultAuthenticationTypes.ApplicationCookie; var data = new[] { new Claim(ClaimTypes.Email, string.Format("{0}@domain.tld", Guid.NewGuid())), new Claim(ClaimTypes.NameIdentifier, new Random().Next(3, int.MaxValue) .ToString(CultureInfo.InvariantCulture)), new Claim(ClaimTypes.Gender, string.Empty), }; var queries = new Mock <IProcessQueries>(MockBehavior.Strict); Expression <Func <ExternalCookieClaims, bool> > expectedQuery = x => x.AuthenticationType == authenticationType; queries.Setup(x => x.Execute(It.Is(expectedQuery))) .Returns(Task.FromResult(data as IEnumerable <Claim>)); var handler = new HandleExternalCookieClaimQuery(queries.Object); var query = new ExternalCookieClaim(ClaimTypes.GivenName, authenticationType); Claim result = handler.Handle(query).Result; result.ShouldBeNull(); queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once); }