public void Execute_WordIsNotPlural_ReturnsEmptyString() { var unpluralizeWord = mocker.Resolve <UnpluralizeWord>(); var result = unpluralizeWord.Execute("category"); Assert.AreEqual("category", result); }
public void Returns_deserialized_instances_from_file_system() { mocker.GetMock <IGetDataPathForType>() .Setup(a => a.GetPathForDataByType(typeof(DataClass))) .Returns("/path/"); mocker.GetMock <IFileSystem>() .Setup(a => a.GetFiles("/path/", "*.xml")) .Returns(new string[] { "/path/1.xml", "/path/2.xml", }); mocker.GetMock <IXmlFileSerializationHelper>() .Setup(a => a.DeserializeFromPath <DataClass>("/path/1.xml")) .Returns(new DataClass() { Id = "1", }); mocker.GetMock <IXmlFileSerializationHelper>() .Setup(a => a.DeserializeFromPath <DataClass>("/path/2.xml")) .Returns(new DataClass() { Id = "2", }); var results = mocker.Resolve <EasyObjectStore <DataClass> >().GetAll(); Assert.AreEqual(2, results.Count()); Assert.AreEqual(1, results.Where(a => a.Id == "1").Count()); Assert.AreEqual(1, results.Where(a => a.Id == "2").Count()); }
public void Assert_Refueler_Does_Not_Overfill() { var refuler = autoMoqer.Resolve <RefuelerService>(); var fuelTank = new FuelTank(FuelType.Oxygen, 3); Assert.Throws <PreventOverfillException>(() => refuler.AddFuel(fuelTank, FuelType.Oxygen, 5)); }
UserAuthenticateCommand_WithRequiredPropertiesNotInformed_Handle_ShouldReturnAllErrors() { //Arrange DomainEvent.Register <DomainNotification>(dn => _notifications.Add(dn)); _mocker.GetMock <IValidationService>() .Setup(v => v.Validate(It.IsAny <ICommand>())) .Returns(() => true); var invalidCommand = new UserAuthenticateCommandBuilder(); var handler = _mocker.Resolve <UserCommandHandler>(); //Act handler.Handle(invalidCommand); //Assert _notifications.Should() .NotBeEmpty() .And.Contain(n => n.Value == Domain.Main.Resources.Messages.UserAuthenticateUserRequired) .And.Contain(n => n.Value == Domain.Main.Resources.Messages.UserAuthenticatePasswordRequired) .And.HaveCount(2); _mocker.GetMock <IValidationService>().Verify(x => x.Validate(It.IsAny <ICommand>()), Times.Once()); }
public void Creates_temp_working_folder() { mocker.Resolve <TextTemplateBatchProcessor>().ProcessBatch(new TextTemplateBatch()); mocker.GetMock <IFileSystem>() .Verify(a => a.CreateFolder(GetTemporaryWorkingFolderPath()), Times.Once()); }
public void Returns_a_genric_principal() { var creator = mocker.Resolve <DefaultUnauthenticatedPrincipalCreator>(); var result = creator.Create(); result.ShouldBeType(typeof(GenericPrincipal)); }
public void Execute_Category_ReturnsDogs() { var pluralizeWord = mocker.Resolve <PluralizeWord>(); var result = pluralizeWord.Execute("category"); Assert.AreEqual("categories", result); }
public void Returns_non_null_input_model_when_passed_null() { var result = mocker.Resolve <ModifyViewModelBuilder>() .BuildViewModel(null); Assert.IsNotNull(result.InputModel); }
public void Returns_correct_dictionary() { var result = mocker.Resolve <GetDictionaryFromStringArray>().GetDictionaryFrom2DimensionalArray(array); Assert.AreEqual("token1", result.First().Key); Assert.AreEqual("value1", result.First().Value); }
public void Arrange() { _mocker = new AutoMoqer(); _mocker.GetMock <IHashingService>() .Setup(x => x.DecodeValue(It.IsAny <string>())) .Returns(ExpectedAccountId); _mocker.GetMock <CurrentBalance>() .Setup(x => x.RefreshBalance(It.IsAny <bool>(), It.IsAny <bool>())).ReturnsAsync(true); _mocker.GetMock <ICurrentBalanceRepository>() .Setup(x => x.Get(ExpectedAccountId)) .ReturnsAsync(_mocker.Resolve <CurrentBalance>()); _mocker.GetMock <IAccountEstimationProjection>() .Setup(x => x.Projections) .Returns(new List <AccountEstimationProjectionModel>().AsReadOnly); _mocker.GetMock <IAccountEstimationProjection>() .Setup(x => x.TransferAllowance) .Returns(400m); _accountEstimationProjection = _mocker.Resolve <IAccountEstimationProjection>(); _mocker.GetMock <IAccountEstimationProjectionRepository>() .Setup(x => x.Get(It.IsAny <AccountEstimation>(), false)) .ReturnsAsync(_accountEstimationProjection); _mocker.GetMock <IExpiredFundsService>() .Setup(s => s.GetExpiringFunds(It.IsAny <ReadOnlyCollection <AccountEstimationProjectionModel> >(), It.IsAny <long>(), It.IsAny <ProjectionGenerationType>(), It.IsAny <DateTime>())).ReturnsAsync(new Dictionary <CalendarPeriod, decimal>()); _orchestrator = _mocker.Resolve <EstimationOrchestrator>(); }
public void End_ShouldNullifyLoggedInAsOnSession() { SetupMockParameters(); _autoMoqer.Resolve <SessionAuthentication>().End(); _autoMoqer.GetMock <HttpSessionStateBase>().VerifySet(x => x["LoggedInAs"] = null, Times.Once()); }
public async Task Uses_Repository_To_Get_Levy_Period() { var handler = Moqer.Resolve <StoreLevyDeclarationHandler>(); await handler.Handle(LevySchemeDeclaration, "forecasting-levy-allow-projection"); Moqer.GetMock <ILevyDeclarationRepository>() .Verify(x => x.Get(It.Is <LevyDeclarationModel>(c => c.SubmissionId.Equals(LevySchemeDeclaration.SubmissionId))), Times.Once()); }
public async Task Rejects_Requests_Generated_More_Than_5_Mins_In_The_Past() { var handler = _moqer.Resolve <GetCoursesHandler>(); var courses = await handler.Handle( new RefreshCourses { RequestTime = DateTime.Now.AddMinutes(-10), CourseType = CourseType.Standards }); Assert.AreEqual(0, courses.Count(m => m.Id.StartsWith("standard"))); }
private LocalEventBus CreateLocalEventBus() { var typeCatalog = mocker.Resolve <ITypeCatalog>(); var factory = mocker.Resolve <IDomainEventHandlerFactory>(); var eventHandlerTypes = typeCatalog.GetGenericInterfaceImplementations(typeof(IHandleDomainEvents <>)); return(new LocalEventBus(eventHandlerTypes, factory)); }
public void Execute_BinaryPropertyTypeName_ReturnsFileUpload() { var getViewerFieldControlTypeByEntityPropertyAction = mocker.Resolve<GetViewerFieldControlTypeByEntityPropertyAction>(); var result = getViewerFieldControlTypeByEntityPropertyAction.Execute(new CATALYST.Core.Objects.EntityProperty() { TypeName = EntityProperty.TypeName_Binary }); Assert.AreEqual(ViewerControlType.FileUpload, result); }
public void Execute_BinaryProperty_ReturnsString() { var convertEntityTypeNameToCLRTypeNameAction = mocker.Resolve <ConvertEntityTypeNameToCLRTypeNameAction>(); var result = convertEntityTypeNameToCLRTypeNameAction.Execute(new CATALYST.Core.Objects.EntityProperty() { TypeName = EntityProperty.TypeName_Binary }); Assert.AreEqual("string", result); }
public void Deletes_text_templates_but_not_other_files() { mocker.GetMock <IFileSystem>().Setup(a => a.GetFiles("path")) .Returns(new string[] { "file1.tt", "file2.txt" }); mocker.Resolve <RecursivelyDeleteTtFilesInPathService>() .RecursivelyDeleteTtFilesInPath("path"); mocker.GetMock <IFileSystem>().Verify(a => a.DeleteFile("file1.tt"), Times.Once()); mocker.GetMock <IFileSystem>().Verify(a => a.DeleteFile("file2.txt"), Times.Never()); }
public void GetProperties_Null_Returns2CorrectNavigationPropertyNames() { mocker.GetMock <IGetPathToEdmxFileAction>().Setup(a => a.Execute()).Returns(@"C:\_APPLICATION\CATALYST\CATALYST\CATALYST.Core.Tests\Actions\EdmxIntegration\Model1.edmx"); var retrieveNavigationPropertiesByEntityName = mocker.Resolve <RetrieveNavigationPropertiesByEntityName>(); var result = retrieveNavigationPropertiesByEntityName.GetProperties("TestEntity2"); Assert.AreEqual(2, result.Count()); Assert.AreEqual(1, result.Where(a => a.Name == "TestEntity2Category").Count()); Assert.AreEqual(1, result.Where(a => a.Name == "Faqs").Count()); }
public void Execute_FileSystemContains1Dir_VerifyRecursionOnDirectory() { var removeAllFilesButLeaveDirectoryStructureAction = mocker.Resolve <RemoveAllFilesButLeaveDirectoryStructureAction>(); mocker.GetMock <IFileSystem>().Setup(a => a.GetFiles("folder")).Returns(new string[] { "deleteme" }); mocker.GetMock <IFileSystem>().Setup(a => a.GetDirectories("path")).Returns(new string[] { "folder" }); removeAllFilesButLeaveDirectoryStructureAction.Execute("path"); mocker.GetMock <IFileSystem>().Verify(a => a.DeleteFile("deleteme"), Times.Once()); }
public void Does_not_add_files_that_do_not_end_with_tt_extension_to_queue() { mocker.GetMock <IFileSystem>().Setup(a => a.GetFiles("path")) .Returns(new string[] { "file1.tt", "file2.txt" }); var result = mocker.Resolve <CreateQueueFromPathService>().RecursivelyBuildQueueFromPath("path"); Assert.AreEqual(1, result.QueueItems.Count()); Assert.AreEqual(1, result.QueueItems.Where(a => a.InputPath == "file1.tt").Count()); Assert.AreEqual(0, result.QueueItems.Where(a => a.InputPath == "file2.txt").Count()); }
public void Calls_Delete_method_of_IFileSystem_with_correct_path_when_the_file_exists() { mocker.GetMock <IFileSystem>().Setup(a => a.FileExists("/path/id.xml")).Returns(true); mocker.GetMock <IGetDataPathForType>().Setup(a => a.GetPathForDataByType(typeof(DataClass))) .Returns("/path/"); mocker.Resolve <EasyObjectStore <DataClass> >().Delete("id"); mocker.GetMock <IFileSystem>() .Verify(a => a.DeleteFile("/path/id.xml"), Times.Once()); }
public void GetStateFromFile_FileContainsValidSTate_ReturnsCorrectReplaceTag4() { mocker.GetMock<IGetFileContents>().Setup(a => a.Execute(It.IsAny<string>())).Returns(GetTestXml()); var serializeStateFromFile = mocker.Resolve<DeserializeStateFromFile>(); var result = serializeStateFromFile.GetStateFromFile(); Assert.AreEqual("ReplaceTag4", result.ReplaceTag4); }
public void CreateUnauthenticatedPrincipal_returns_the_principal_from_the_unauthorized_principal_creator() { var expected = new Mock <IPrincipal>().Object; mocker.GetMock <IUnauthenticatedPrincipalCreator>() .Setup(x => x.Create()) .Returns(expected); var creator = mocker.Resolve <PrincipalCreator>(); var result = creator.CreateUnauthenticatedPrincipal(); result.ShouldBeSameAs(expected); }
public void Sets_the_principal_to_an_unauthenticated_principal_when_passed_a_null_principal() { var expected = CreateAPrincipal(); ThePrincipalCreatorWillReturnThisAsAnUnauthenticatedPrincipal(expected); var context = mocker.Resolve <AuthenticationContext>(); context.Authenticate(null); mocker.GetMock <IPrincipalContext>() .Verify(x => x.SetPricipal(expected), Times.Once()); }
public void WhenANewMessageIsAvailableInTheInbox() { MailMessage mailMessage = new MailMessage(string.Empty, string.Empty, null); mocker.GetMock <IMailRepository>() .Setup(messages => messages.GetUnreadMails("INBOX")) .Returns(new List <MailMessage> { mailMessage }); _mailRepository = mocker.Resolve <IMailRepository>(); var newMessages = _mailRepository.GetUnreadMails("INBOX"); }
public void Execute_ValidFilCcontents_ReturnsCorrectOutputFilename() { mocker.GetMock <ICore>().Setup(a => a.GetState()).Returns(new T4ProcessState() { Classname = "className" }); var createCodeGenerationQueueFromXmlFile = mocker.Resolve <CreateCodeGenerationQueueFromXml>(); var result = createCodeGenerationQueueFromXmlFile.Execute(@"<Root><T4File InputFilename=""TestTemplate.tt"" OutputFilename=""OutputFilename_::Classname::.cs"" /></Root>"); Assert.AreEqual(1, result.Count()); Assert.AreEqual(@"OutputFilename_className.cs", result.First().OutputFilename); }
public void Returns_value_of_Id_field() { mocker.GetMock <IGetNameOfIdPropertyForType>() .Setup(a => a.GetNameOfIdProperty(typeof(Test1))) .Returns("Id"); var result = mocker.Resolve <GetValueOfIdPropertyForInstance>() .GetId(new Test1() { Id = "1" }); Assert.AreEqual("1", result); }
public async Task Positive_LevyAmount_Returns_Projection() { var levyDataSession = _moqer.GetMock <ILevyDataSession>(); levyDataSession.Setup(s => s.GetLatestLevyAmount(12345)).ReturnsAsync(400); var sut = _moqer.Resolve <AccountProjectionRepository>(); var projection = await sut.InitialiseProjection(12345); projection.Should().BeOfType <AccountProjection>(); projection.EmployerAccountId.Should().Be(12345); projection.BuildLevyTriggeredProjections(DateTime.Now, 24); projection.Projections.Count.Should().Be(25); }
public void ExecuteAndReturnErrors_QueueWirhItem_VerifyCreateDirectoryFromFilenameActionCalledForItemOutputFile() { mocker.GetMock <IT4TemplateHostWrapper>().Setup(a => a.Errors).Returns(new string[] { "error" }); var codeGenerationQueueConsumer = mocker.Resolve <CodeGenerationQueueConsumer>(); var result = codeGenerationQueueConsumer.ExecuteAndReturnErrors(new List <CodeGenerationQueueItem>() { new CodeGenerationQueueItem() { OutputFilename = "outputfile" } }); mocker.GetMock <ICreateDirectoryFromFilenameAction>().Verify(a => a.Execute("outputfile"), Times.Once()); }
public void Setup() { _autoMoq = new AutoMoqer(); var _model = new AccountEstimationModel { Id = Guid.NewGuid().ToString("N"), Apprenticeships = new List <VirtualApprenticeship>(), EmployerAccountId = AccountId, EstimationName = "default" }; var p = _autoMoq.GetMock <IAccountEstimationProjection>(); p.Setup(x => x.BuildProjections()).Verifiable(); IList <AccountProjectionReadModel> projectionModel = new List <AccountProjectionReadModel> { new AccountProjectionReadModel { EmployerAccountId = 10000, Month = 4, Year = 2018, FutureFunds = 15000m, TotalCostOfTraining = 0m } }; p.Setup(o => o.Projections) .Returns(new ReadOnlyCollection <AccountProjectionReadModel>(projectionModel)); _autoMoq.SetInstance(_model); _autoMoq.GetMock <IHashingService>() .Setup(o => o.DecodeValue(HashedAccountId)) .Returns(AccountId); _autoMoq.GetMock <IAccountEstimationRepository>() .Setup(x => x.Get(It.IsAny <long>())) .Returns(Task.FromResult(_autoMoq.Resolve <AccountEstimation>())); _autoMoq.GetMock <IAccountEstimationProjectionRepository>() .Setup(x => x.Get(It.IsAny <AccountEstimation>())) .Returns(Task.FromResult(p.Object)); _estimationOrchestrator = _autoMoq.Resolve <EstimationOrchestrator>(); }
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 = "******", 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); }
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); }
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); }
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); }
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); }
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)); }
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"); }
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 = "******", Password = "******", 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)"); }
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(); }
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 = "******", Password = "******", 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"); }
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)); } }
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); }
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 = "******", Password = "******", 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); }
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); }
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()); } }
public void WhenAccessTokenIsIncluded_ThenValidationSucceeds() { var mocker = new AutoMoqer(); mocker.GetMock<IOAuthRequest>().Setup(x => x.AccessToken).Returns("accesstoken"); var validator = mocker.Resolve<ResourceRequestValidator>(); var result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object); Assert.IsTrue(result.Success); }
public void Trending_should_return_currently_trending_movies() { //Setup var jsonResult = File.ReadAllText(@".\Files\Movies_Trending.txt"); var expectedUrl = String.Format("{0}{1}", Url.MoviesTrending, Constants.ApiKey); var mocker = new AutoMoqer(); mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(expectedUrl)).Returns(jsonResult); //Act var result = mocker.Resolve<MoviesProvider>().Trending(Constants.ApiKey); //Assert result.Should().HaveCount(2); }
public void WhenAccessTokenIsMissing_ThenValidationFails() { var mocker = new AutoMoqer(); mocker.GetMock<IOAuthRequest>().Setup(x => x.AccessToken).Returns(""); var validator = mocker.Resolve<ResourceRequestValidator>(); var result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object); Assert.IsFalse(result.Success); mocker.GetMock<IOAuthRequest>().Setup(x => x.AccessToken).Returns<string>(null); result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object); Assert.IsFalse(result.Success); }
public void DismissShow_should_return_success_with_movie() { //Setup var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"tvdb_id\": 80348}"; var jsonResult = "{\"status\":\"success\",\"message\":\"dismissed Chuck\",\"movie\":{\"title\":\"Chuck\",\"year\":\"2007\",\"imdb_id\":\"tt0934814\",\"tmdb_id\":\"80348\"}}"; 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<RecommendationsProvider>().DismissShow(Constants.ApiKey, "username", "sha1hash", null, 80348); //Assert result.Should().NotBeNull(); result.Movie.Title.Should().Be("Chuck"); }
public void GetShowGenres_should_return_List_of_Genre() { //Setup var date = new DateTime(2011, 11, 02); var jsonResult = File.ReadAllText(@".\Files\Genres.txt"); var mocker = new AutoMoqer(); mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>())).Returns(jsonResult); //Act var result = mocker.Resolve<GenreProvider>().GetShowGenres(Constants.ApiKey); //Assert result.Should().NotBeEmpty(); }
public void GetPremieres_should_return_list_of_days() { //Setup var date = new DateTime(2011, 11, 02); var jsonResult = File.ReadAllText(@".\Files\Calendar_Premieres.txt"); var mocker = new AutoMoqer(); mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>())).Returns(jsonResult); //Act var result = mocker.Resolve<CalendarProvider>().GetPremieres(Constants.ApiKey, date); //Assert result.Should().HaveCount(1); Console.WriteLine(result); }
public void GetShows_should_return_empty_result_when_no_data_is_returned_from_server() { //Setup var date = new DateTime(2020, 01, 01); var jsonResult = "[ ]"; var mocker = new AutoMoqer(); mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>())).Returns(jsonResult); //Act var result = mocker.Resolve<CalendarProvider>().GetShows(Constants.ApiKey, date); //Assert result.Should().BeEmpty(); Console.WriteLine(result); }
public void People_should_return_list_of_PeopleSearchResult() { //Setup var searchTerm = "christian bale"; var expectedUrl = String.Format("{0}{1}/{2}", Url.SearchPeople, Constants.ApiKey, "christian+bale"); var jsonResult = File.ReadAllText(@".\Files\Search_People.txt"); var mocker = new AutoMoqer(); mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(expectedUrl)).Returns(jsonResult); //Act var result = mocker.Resolve<SearchProvider>().People(Constants.ApiKey, searchTerm); //Assert result.Should().HaveCount(1); result.First().Birthday.Should().Be(new DateTime(1974, 1, 30)); }
public void CancelledWatching_should_return_success() { //Setup var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\"}"; var jsonResult = "{\"status\":\"success\",\"message\":\"cancelled watching\"}"; 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<ShowProvider>().CancelWatching(Constants.ApiKey, "username", "sha1hash"); //Assert result.Should().NotBeNull(); result.Status.Should().Be(ResultStatusType.Success); result.Message.Should().Be("cancelled watching"); }
public void Episodes_should_return_list_of_EpisodeSearchResult() { //Setup var searchTerm = "warfare"; var expectedUrl = String.Format("{0}{1}/{2}", Url.SearchEpisodes, Constants.ApiKey, searchTerm); var jsonResult = File.ReadAllText(@".\Files\Search_Episodes.txt"); var mocker = new AutoMoqer(); mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(expectedUrl)).Returns(jsonResult); //Act var result = mocker.Resolve<SearchProvider>().Episodes(Constants.ApiKey, searchTerm); //Assert result.Should().HaveCount(1); result.First().Show.Title.Should().Be("Community"); }
public void Movies_should_return_list_of_movies() { //Setup var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"genre\": \"action\"}"; var jsonResult = "[{\"title\":\"The Expendables\",\"year\":2010,\"released\":1283410800,\"url\":\"http://trakt.tv/movie/the-expendables-2010\",\"runtime\":103,\"tagline\":\"Choose Your Weapon.\",\"overview\":\"Barney Ross (Stallone) leads a band of highly skilled mercenaries including knife enthusiast Lee Christmas (Statham), a martial arts expert, heavy weapons specialist, demolitionist, and a loose-cannon sniper. When the group is commissioned by the mysterious Mr. Church to assassinate the dictator of a small South American island, Barney and Lee visit the remote locale to scout out their opposition and discover the true nature of the conflict engulfing the city.\",\"certification\":\"R\",\"imdb_id\":\"tt1320253\",\"tmdb_id\":\"27578\",\"images\":{\"poster\":\"http://vicmackey.trakt.tv/images/posters_movies/304.jpg\",\"fanart\":\"http://vicmackey.trakt.tv/images/fanart_movies/304.jpg\"},\"ratings\":{\"percentage\":69,\"votes\":36,\"loved\":25,\"hated\":11}}]"; 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<RecommendationsProvider>().Movies(Constants.ApiKey, "username", "sha1hash", new Genre{ Name = "Action", Slug = "action" }); //Assert result.Should().HaveCount(1); result.First().Year.Should().Be(2010); result.First().Runtime.Should().Be(103); result.First().TmdbId.Should().Be(27578); }
public void EnsureApplicationIsApproved() { var mocker = new AutoMoqer(); 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 = "******", Password = "******".ToHash() }); mocker.GetMock<IOAuthRequest>().Setup(x => x.Password).Returns("password"); mocker.SetInstance<IOAuthIssuer>(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()); }
public void ReturnsAuthorizedToken() { var mocker = new AutoMoqer(); mocker.MockServiceLocator(); mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("clientid"); mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("clientsecret"); mocker.GetMock<IConsumerRepository>().Setup(x => x.GetByClientId("clientid")).Returns(new ConsumerImpl { ConsumerId = 1, ClientId = "clientid", Secret = "clientsecret" }); mocker.GetMock<IConfiguration>().Setup(x => x.AccessTokenExpirationLength).Returns(3600); mocker.GetMock<IOAuthServiceLocator>().Setup(x => x.Issuer).Returns(new OAuthIssuer()); var authorizer = mocker.Resolve<ClientCredentialsTokenRequestAuthorizer>(); var token = authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object); Assert.IsNotNull(token); Assert.IsNotNull(token.AccessToken); Assert.AreEqual(3600, token.ExpiresIn); Assert.IsNotNull(token.RefreshToken); }
public void Movies_should_return_list_of_TraktMovie() { //Setup var searchTerm = "batman"; var expectedUrl = String.Format("{0}{1}/{2}", Url.SearchMovies, Constants.ApiKey, searchTerm); var jsonResult = File.ReadAllText(@".\Files\Search_Movies.txt"); var mocker = new AutoMoqer(); mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(expectedUrl)).Returns(jsonResult); //Act var result = mocker.Resolve<SearchProvider>().Movies(Constants.ApiKey, searchTerm); //Assert result.Should().HaveCount(1); result.First().Title.Should().Be("Batman"); result.First().Released.Should().HaveYear(1989); result.First().Released.Should().HaveMonth(6); result.First().Released.Should().HaveDay(23); }
public void WhenClientSecretIsInvalid_ThenThrowsException() { var mocker = new AutoMoqer(); mocker.MockServiceLocator(); mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("clientid"); mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("clientsecret"); mocker.GetMock<IConsumerRepository>().Setup(x => x.GetByClientId("clientid")).Returns(new ConsumerImpl { ClientId = "clientid", Secret = "secret" }); var authorizer = mocker.Resolve<ClientCredentialsTokenRequestAuthorizer>(); 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)); } }