示例#1
0
		public void VerifyAuthenticationWithoutReturnUrlThrows() {
			// Arrange
			var client = new MockOAuth2Client();

			// Act && Assert
			Assert.Throws<InvalidOperationException>(() => client.VerifyAuthenticationAsync(new Mock<HttpContextBase>().Object).GetAwaiter().GetResult());
		}
示例#2
0
		public void VerifyAuthenticationThrowsIfContextIsNull() {
			// Arrange
			var client = new MockOAuth2Client();

			// Act && Assert
			Assert.Throws<ArgumentNullException>(() => client.VerifyAuthenticationAsync(null, new Uri("http://me.com")).GetAwaiter().GetResult());
		}
示例#3
0
        public void VerifyAuthenticationWithoutReturnUrlThrows()
        {
            // Arrange
            var client = new MockOAuth2Client();

            // Act && Assert
            Assert.Throws <InvalidOperationException>(() => client.VerifyAuthenticationAsync(new Mock <HttpContextBase>().Object).GetAwaiter().GetResult());
        }
示例#4
0
        public void VerifyAuthenticationThrowsIfContextIsNull()
        {
            // Arrange
            var client = new MockOAuth2Client();

            // Act && Assert
            Assert.Throws <ArgumentNullException>(() => client.VerifyAuthenticationAsync(null, new Uri("http://me.com")).GetAwaiter().GetResult());
        }
示例#5
0
		public async Task VerifyAuthenticationFailsIfCodeIsNotPresent() {
			// Arrange
			var client = new MockOAuth2Client();
			var context = new Mock<HttpContextBase>(MockBehavior.Strict);
			var queryStrings = new NameValueCollection();
			context.Setup(c => c.Request.QueryString).Returns(queryStrings);

			// Act 
			AuthenticationResult result = await client.VerifyAuthenticationAsync(context.Object, new Uri("http://me.com"));

			// Assert
			Assert.IsFalse(result.IsSuccessful);
		}
示例#6
0
        public async Task VerifyAuthenticationFailsIfCodeIsNotPresent()
        {
            // Arrange
            var client       = new MockOAuth2Client();
            var context      = new Mock <HttpContextBase>(MockBehavior.Strict);
            var queryStrings = new NameValueCollection();

            context.Setup(c => c.Request.QueryString).Returns(queryStrings);

            // Act
            AuthenticationResult result = await client.VerifyAuthenticationAsync(context.Object, new Uri("http://me.com"));

            // Assert
            Assert.IsFalse(result.IsSuccessful);
        }
示例#7
0
        public async Task VerifyAuthenticationSucceeds()
        {
            // Arrange
            var client       = new MockOAuth2Client();
            var context      = new Mock <HttpContextBase>(MockBehavior.Strict);
            var queryStrings = new NameValueCollection();

            queryStrings.Add("code", "secret");
            context.Setup(c => c.Request.QueryString).Returns(queryStrings);

            // Act
            AuthenticationResult result = await client.VerifyAuthenticationAsync(context.Object, new Uri("http://me.com"));

            // Assert
            Assert.True(result.IsSuccessful);
            Assert.AreEqual("mockprovider", result.Provider);
            Assert.AreEqual("12345", result.ProviderUserId);
            Assert.AreEqual("John Doe", result.UserName);
            Assert.NotNull(result.ExtraData);
            Assert.AreEqual("abcde", result.ExtraData["accesstoken"]);
        }
示例#8
0
		public async Task VerifyAuthenticationSucceeds() {
			// Arrange
			var client = new MockOAuth2Client();
			var context = new Mock<HttpContextBase>(MockBehavior.Strict);
			var queryStrings = new NameValueCollection();
			queryStrings.Add("code", "secret");
			context.Setup(c => c.Request.QueryString).Returns(queryStrings);

			// Act 
			AuthenticationResult result = await client.VerifyAuthenticationAsync(context.Object, new Uri("http://me.com"));

			// Assert
			Assert.True(result.IsSuccessful);
			Assert.AreEqual("mockprovider", result.Provider);
			Assert.AreEqual("12345", result.ProviderUserId);
			Assert.AreEqual("John Doe", result.UserName);
			Assert.NotNull(result.ExtraData);
			Assert.AreEqual("abcde", result.ExtraData["accesstoken"]);
		}