public void RequestAccessToken_ReceivedTokenIsCorrect() { ProtocolResponse oauthResponse = CreateSwtTokenResponse(); IHttpClient httpAdapter = Substitute.For<IHttpClient>(); httpAdapter.SendRequest(Arg.Any<ProtocolRequest>()).Returns(oauthResponse); var flow = new AcsClientAccountPasswordFlow(_serviceUri, _tokenRequest, httpAdapter); SwtSecurityToken receivedToken = flow.GetAccessToken() as SwtSecurityToken; Assert.AreEqual("myScope", receivedToken.Audience); Assert.AreEqual("http://mysts", receivedToken.Issuer); Assert.Greater(DateTime.UtcNow, receivedToken.ValidTo); }
public void RequestAccessToken_RequestContentIsCorrect() { ProtocolResponse oauthResponse = CreateSwtTokenResponse(); IHttpClient httpAdapter = Substitute.For<IHttpClient>(); ProtocolRequest receivedRequest = null; httpAdapter.SendRequest(Arg.Do<ProtocolRequest>(request => receivedRequest = request)) .Returns(oauthResponse); var flow = new AcsClientAccountPasswordFlow(_serviceUri, _tokenRequest, httpAdapter); flow.GetAccessToken(); httpAdapter.Received(1).SendRequest(Arg.Any<ProtocolRequest>()); Assert.AreEqual(receivedRequest.BodyParameters["wrap_name"], _tokenRequest.ClientId); Assert.AreEqual(receivedRequest.BodyParameters["wrap_password"], _tokenRequest.ClientSecret); Assert.AreEqual(receivedRequest.BodyParameters["wrap_scope"], _tokenRequest.Scope); }
public void RequestAccessToken_RequestUrlIsCorrect() { ProtocolResponse oauthResponse = CreateSwtTokenResponse(); IHttpClient httpAdapter = Substitute.For<IHttpClient>(); ProtocolRequest receivedRequest = null; httpAdapter.SendRequest(Arg.Do<ProtocolRequest>(request => receivedRequest = request)) .Returns(oauthResponse); var flow = new AcsClientAccountPasswordFlow(_serviceUri, _tokenRequest, httpAdapter); // Act flow.GetAccessToken(); // Assert httpAdapter.Received(1).SendRequest(Arg.Any<ProtocolRequest>()); Uri expectedUri = new Uri(_serviceUri, "/WRAPv0.9/"); Assert.AreEqual(expectedUri, receivedRequest.Url.BuildUri()); }