private Mock <ISFUtilities> BuildWithToken(SF_Token token) { var utility = new Mock <ISFUtilities>(); var request = new Mock <WebRequest>(); request.SetupProperty(x => x.Method); request.SetupProperty(x => x.ContentType); utility.Setup(x => x.ReadToken <SF_Token>(It.IsAny <WebRequest>())).Returns(token); utility.Setup(x => x.CreateWebRequest(It.IsAny <string>())).Returns(request.Object); return(utility); }
public void GetToken_PassNotNullAuthecationCode_ReturnNotNullToken() { // Arrange var expectedToken = new SF_Token(); var utility = BuildWithToken(expectedToken); AuthenticationHelper.InitUtilities(utility.Object); // Act var result = AuthenticationHelper.GetToken <SF_Token>(Endpoint, ConsumerKey, ConsumerSecret, RedirectUrl, AuthCode); // Assert result.ShouldBe(expectedToken); utility.Verify(x => x.LogWebException(It.IsAny <WebException>(), It.IsAny <string>()), Times.Never); utility.Verify(x => x.ReadToken <SF_Token>( It.Is <WebRequest>( r => r.Method == HttpPost && r.ContentType == ContentType)), Times.Once); }