Example #1
0
        public void VerifyAuthenticationSucceeds()
        {
            // Arrange
            var endpoint = new MessageReceivingEndpoint("http://live.com/path/?a=b", HttpDeliveryMethods.GetRequest);
            var request  = new AuthorizedTokenRequest(endpoint, new Version("1.0"));
            var response = new AuthorizedTokenResponse(request)
            {
                AccessToken = "ok"
            };

            var webWorker = new Mock <IOAuthWebWorker>(MockBehavior.Strict);

            webWorker.Setup(w => w.ProcessUserAuthorization()).Returns(response).Verifiable();

            var client  = new MockOAuthClient(webWorker.Object);
            var context = new Mock <HttpContextBase>();

            // Act
            AuthenticationResult result = client.VerifyAuthentication(context.Object);

            // Assert
            webWorker.Verify();

            Assert.True(result.IsSuccessful);
            Assert.AreEqual("mockoauth", result.Provider);
            Assert.AreEqual("12345", result.ProviderUserId);
            Assert.AreEqual("super", result.UserName);
            Assert.IsNotNull(result.ExtraData);
            Assert.IsTrue(result.ExtraData.ContainsKey("accesstoken"));
            Assert.AreEqual("ok", result.ExtraData["accesstoken"]);
        }
Example #2
0
        public void VerifyAuthenticationFailsIfAccessTokenIsInvalid()
        {
            // Arrange
            var endpoint = new MessageReceivingEndpoint("http://live.com/path/?a=b", HttpDeliveryMethods.GetRequest);
            var request  = new AuthorizedTokenRequest(endpoint, new Version("1.0"));
            var response = new AuthorizedTokenResponse(request)
            {
                AccessToken = "invalid token"
            };

            var webWorker = new Mock <IOAuthWebWorker>(MockBehavior.Strict);

            webWorker.Setup(w => w.ProcessUserAuthorization()).Returns(response).Verifiable();

            var client  = new MockOAuthClient(webWorker.Object);
            var context = new Mock <HttpContextBase>();

            // Act
            AuthenticationResult result = client.VerifyAuthentication(context.Object);

            // Assert
            webWorker.Verify();

            Assert.False(result.IsSuccessful);
        }
		public void VerifyAuthenticationFailsIfResponseTokenIsNull() {
			// Arrange
			var webWorker = new Mock<IOAuthWebWorker>(MockBehavior.Strict);
			webWorker.Setup(w => w.ProcessUserAuthorization()).Returns((AuthorizedTokenResponse)null);

			var client = new MockOAuthClient(webWorker.Object);
			var context = new Mock<HttpContextBase>();

			// Act
			client.VerifyAuthentication(context.Object);

			// Assert
			webWorker.Verify();
		}
Example #4
0
        public void VerifyAuthenticationFailsIfResponseTokenIsNull()
        {
            // Arrange
            var webWorker = new Mock <IOAuthWebWorker>(MockBehavior.Strict);

            webWorker.Setup(w => w.ProcessUserAuthorization()).Returns((AuthorizedTokenResponse)null);

            var client  = new MockOAuthClient(webWorker.Object);
            var context = new Mock <HttpContextBase>();

            // Act
            client.VerifyAuthentication(context.Object);

            // Assert
            webWorker.Verify();
        }
		public void VerifyAuthenticationFailsIfAccessTokenIsInvalid() {
			// Arrange
			var endpoint = new MessageReceivingEndpoint("http://live.com/path/?a=b", HttpDeliveryMethods.GetRequest);
			var request = new AuthorizedTokenRequest(endpoint, new Version("1.0"));
			var response = new AuthorizedTokenResponse(request) {
				AccessToken = "invalid token"
			};

			var webWorker = new Mock<IOAuthWebWorker>(MockBehavior.Strict);
			webWorker.Setup(w => w.ProcessUserAuthorization()).Returns(response).Verifiable();

			var client = new MockOAuthClient(webWorker.Object);
			var context = new Mock<HttpContextBase>();

			// Act
			AuthenticationResult result = client.VerifyAuthentication(context.Object);

			// Assert
			webWorker.Verify();

			Assert.False(result.IsSuccessful);
		}
		public void VerifyAuthenticationSucceeds() {
			// Arrange
			var endpoint = new MessageReceivingEndpoint("http://live.com/path/?a=b", HttpDeliveryMethods.GetRequest);
			var request = new AuthorizedTokenRequest(endpoint, new Version("1.0"));
			var response = new AuthorizedTokenResponse(request) {
				AccessToken = "ok"
			};

			var webWorker = new Mock<IOAuthWebWorker>(MockBehavior.Strict);
			webWorker.Setup(w => w.ProcessUserAuthorization()).Returns(response).Verifiable();

			var client = new MockOAuthClient(webWorker.Object);
			var context = new Mock<HttpContextBase>();

			// Act
			AuthenticationResult result = client.VerifyAuthentication(context.Object);

			// Assert
			webWorker.Verify();

			Assert.True(result.IsSuccessful);
			Assert.AreEqual("mockoauth", result.Provider);
			Assert.AreEqual("12345", result.ProviderUserId);
			Assert.AreEqual("super", result.UserName);
			Assert.IsNotNull(result.ExtraData);
			Assert.IsTrue(result.ExtraData.ContainsKey("accesstoken"));
			Assert.AreEqual("ok", result.ExtraData["accesstoken"]);
		}