public void When_GetPhotos_is_called_and_no_PhotoAdapterSettings_have_been_stored_then_an_AuthorizationException_is_thrown_and_GetPhotos_on_the_PhotoAdapter_is_never_called() { var adapterSettings = AdapterSettingsCreator.CreateSingle(); adapterSettings.OAuthAccessToken = null; adapterSettings.OAuthRequestToken = null; BandRepository .Expect(repository => repository.GetAdapterSettings(Arg <string> .Is.Anything)) .Throw(new InvalidOperationException()) .Repeat.Once(); BandRepository .Expect(repository => repository.AddAdapterSettings(Arg <AdapterSettings> .Is.Anything)) .Return(adapterSettings) .Repeat.Once(); BandRepository.Replay(); PhotoAdapter .Expect(adapter => adapter.GetItems(null, null)) .IgnoreArguments() .Repeat.Never(); PhotoAdapter.Replay(); Process.GetPhotos(); PhotoAdapter.VerifyAllExpectations(); }
public void When_AddPhoto_is_called_and_no_PhotoAdapterSettings_have_been_stored_then_an_InvalidOperationException_is_thrown_and_UploadPhoto_on_the_PhotoAdapter_is_never_called() { var adapterSettings = AdapterSettingsCreator.CreateSingle(); adapterSettings.OAuthAccessToken = null; adapterSettings.OAuthRequestToken = null; var photo = new MemoryStream(); const string fileName = "photo.jpg"; BandRepository .Expect(repository => repository.GetAdapterSettings(Arg <string> .Is.Anything)) .Throw(new InvalidOperationException()) .Repeat.Once(); BandRepository .Expect(repository => repository.AddAdapterSettings(Arg <AdapterSettings> .Is.Anything)) .Return(adapterSettings) .Repeat.Once(); BandRepository.Replay(); PhotoAdapter .Expect(adapter => adapter.UploadItem(null, null, null, null)) .IgnoreArguments() .Return("") .Repeat.Never(); PhotoAdapter.Replay(); Process.AddPhoto(photo, fileName); PhotoAdapter.VerifyAllExpectations(); }
public void When_GetPhotos_is_called_then_GetPhotoAdapterSettings_on_the_BandRepository_is_called() { var photos = PhotoCreator.CreateCollection(); var settings = AdapterSettingsCreator.CreateSingle(); BandRepository .Expect(repository => repository.GetAdapterSettings(Arg <string> .Is.Anything)) .Return(settings) .Repeat.Once(); BandRepository.Replay(); PhotoAdapter .Expect(adapter => adapter.GetItems(settings.SetName, settings.OAuthAccessToken)) .Return(photos) .Repeat.Once(); PhotoAdapter.Replay(); var result = Process.GetPhotos(); Assert.AreEqual(photos.Count(), result.Count()); Assert.AreEqual(photos.First(), result.First()); BandRepository.VerifyAllExpectations(); }
public void When_AddPhoto_is_called_with_a_new_Photo_then_UploadPhoto_on_the_PhotoAdapter_is_called_with_that_Photo_and_the_stored_PhotoAdapterSettings() { var photo = new MemoryStream(); const string fileName = "photo.jpg"; const string photoId = "http://www.photos.com/myphoto"; var entity = AdapterSettingsCreator.CreateSingle(); BandRepository .Expect(repository => repository.GetAdapterSettings(Arg <string> .Is.Anything)) .Return(entity) .Repeat.Once(); BandRepository.Replay(); PhotoAdapter .Expect(adapter => adapter.UploadItem(photo, entity.SetName, fileName, entity.OAuthAccessToken)) .Return(photoId) .Repeat.Once(); PhotoAdapter.Replay(); var result = Process.AddPhoto(photo, fileName); Assert.AreEqual(photoId, result); PhotoAdapter.VerifyAllExpectations(); }