예제 #1
0
 public PhotosController(
     IPhotoService photoService,
     PhotoAdapter photoAdapter)
 {
     _svc          = photoService ?? throw new ArgumentNullException(nameof(photoService));
     _photoAdapter = photoAdapter ?? throw new ArgumentNullException(nameof(photoAdapter));
 }
예제 #2
0
        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();
        }
예제 #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            _progress = new ProgressDialog(this);

            _progress.SetTitle("Loading");
            _progress.SetCanceledOnTouchOutside(false);

            if (!Loaded)
            {
                LoadAsync().ContinueWith((task) =>
                {
                });
            }

            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetActionBar(toolbar);

            ActionBar.Title = "Immedia";

            _recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView);

            layoutManager = new LinearLayoutManager(this);
            _recyclerView.SetLayoutManager(layoutManager);
            Adapter = new PhotoAdapter(_photos);
            _recyclerView.SetAdapter(Adapter);
        }
예제 #4
0
        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();
        }
예제 #5
0
        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();
        }
예제 #6
0
        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();
        }
예제 #7
0
        private void InitData()
        {
            var adapter = new PhotoAdapter((IMvxAndroidBindingContext)BindingContext);

            _photos.SetLayoutManager(new LinearLayoutManager(Activity));
            _photos.HasFixedSize = true;
            _photos.SetAdapter(adapter);
        }
 public PhotoCategoriesController(
     IPhotoService photoService,
     PhotoAdapter photoAdapter,
     PhotoCategoryAdapter categoryAdapter)
 {
     _svc             = photoService ?? throw new ArgumentNullException(nameof(photoService));
     _photoAdapter    = photoAdapter ?? throw new ArgumentNullException(nameof(photoAdapter));
     _categoryAdapter = categoryAdapter ?? throw new ArgumentNullException(nameof(categoryAdapter));
 }
예제 #9
0
        private void RecuperaDados()
        {
            var apiService = new ApiService();

            var photos = apiService.GetPhotoMock();

            //var photos = apiService.GetPhotoApi(10);

            photoAdapter = new PhotoAdapter(photos);
            rvPhoto.SetAdapter(photoAdapter);
        }
예제 #10
0
        public IEnumerable <Photo> GetPhotos()
        {
            var adapterSettings = GetAdapterSettings();

            if (adapterSettings.OAuthAccessToken == null)
            {
                throw new AuthorizationException();
            }

            return(PhotoAdapter.GetItems(adapterSettings.SetName, adapterSettings.OAuthAccessToken));
        }
예제 #11
0
 public void Create(List <PhotoDto> photoDto, Guid requesotrId)
 {
     if ((_userRepository.GetUserById(requesotrId)).Roles[0].Name.Equals("Subscriber") || (_userRepository.GetUserById(requesotrId)).Roles[0].Name.Equals("Admin"))
     {
         foreach (var photo in photoDto)
         {
             var temp = PhotoAdapter.BuildPhoto(photo);
             _gPhotoRepository.Add(temp);
         }
         ;
     }
 }
예제 #12
0
        public Uri GetAuthenticationUri(Uri currentLocation)
        {
            var requestToken = PhotoAdapter.GetOAuthRequestToken(currentLocation);

            var entity = GetAdapterSettings();

            entity.OAuthRequestToken = requestToken;
            entity.OAuthAccessToken  = null;
            UpdateAdapterSettings(entity);

            return(PhotoAdapter.GetOAuthCalculatedAuthorizationUri(requestToken));
        }
예제 #13
0
        public IEnumerable <PhotoDto> GetPhotosById(Guid id, Guid requestorid, PagingParameterDto paging)
        {
            if ((_userRepository.GetUserById(requestorid)).Roles[0].Name.Equals("Subscriber") || (_userRepository.GetUserById(requestorid)).Roles[0].Name.Equals("Admin"))
            {
                int start = (paging.pageNumber - 1) * paging._pageSize;

                var allPhotos  = _gPhotoRepository.GetRange(start, paging._pageSize, photo => (photo.AlbumId == id), photo => photo.Id);
                var photosById = allPhotos as IList <Photo> ?? allPhotos.ToList();
                var photosDto  = photosById.Select(x => PhotoAdapter.BuildPhotoDto(x));

                return(photosDto);
            }
            else if ((_userRepository.GetUserById(requestorid)).Roles[0].Name.Equals("User"))
            {
                var albums = _albumRepository.GetAlbumsById(requestorid, requestorid);
                var album  = albums.SingleOrDefault(x => x.Id.Equals(id));

                if (!album.Equals(null))
                {
                    int start = (paging.pageNumber - 1) * paging._pageSize;

                    var allPhotos = _gPhotoRepository.GetRange(start, paging._pageSize, photo => (photo.AlbumId.Equals(id)), photo => photo.Id);
                    var user      = _userRepository.GetUserById(requestorid);
                    foreach (var photo in allPhotos)
                    {
                        if (photo.SelectedByUsers != null)
                        {
                            if (photo.SelectedByUsers.Any(x => x.Id.Equals(user.Id)))
                            {
                                photo.Selected = true;
                            }
                        }
                        else
                        {
                            photo.Selected = false;
                        }
                    }

                    var photosDto = allPhotos.Select(PhotoAdapter.BuildPhotoDto);

                    return(photosDto);
                }
            }
            return(null);
        }
예제 #14
0
        public string AddPhoto(Stream photo, string fileName)
        {
            if (photo == null)
            {
                throw new ArgumentNullException("photo");
            }
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName");
            }

            var adapterSettings = GetAdapterSettings();

            if (adapterSettings.OAuthAccessToken == null)
            {
                throw new AuthorizationException();
            }

            return(PhotoAdapter.UploadItem(photo, adapterSettings.SetName, fileName, adapterSettings.OAuthAccessToken));
        }
예제 #15
0
        public void Authorize(Uri verificationUri)
        {
            if (verificationUri == null)
            {
                throw new ArgumentNullException("verificationUri");
            }

            var verifier = verificationUri.GetQueryParameters()["oauth_verifier"];
            var entity   = GetAdapterSettings();

            if (string.IsNullOrEmpty(verifier) || entity.OAuthRequestToken == null)
            {
                throw new AuthorizationException();
            }

            var accessToken = PhotoAdapter.GetOAuthAccessToken(entity.OAuthRequestToken, verifier);

            entity.OAuthRequestToken = null;
            entity.OAuthAccessToken  = accessToken;
            UpdateAdapterSettings(entity);
        }