当前位置: 首页>>代码示例>>C#>>正文


C# AutoMoqer.Resolve方法代码示例

本文整理汇总了C#中AutoMoqer.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# AutoMoqer.Resolve方法的具体用法?C# AutoMoqer.Resolve怎么用?C# AutoMoqer.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AutoMoqer的用法示例。


在下文中一共展示了AutoMoqer.Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EpisodeAction_should_return_success_for_Library

        public void EpisodeAction_should_return_success_for_Library()
        {
            //Setup
            var expectedUrl = String.Format("{0}{1}", Url.ShowEpisodeLibrary, Constants.ApiKey);
            var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"tvdb_id\": 80379,\"imdb_id\": \"tt0898266\",\"title\": \"The Big Bang Theory\",\"year\": 2007,\"episodes\": [{\"season\": 1,\"episode\": 1}]}";
            var jsonResult = "{\"status\":\"success\",\"message\":\"1 episodes added to your library\"}";

            var mocker = new AutoMoqer();
            mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(expectedUrl, It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult);

            //Act
            var result = mocker.Resolve<ShowProvider>().EpisodeAction(
                                                                        Constants.ApiKey,
                                                                        "username",
                                                                        "sha1hash",
                                                                        ActionType.Library,
                                                                        new List<SeasonEpisodePair> { new SeasonEpisodePair { Season = 1, Episode = 1 } },
                                                                        80379,
                                                                        "tt0898266",
                                                                        "The Big Bang Theory",
                                                                        2007
                                                                    );

            //Assert
            result.Should().NotBeNull();
            result.Status.Should().Be(ResultStatusType.Success);
            result.Message.Should().Be("1 episodes added to your library");
        }
开发者ID:markus101,项目名称:Trakter,代码行数:28,代码来源:ShowProviderTests.cs

示例2: RequiresResponseTypeOfCode

        public void RequiresResponseTypeOfCode()
        {
            var mocker = new AutoMoqer();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ResponseType).Returns(" ");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("12345");

            var validator = mocker.Resolve<AuthorizationRequestValidator>();

            var result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result);
            Assert.AreEqual(ErrorCode.InvalidRequest, result.ErrorCode);
            Assert.IsFalse(string.IsNullOrWhiteSpace(result.ErrorDescription));

            mocker.GetMock<IOAuthRequest>().Setup(x => x.ResponseType).Returns("something_else");

            result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result);
            Assert.AreEqual(ErrorCode.InvalidRequest, result.ErrorCode);
            Assert.IsFalse(string.IsNullOrWhiteSpace(result.ErrorDescription));

            mocker.GetMock<IOAuthRequest>().Setup(x => x.ResponseType).Returns<string>(null);

            result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result);
            Assert.AreEqual(ErrorCode.InvalidRequest, result.ErrorCode);
            Assert.IsFalse(string.IsNullOrWhiteSpace(result.ErrorDescription));
        }
开发者ID:naasir,项目名称:OAuth2Provider,代码行数:33,代码来源:AuthorizationRequestValidatorTest.cs

示例3: RequiresClientSecret

        public void RequiresClientSecret()
        {
            var mocker = new AutoMoqer();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Method).Returns(HttpMethod.Post);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns(GrantType.ClientCredentials);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("clientid");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns<string>(null);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ContentType).Returns(ContentType.FormEncoded);

            var validator = mocker.Resolve<ClientCredentialsRequestValidator>();

            var result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);

            Assert.IsNotNull(result);
            Assert.AreEqual(ErrorCode.InvalidRequest, result.ErrorCode);
            Assert.IsFalse(string.IsNullOrWhiteSpace(result.ErrorDescription));

            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("  ");
            result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);

            Assert.IsNotNull(result);
            Assert.AreEqual(ErrorCode.InvalidRequest, result.ErrorCode);
            Assert.IsFalse(string.IsNullOrWhiteSpace(result.ErrorDescription));

            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("asdffa");
            result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);

            Assert.IsTrue(result.Success);
        }
开发者ID:naasir,项目名称:OAuth2Provider,代码行数:29,代码来源:ClientCredentialsRequestValidatorTest.cs

示例4: SendShout_should_return_a_success_response_for_a_movie_shout

        public void SendShout_should_return_a_success_response_for_a_movie_shout()
        {
            //Setup
            var expectedUrl = String.Format("{0}{1}", Url.ShoutMovie, Constants.ApiKey);
            var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"imdb_id\": \"tt0082971\",\"title\": \"Indiana Jones and the Raiders of the Lost Ark\",\"year\": 1981,\"shout\": \"I grew up with this movie and even today it is EPIC.\"}";
            var jsonResult = "{\"status\":\"success\",\"message\":\"shout added to Indiana Jones and the Raiders of the Lost Ark (1981)\"}";

            var mocker = new AutoMoqer();
            mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(expectedUrl, It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult);

            var shout = new ShoutMovie
            {
                Username = "username",
                Password = "sha1hash",
                ImdbId = "tt0082971",
                Title = "Indiana Jones and the Raiders of the Lost Ark",
                Year = 1981,
                Shout = "I grew up with this movie and even today it is EPIC."
            };

            //Act
            var result = mocker.Resolve<ShoutProvider>().SendShout(Constants.ApiKey, shout);

            //Assert
            result.Should().NotBeNull();
            result.Status.Should().Be(ResultStatusType.Success);
            result.Message.Should().Be("shout added to Indiana Jones and the Raiders of the Lost Ark (1981)");
        }
开发者ID:markus101,项目名称:Trakter,代码行数:28,代码来源:ShoutProviderTests.cs

示例5: Library_should_return_success

        public void Library_should_return_success()
        {
            //Setup
            var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"movies\": [{\"imdb_id\": \"tt0114746\",\"tmdb_id\": null,\"title\": \"Twelve Monkeys\",\"year\": 1995}]}";

            var jsonResult = "{\"status\": \"success\",\"inserted\": 1,\"already_exist\": 0,\"already_exist_movies\": [],\"skipped\": 0,\"skipped_movies\": []}";
            var movie = new TraktMovieSearch
            {
                ImdbId = "tt0114746",
                Title = "Twelve Monkeys",
                Year = 1995,
                Plays = 1,
                LastPlayed = new DateTime(2009, 10, 19, 1, 56, 18)
            };

            var mocker = new AutoMoqer();
            mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>(), It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult);

            //Act
            var result = mocker.Resolve<MovieProvider>().Library(Constants.ApiKey, "username", "sha1hash", new List<TraktMovieSearch> { movie });

            //Assert
            result.Should().NotBeNull();
            result.Status.Should().Be(ResultStatusType.Success);
            result.Inserted.Should().Be(1);
            result.Already_Exist.Should().Be(0);
            result.Already_Exist_Movies.Should().BeEmpty();
            result.Skipped.Should().Be(0);
            result.Skipped_Movies.Should().BeEmpty();
        }
开发者ID:markus101,项目名称:Trakter,代码行数:30,代码来源:MovieProviderTests.cs

示例6: SendShout_should_return_a_success_response_for_an_episode_shout

        public void SendShout_should_return_a_success_response_for_an_episode_shout()
        {
            //Setup
            var expectedUrl = String.Format("{0}{1}", Url.ShoutEpisode, Constants.ApiKey);
            var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"tvdb_id\": 213221,\"title\": \"Portlandia\",\"year\": 2011,\"season\": 1,\"episode\": 1,\"shout\": \"The opening musical number is just superb!\"}";
            var jsonResult = "{\"status\":\"success\",\"message\":\"shout added to Portlandia 1x01\"}";

            var mocker = new AutoMoqer();
            mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(expectedUrl, It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult);

            var shout = new ShoutEpisode
                            {
                                Username = "username",
                                Password = "sha1hash",
                                TvdbId = 213221,
                                Title = "Portlandia",
                                Year = 2011,
                                Season = 1,
                                Episode = 1,
                                Shout = "The opening musical number is just superb!"
                            };

            //Act
            var result = mocker.Resolve<ShoutProvider>().SendShout(Constants.ApiKey, shout);

            //Assert
            result.Should().NotBeNull();
            result.Status.Should().Be(ResultStatusType.Success);
            result.Message.Should().Be("shout added to Portlandia 1x01");
        }
开发者ID:markus101,项目名称:Trakter,代码行数:30,代码来源:ShoutProviderTests.cs

示例7: AddListItems_should_return_success_when_list_items_are_added

        public void AddListItems_should_return_success_when_list_items_are_added()
        {
            //Setup
            const string slug = "new-test-list";

            var items = new List<dynamic>();
            items.Add(new { Type = "movie", Tmdb_id = 161, Title = "Ocean's 11", Year = 2001 });
            items.Add(new { Type = "show", Title = "30 Rock", Tvdb_Id = 79488 });

            var expectedJson = "{\"username\":\"username\",\"password\":\"sha1hash\",\"slug\":\"new-test-list\",\"items\":[{\"type\":\"movie\",\"tmdb_id\":161,\"title\":\"Ocean's 11\",\"year\":2001},{\"type\":\"show\",\"title\":\"30 Rock\",\"tvdb_id\":79488}]}";

            var jsonResult = "{\"status\": \"success\",\"inserted\": 2,\"already_exist\": 0,\"skipped\": 0,\"skipped_array\": []}";

            var mocker = new AutoMoqer();
            mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>(), It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult);

            //Act
            var result = mocker.Resolve<ListProvider>().AddListItems(Constants.ApiKey, "username", "sha1hash", slug, items);

            //Assert
            result.Should().NotBeNull();
            result.Status.Should().Be(ResultStatusType.Success);
            result.Inserted.Should().Be(items.Count);
            result.Skipped.Should().Be(0);
            result.Already_Exist.Should().Be(0);
        }
开发者ID:markus101,项目名称:Trakter,代码行数:26,代码来源:ListProviderTests.cs

示例8: RequiresAuthorizationCodeGrantType

        public void RequiresAuthorizationCodeGrantType()
        {
            var mocker = new AutoMoqer();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns<string>(null);

            var validator = mocker.Resolve<AuthorizationCodeRequestValidator>();

            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns("");

            var result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);
            Assert.AreEqual(ErrorCode.InvalidRequest, result.ErrorCode);
            Assert.IsTrue(result.ErrorDescription.HasValue());

            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns("   ");

            result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);
            Assert.AreEqual(ErrorCode.InvalidRequest, result.ErrorCode);
            Assert.IsTrue(result.ErrorDescription.HasValue());

            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns("bad");

            result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);
            Assert.AreEqual(ErrorCode.InvalidGrant, result.ErrorCode);
            Assert.IsTrue(result.ErrorDescription.HasValue());

            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns(GrantType.AuthorizationCode);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.AuthorizationCode).Returns("authcode");
            result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);
            Assert.IsTrue(result.Success);
        }
开发者ID:naasir,项目名称:OAuth2Provider,代码行数:30,代码来源:AuthorizationCodeRequestValidatorTest.cs

示例9: WhenClientIdIsInvalid_ThenThrowsException

        public void WhenClientIdIsInvalid_ThenThrowsException()
        {
            var mocker = new AutoMoqer();
            mocker.MockServiceLocator();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ContentType).Returns(ContentType.FormEncoded);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("clientsecret");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Username).Returns("username");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Password).Returns("password");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns(GrantType.Password);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("clientid");
            mocker.GetMock<IConsumerRepository>().Setup(x => x.GetByClientId("clientid")).Returns<ConsumerImpl>(null);

            var authorizer = mocker.Resolve<PasswordTokenRequestAuthorizer>();

            try
            {
                authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object);
                Assert.Fail("Exception not thrown");
            }
            catch (OAuthException ex)
            {
                Assert.AreEqual(ErrorCode.InvalidClient, ex.ErrorCode);
                Assert.IsTrue(!string.IsNullOrWhiteSpace(ex.ErrorDescription));
            }
        }
开发者ID:joeyburgett,项目名称:OAuth2Provider,代码行数:26,代码来源:PasswordTokenRequestAuthorizerTest.cs

示例10: WhenAccessTokenIsExpired_ThenReturnFalse

        public void WhenAccessTokenIsExpired_ThenReturnFalse()
        {
            var mocker = new AutoMoqer();
            mocker.MockServiceLocator();

            var issuer = new OAuthIssuer();
            mocker.GetMock<IOAuthServiceLocator>().Setup(x => x.Issuer).Returns(issuer);
            mocker.GetMock<IConfiguration>().Setup(x => x.AccessTokenExpirationLength).Returns(3600);

            var validator = mocker.Resolve<ResourceRequestAuthorizer>();

            var token =
                issuer.GenerateAccessToken(new TokenData
                                               {
                                                   ConsumerId = 1,
                                                   ResourceOwnerId = 5,
                                                   Timestamp = DateTimeOffset.UtcNow.AddMinutes(-65).Ticks
                                               });

            mocker.GetMock<IOAuthRequest>().Setup(x => x.AccessToken).Returns(token);

            var result = validator.Authorize(mocker.GetMock<IOAuthRequest>().Object);

            Assert.IsFalse(result);
        }
开发者ID:naasir,项目名称:OAuth2Provider,代码行数:25,代码来源:ResourceRequestAuthorizerTest.cs

示例11: RequiresClientSecret

        public void RequiresClientSecret()
        {
            var mocker = new AutoMoqer();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns(GrantType.Password);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Username).Returns("username");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Password).Returns("password");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("clientid");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns<string>(null);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ContentType).Returns("application/x-www-form-urlencoded");

            var validator = mocker.Resolve<PasswordRequestValidator>();

            var result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);

            Assert.IsNotNull(result);
            Assert.AreEqual(ErrorCode.InvalidRequest, result.ErrorCode);
            Assert.IsFalse(string.IsNullOrWhiteSpace(result.ErrorDescription));

            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("  ");
            result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);

            Assert.IsNotNull(result);
            Assert.AreEqual(ErrorCode.InvalidRequest, result.ErrorCode);
            Assert.IsFalse(string.IsNullOrWhiteSpace(result.ErrorDescription));

            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("asdffa");
            result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);

            Assert.IsTrue(result.Success);
        }
开发者ID:naasir,项目名称:OAuth2Provider,代码行数:30,代码来源:PasswordRequestValidatorTest.cs

示例12: RateEpsiode_unrate_should_return_RateResult_on_success

        public void RateEpsiode_unrate_should_return_RateResult_on_success()
        {
            //Setup
            var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"tvdb_id\": 213221,\"title\": \"Portlandia\",\"year\": 2011,\"season\": 1,\"episode\": 1,\"rating\": \"unrate\"}";
            var jsonResult = "{\"status\":\"success\",\"message\":\"rated Portlandia 1x01\",\"type\":\"episode\",\"rating\":\"unrate\",\"ratings\":{\"percentage\":100,\"votes\":2,\"loved\":2,\"hated\":0},\"facebook\":true,\"twitter\":true,\"tumblr\":false}";

            var episode = new RateEpisode
            {
                Username = "username",
                Password = "sha1hash",
                TvdbId = 213221,
                Title = "Portlandia",
                Year = 2011,
                Season = 1,
                Episode = 1,
                Rating = RatingType.Unrate
            };

            var mocker = new AutoMoqer();
            mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>(), It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult);

            //Act
            var result = mocker.Resolve<RateProvider>().Episode(Constants.ApiKey, episode);

            //Assert
            result.Should().NotBeNull();
            result.Status.Should().Be(ResultStatusType.Success);
            result.Rating.Should().Be(RatingType.Unrate);
            result.Facebook.Should().BeTrue();
            result.Type.Should().Be(TraktType.Episode);
        }
开发者ID:markus101,项目名称:Trakter,代码行数:31,代码来源:RateProviderTests.cs

示例13: AddList_should_return_success_when_list_is_added

        public void AddList_should_return_success_when_list_is_added()
        {
            //Setup
            const string name = "Top 10 of 2011";
            const ListPrivacyType privacy = ListPrivacyType.Public;
            const string description = "These movies and shows really defined 2011 for me.";

            var expectedJson = @"{""username"": ""username"",""password"": ""sha1hash"",""name"": ""Top 10 of 2011"",""description"": ""These movies and shows really defined 2011 for me."",""privacy"": ""public""}";

            var jsonResult = "{\"status\":\"success\",\"message\":\"list added\",\"name\":\"Top 10 of 2011\",\"slug\":\"top-10-of-2011\",\"privacy\":\"public\"}";

            var mocker = new AutoMoqer();
            mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>(), It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult);

            //Act
            var result = mocker.Resolve<ListProvider>().AddList(Constants.ApiKey, "username", "sha1hash", name, privacy, description);

            //Assert
            result.Should().NotBeNull();
            result.Status.Should().Be(ResultStatusType.Success);
            result.Message.Should().Be("list added");
            result.Name.Should().Be(name);
            result.Slug.Should().Be(name.Replace(' ', '-').ToLowerInvariant());
            result.Privacy.Should().Be(privacy);
        }
开发者ID:markus101,项目名称:Trakter,代码行数:25,代码来源:ListProviderTests.cs

示例14: ReturnsAuthorizedToken

        public void ReturnsAuthorizedToken()
        {
            var mocker = new AutoMoqer();
            mocker.MockServiceLocator();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ContentType).Returns(ContentType.FormEncoded);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("clientid");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("clientsecret");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Username).Returns("username");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns(GrantType.Password);
            mocker.GetMock<IConsumerRepository>().Setup(x => x.GetByClientId("clientid")).Returns(new ConsumerImpl { ConsumerId = 1, ClientId = "clientid", Secret = "clientsecret" });
            mocker.GetMock<IResourceOwnerRepository>().Setup(x => x.GetByUsername(1, "username")).Returns(new ResourceOwnerImpl { ResourceOwnerId = 2, Username = "username", Password = "password".ToHash() });
            mocker.GetMock<IPasswordHasher>().Setup(x => x.CheckPassword("password", "password".ToHash())).Returns(true);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Password).Returns("password");
            mocker.GetMock<IConfiguration>().Setup(x => x.AccessTokenExpirationLength).Returns(3600);
            mocker.GetMock<IOAuthServiceLocator>().Setup(x => x.Issuer).Returns(new OAuthIssuer());

            var authorizer = mocker.Resolve<PasswordTokenRequestAuthorizer>();

            var token = authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object);

            mocker.GetMock<IResourceOwnerRepository>().Verify(x => x.ApproveConsumer(2, 1), Times.Once());
            Assert.IsNotNull(token);
            Assert.IsNotNull(token.AccessToken);
            Assert.AreEqual(3600, token.ExpiresIn);
            Assert.IsNotNull(token.RefreshToken);
        }
开发者ID:joeyburgett,项目名称:OAuth2Provider,代码行数:26,代码来源:PasswordTokenRequestAuthorizerTest.cs

示例15: RequiresAuthorizationCodeGrantType

        public void RequiresAuthorizationCodeGrantType()
        {
            var mocker = new AutoMoqer();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns<string>(null);

            var authorizer = mocker.Resolve<AuthorizationCodeAuthorizer>();

            try
            {
                authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object);
                Assert.Fail("Exception not thrown.");
            }
            catch (OAuthException ex)
            {
                Assert.AreEqual(ErrorCode.InvalidRequest, ex.ErrorCode);
                Assert.IsTrue(ex.ErrorDescription.HasValue());
            }

            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns("");

            try
            {
                authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object);
                Assert.Fail("Exception not thrown.");
            }
            catch (OAuthException ex)
            {
                Assert.AreEqual(ErrorCode.InvalidRequest, ex.ErrorCode);
                Assert.IsTrue(ex.ErrorDescription.HasValue());
            }

            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns("   ");

            try
            {
                authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object);
                Assert.Fail("Exception not thrown.");
            }
            catch (OAuthException ex)
            {
                Assert.AreEqual(ErrorCode.InvalidRequest, ex.ErrorCode);
                Assert.IsTrue(ex.ErrorDescription.HasValue());
            }

            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns("asdf");

            try
            {
                authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object);
                Assert.Fail("Exception not thrown.");
            }
            catch (OAuthException ex)
            {
                Assert.AreEqual(ErrorCode.InvalidGrant, ex.ErrorCode);
                Assert.IsTrue(ex.ErrorDescription.HasValue());
            }
        }
开发者ID:naasir,项目名称:OAuth2Provider,代码行数:57,代码来源:AuthorizationCodeAuthorizerTest.cs


注:本文中的AutoMoqer.Resolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。