public async Task ShouldCorrectlyUploadFileByPath()
        {
            long           length;
            IUploadRequest completedRequest;
            var            tempFilePath = Path.GetTempFileName() + ".mp4";

            using (var fs = new FileStream(tempFilePath, FileMode.CreateNew))
            {
                await TestHelper.GetFileFromEmbeddedResources(TestHelper.TestFilePath).CopyToAsync(fs);
            }

            using (var file = new BinaryContent(tempFilePath))
            {
                file.ContentType.ShouldBe("video/mp4");
                length           = file.Data.Length;
                completedRequest = await AuthenticatedClient.UploadEntireFileAsync(file);

                completedRequest.ClipId.ShouldNotBeNull();
                await AuthenticatedClient.DeleteVideoAsync(completedRequest.ClipId.Value);
            }

            completedRequest.ShouldNotBeNull();
            completedRequest.IsVerifiedComplete.ShouldBeTrue();
            completedRequest.BytesWritten.ShouldBe(length);
            completedRequest.ClipUri.ShouldNotBeNull();
            completedRequest.ClipId.ShouldNotBeNull();
            completedRequest.ClipId?.ShouldBeGreaterThan(0);
            if (File.Exists(tempFilePath))
            {
                File.Delete(tempFilePath);
            }
        }
 public AuthenticatedClientTests()
 {
     client = new AuthenticatedClient();
     // The following line is to ensure that the xunit.assert assembly is loaded in the current AppDomain.
     // ReSharper disable once ExceptionNotDocumented
     Assert.NotNull(client);
 }
        //
        // GET: /Articles/
        public async Task <ActionResult> Index(string Store)
        {
            using (var client = new AuthenticatedClient())
            {
                HttpResponseMessage responseStoresMessage = await client.GetAsync("/services/stores");

                if (responseStoresMessage.IsSuccessStatusCode)
                {
                    var responseData = responseStoresMessage.Content.ReadAsStringAsync().Result;
                    var googleSearch = JObject.Parse(responseData);
                    var Stores       = JsonConvert.DeserializeObject <List <StoreEntity> >(googleSearch["Stores"].ToString());
                    ViewBag.Stores = Stores;
                }
                else
                {
                    ViewBag.Stores = new List <StoreEntity>();
                }

                HttpResponseMessage responseMessage = await client.GetAsync(string.IsNullOrEmpty(Store)? "/services/articles" : "/services/articles/stores/" + Store);

                if (responseMessage.IsSuccessStatusCode)
                {
                    var     responseData = responseMessage.Content.ReadAsStringAsync().Result;
                    JObject googleSearch = JObject.Parse(responseData);
                    var     Articles     = JsonConvert.DeserializeObject <List <ArticleEntity> >(googleSearch["Articles"].ToString());
                    Articles = Articles ?? new List <ArticleEntity>();


                    return(View(Articles));
                }
                return(View(new List <ArticleEntity>()));
            }
        }
        //
        // GET: /Articles/Edit
        public async Task <ActionResult> Edit(int articleId)
        {
            using (var client = new AuthenticatedClient())
            {
                HttpResponseMessage responseMessage = await client.GetAsync("/services/articles/" + articleId);

                if (responseMessage.IsSuccessStatusCode)
                {
                    var     responseData = responseMessage.Content.ReadAsStringAsync().Result;
                    JObject googleSearch = JObject.Parse(responseData);
                    var     Articles     = JsonConvert.DeserializeObject <ArticleEntity>(googleSearch["Article"].ToString());

                    HttpResponseMessage responseStoresMessage = await client.GetAsync("/services/stores");

                    if (responseStoresMessage.IsSuccessStatusCode)
                    {
                        responseData = responseStoresMessage.Content.ReadAsStringAsync().Result;
                        googleSearch = JObject.Parse(responseData);
                        var Stores = JsonConvert.DeserializeObject <List <StoreEntity> >(googleSearch["Stores"].ToString());
                        ViewBag.Stores = Stores;
                    }
                    else
                    {
                        ViewBag.Stores = new List <StoreEntity>();
                    }
                    return(View(Articles));
                }
                return(View("Error"));
            }
        }
        public void ExistingUserAuthenticatingShouldUseExistingUser()
        {
            var authenticatedUser = new AuthenticatedUser(Guid.NewGuid(), "user1", "email1", "picture", new List <AuthenticationProvider>()
            {
                new AuthenticationProvider(Guid.NewGuid(), "Facebook", "12345"),
            });

            var authenticatedClient = new AuthenticatedClient("Facebook")
            {
                UserInformation = new UserInformation()
                {
                    Id      = "12345",
                    Name    = "user1",
                    Email   = "email",
                    Picture = "picture",
                }
            };

            SaveEntities(authenticatedUser);

            var sut = new UserMapper(() => Session);
            AuthenticatedUser actual = sut.MapUser(authenticatedClient);

            actual.ShouldEqual(authenticatedUser);

            int count = Session.QueryOver <AuthenticatedUser>()
                        .RowCount();

            Assert.That(count, Is.EqualTo(1));
        }
Exemple #6
0
        public async Task TestStream()
        {
            // Check that the user has an Xbox Music Pass subscription
            UserProfileResponse userProfileResponse = await AuthenticatedClient.GetUserProfileAsync(Namespace.music).Log();

            // Beware: HasSubscription is bool?. You want != true instead of == false
            if (userProfileResponse.HasSubscription != true)
            {
                Assert.Inconclusive("The user doesn't have an Xbox Music Pass subscription. Cannot stream from catalog.");
            }

            // Get popular tracks in the user's country
            ContentResponse browseResults = await AuthenticatedClient.BrowseAsync(Namespace.music, ContentSource.Catalog, ItemType.Tracks).Log();

            Assert.IsNotNull(browseResults, "The browse response should not be null");
            AssertPaginatedListIsValid(browseResults.Tracks, 25, 100);

            // Stream the first streamable track
            Track          track          = browseResults.Tracks.Items.First(t => t.Rights.Contains("Stream"));
            StreamResponse streamResponse = await AuthenticatedClient.StreamAsync(track.Id, ClientInstanceId).Log();

            Assert.IsNotNull(streamResponse, "The stream URL response should not be null");
            Assert.IsNotNull(streamResponse.Url, "The stream URL should not be null");
            Assert.IsNotNull(streamResponse.ContentType, "The stream content type should not be null");
            Assert.IsNotNull(streamResponse.ExpiresOn, "The stream expiry date should not be null");
        }
Exemple #7
0
        public async Task ShouldCorrectlyGetVideoTag()
        {
            await AuthenticatedClient.AddVideoTagAsync(VimeoSettings.VideoId, "test-tag1");

            var result = await AuthenticatedClient.GetVideoTagAsync("test-tag1");

            result.Id.ShouldBe("test-tag1");
        }
Exemple #8
0
        public async Task DisposeAsync()
        {
            await CleanupTags(AuthenticatedClient, VimeoSettings.VideoId);

            var video = await AuthenticatedClient.GetVideoAsync(VimeoSettings.VideoId);

            video.Tags.Count.ShouldBe(0);
        }
Exemple #9
0
 public async Task ShouldCorrectlyRetrievesVideosByMe()
 {
     await AuthenticatedClient.WithTempVideo(async clipId =>
     {
         var videos = await AuthenticatedClient.GetVideosAsync(UserId.Me);
         videos.ShouldNotBeNull();
     });
 }
        public async Task <ActionResult> Delete(ArticleEntity article)
        {
            using (var client = new AuthenticatedClient())
            {
                var response = await client.DeleteAsync("/services/articles/" + article.ArticleId);

                return(RedirectToAction("Index"));
            }
        }
        public async Task <ActionResult> Delete(StoreEntity store)
        {
            using (var client = new AuthenticatedClient())
            {
                var response = await client.DeleteAsync("/services/stores/" + store.StoreId);

                return(RedirectToAction("Index"));
            }
        }
Exemple #12
0
 public async Task ShouldCorrectlyRetrievesVideosByUserId()
 {
     await AuthenticatedClient.WithTempVideo(async clipId =>
     {
         var videos = await AuthenticatedClient.GetVideosAsync(VimeoSettings.UserId);
         videos.ShouldNotBeNull();
         videos.Data.Count.ShouldBeGreaterThan(0);
     });
 }
        public async Task TestBrowsePlaylists()
        {
            // Get all the user's playlists
            ContentResponse browseResults =
                await AuthenticatedClient.BrowseAsync(Namespace.music, ContentSource.Collection, ItemType.Playlists).Log();

            Assert.IsNotNull(browseResults, "The browse response should not be null");
            AssertPaginatedListIsValid(browseResults.Playlists, 1);
        }
Exemple #14
0
 public async Task ShouldCorrectlyRetrievesVideosById()
 {
     await AuthenticatedClient.WithTempVideo(async clipId =>
     {
         var video = await AuthenticatedClient.GetVideoAsync(clipId);
         video.ShouldNotBeNull();
         video.Id.ShouldBe(clipId);
     });
 }
        public async Task ShouldCorrectlyGenerateNewTusResumableUploadTicket()
        {
            var ticket = await AuthenticatedClient.GetTusResumableUploadTicketAsync(1000);

            ticket.ShouldNotBeNull();
            ticket.Upload.UploadLink.ShouldNotBeEmpty();
            ticket.Id.ShouldNotBeNull();
            ticket.User.Id.ShouldBe(VimeoSettings.UserId);
            await AuthenticatedClient.DeleteVideoAsync(ticket.Id.Value);
        }
Exemple #16
0
 public async Task ShouldCorrectlyGetVideoWithFields()
 {
     await AuthenticatedClient.WithTempVideo(async clipId =>
     {
         var video = await AuthenticatedClient.GetVideoAsync(clipId, new[] { "uri", "name" });
         video.ShouldNotBeNull();
         video.Uri.ShouldNotBeNull();
         video.Name.ShouldNotBeNull();
         video.Pictures.ShouldBeNull();
     });
 }
        public void HostRefresh()
        {
            TwitchList <Stream> followed = new TwitchList <Stream>();

            followed.List = AuthenticatedClient.HostStreamsList.ConvertAll(hostStream => hostStream.Stream);
            List <string> hosters = AuthenticatedClient.HostStreamsList.ConvertAll(hoster => hoster.HostLogin);

            AuthenticatedClient.ResetHostStreamList();
            m_offset = 0;
            RefreshStreamPanel(followed, true, hosters);
        }
 public async Task ShouldCorrectlyUploadThumbnail()
 {
     await AuthenticatedClient.WithTempVideo(async clipId =>
     {
         using (var file = new BinaryContent(TestHelper.GetFileFromEmbeddedResources(TestHelper.TestFilePath), "image/png"))
         {
             var picture = await AuthenticatedClient.UploadThumbnailAsync(clipId, file);
             picture.ShouldNotBeNull();
         }
     });
 }
Exemple #19
0
        public async Task ShouldCorrectlyGetPictureFromVideo()
        {
            var pictures = await AuthenticatedClient.GetPicturesAsync(VimeoSettings.PublicVideoId);

            pictures.Data.Count.ShouldBeGreaterThan(0);
            var picture     = pictures.Data[0];
            var parts       = picture.Uri.Split('/');
            var pictureId   = long.Parse(parts[parts.Length - 1]);
            var pictureById = await AuthenticatedClient.GetPictureAsync(VimeoSettings.PublicVideoId, pictureId);

            pictureById.ShouldNotBeNull();
        }
        public async Task ShouldCorrectlyGenerateNewUploadTicket()
        {
            var ticket = await AuthenticatedClient.GetUploadTicketAsync();

            ticket.ShouldNotBeNull();
            ticket.CompleteUri.ShouldNotBeEmpty();
            ticket.TicketId.ShouldNotBeEmpty();
            ticket.UploadLink.ShouldNotBeEmpty();
            ticket.UploadLinkSecure.ShouldNotBeEmpty();
            ticket.Uri.ShouldNotBeEmpty();
            ticket.User.Id.ShouldBe(VimeoSettings.UserId);
        }
Exemple #21
0
        public async Task ShouldCorrectlyGetVideoThumbnails()
        {
            var pictures = await AuthenticatedClient.GetPicturesAsync(VimeoSettings.PublicVideoId);

            pictures.ShouldNotBeNull();
            pictures.Data.Count.ShouldBeGreaterThan(0);
            var uriParts  = pictures.Data[0].Uri.Split('/');
            var pictureId = long.Parse(uriParts[uriParts.Length - 1]);
            var picture   = await AuthenticatedClient.GetPictureAsync(VimeoSettings.PublicVideoId, pictureId);

            picture.ShouldNotBeNull();
        }
        public async Task <ActionResult> Create(ArticleEntity article)
        {
            using (var client = new AuthenticatedClient())
            {
                if (ModelState.IsValid)
                {
                    var response = await client.PostAsJsonAsync("/services/articles", article).ConfigureAwait(false);

                    return(RedirectToAction("Index"));
                }
                return(View("Error"));
            }
        }
        public async Task <ActionResult> Edit(StoreEntity store)
        {
            using (var client = new AuthenticatedClient())
            {
                if (ModelState.IsValid)
                {
                    var response = await client.PutAsJsonAsync("/services/stores/" + store.StoreId, store);

                    return(RedirectToAction("Index"));
                }
                return(View("Error"));
            }
        }
Exemple #24
0
 public async Task ShouldCorrectlyGetUserAlbumVideosByMe()
 {
     await AuthenticatedClient.WithTempVideo(async clipId =>
     {
         await AuthenticatedClient.WithTestAlbum(async albumId =>
         {
             await AuthenticatedClient.AddToAlbumAsync(UserId.Me, albumId, clipId);
             var videos = await AuthenticatedClient.GetAlbumVideosAsync(UserId.Me, albumId);
             videos.ShouldNotBeNull();
             videos.Data.Count.ShouldBeGreaterThan(0);
         });
     });
 }
 public async Task ShouldCorrectlyGenerateReplaceUploadTicket()
 {
     await AuthenticatedClient.WithTempVideo(async clipId =>
     {
         var ticket = await AuthenticatedClient.GetReplaceVideoUploadTicketAsync(clipId);
         ticket.ShouldNotBeNull();
         ticket.CompleteUri.ShouldNotBeEmpty();
         ticket.TicketId.ShouldNotBeEmpty();
         ticket.UploadLink.ShouldNotBeEmpty();
         ticket.UploadLinkSecure.ShouldNotBeEmpty();
         ticket.Uri.ShouldNotBeEmpty();
         ticket.User.Id.ShouldBe(VimeoSettings.UserId);
     });
 }
 public async Task GetAlbumsShouldCorrectlyWorkForMe()
 {
     await AuthenticatedClient.WithTestAlbum(async albumId =>
     {
         var client = CreateAuthenticatedClient();
         var albums = await client.GetAlbumsAsync(UserId.Me);
         albums.Total.ShouldBe(1);
         albums.PerPage.ShouldBe(25);
         albums.Data.Count.ShouldBe(1);
         albums.Paging.Next.ShouldBeNull();
         albums.Paging.Previous.ShouldBeNull();
         albums.Paging.First.ShouldBe("/me/albums?page=1");
         albums.Paging.Last.ShouldBe("/me/albums?page=1");
     });
 }
        // GET: StoresInfo
        public async Task <ActionResult> Index()
        {
            using (var client = new AuthenticatedClient())
            {
                HttpResponseMessage responseMessage = await client.GetAsync("/services/stores");

                if (responseMessage.IsSuccessStatusCode)
                {
                    var     responseData = responseMessage.Content.ReadAsStringAsync().Result;
                    JObject googleSearch = JObject.Parse(responseData);
                    var     Stores       = JsonConvert.DeserializeObject <List <StoreEntity> >(googleSearch["Stores"].ToString());
                    return(View(Stores));
                }
                return(View(new List <StoreEntity>()));
            }
        }
        //
        // GET: /Articles/Delete
        public async Task <ActionResult> Delete(int articleId)
        {
            using (var client = new AuthenticatedClient())
            {
                HttpResponseMessage responseMessage = await client.GetAsync("/services/articles/" + articleId);

                if (responseMessage.IsSuccessStatusCode)
                {
                    var     responseData = responseMessage.Content.ReadAsStringAsync().Result;
                    JObject googleSearch = JObject.Parse(responseData);
                    var     Article      = JsonConvert.DeserializeObject <ArticleEntity>(googleSearch["Article"].ToString());
                    return(View(Article));
                }
                return(View("Error"));
            }
        }
Exemple #29
0
        public async Task ShouldCorrectlyAssignEmbedPresetToVideo()
        {
            if (VimeoSettings.EmbedPresetId == 0)
            {
                return;
            }

            await AuthenticatedClient.WithTempVideo(async clipId =>
            {
                await AuthenticatedClient.AssignEmbedPresetToVideoAsync(clipId, VimeoSettings.EmbedPresetId);
                var video = await AuthenticatedClient.GetVideoAsync(clipId, new[] { "embed_presets" });
                video.ShouldNotBeNull();
                video.EmbedPresets.ShouldNotBeNull();
                video.EmbedPresets.Id.ShouldBe(VimeoSettings.EmbedPresetId);
            });
        }
        public async Task AlbumManagementShouldWorkCorrectlyForUserId()
        {
            // create a new album...
            const string originalName = "Unit Test Album";
            const string originalDesc =
                "This album was created via an automated test, and should be deleted momentarily...";

            var newAlbum = await AuthenticatedClient.CreateAlbumAsync(VimeoSettings.PublicUserId, new EditAlbumParameters
            {
                Name        = originalName,
                Description = originalDesc,
                Sort        = EditAlbumSortOption.Newest,
                Privacy     = EditAlbumPrivacyOption.Password,
                Password    = "******"
            });

            newAlbum.ShouldNotBeNull();
            newAlbum.Name.ShouldBe(originalName);

            newAlbum.Description.ShouldBe(originalDesc);

            // retrieve albums for the current user...there should be at least one now...
            var albums = await AuthenticatedClient.GetAlbumsAsync(UserId.Me);

            albums.Total.ShouldBeGreaterThan(0);

            // update the album...
            const string updatedName = "Unit Test Album (Updated)";
            var          albumId     = newAlbum.GetAlbumId();

            albumId.ShouldNotBeNull();
            var updatedAlbum = await AuthenticatedClient.UpdateAlbumAsync(UserId.Me, albumId.Value,
                                                                          new EditAlbumParameters
            {
                Name    = updatedName,
                Privacy = EditAlbumPrivacyOption.Anybody
            });

            updatedAlbum.Name.ShouldBe(updatedName);

            // delete the album...
            albumId = updatedAlbum.GetAlbumId();
            albumId.ShouldNotBeNull();
            var isDeleted = await AuthenticatedClient.DeleteAlbumAsync(UserId.Me, albumId.Value);

            isDeleted.ShouldBeTrue();
        }
Exemple #31
0
        public async Task TagInteractionTest()
        {
            await AuthenticatedClient.WithTempVideo(async clipId =>
            {
                var tag = await AuthenticatedClient.AddVideoTagAsync(clipId, "test-tag1");

                tag.ShouldNotBeNull();
                tag.Id.ShouldBe("test-tag1");
                tag.Name.ShouldBe("test-tag1");
                tag.Canonical.ShouldBe("test-tag1");
                tag.Uri.ShouldNotBeEmpty();
                tag.Metadata.ShouldNotBeNull();
                tag.Metadata.Connections.ShouldNotBeNull();
                tag.Metadata.Connections.Videos.Uri.ShouldNotBeEmpty();
                tag.Metadata.Connections.Videos.Options.ShouldNotBeEmpty();
                tag.Metadata.Connections.Videos.Total.ShouldBeGreaterThan(0);

                var video = await AuthenticatedClient.GetVideoAsync(clipId);

                while (video.Status == "uploading")
                {
                    _testOutput.WriteLine("Video is uploading...");
                    Thread.Sleep(5000);
                    video = await AuthenticatedClient.GetVideoAsync(clipId);
                }
                video.Tags.Count.ShouldBe(1);
                var tagResult = await AuthenticatedClient.GetVideoTagAsync("test-tag1");
                tagResult.Id.ShouldBe("test-tag1");

                var videoResult = await AuthenticatedClient.GetVideoByTag("test", 1, 10, GetVideoByTagSort.Name,
                                                                          GetVideoByTagDirection.Asc, new[] { "uri", "name" });

                videoResult.Page.ShouldBe(1);
                videoResult.PerPage.ShouldBe(10);
                videoResult.Data.Count.ShouldBeGreaterThan(0);
                videoResult.Data[0].Name.ShouldNotBeEmpty();
                videoResult.Data[0].Uri.ShouldNotBeEmpty();

                var tags = await AuthenticatedClient.GetVideoTags(clipId);
                foreach (var t in tags.Data)
                {
                    await AuthenticatedClient.DeleteVideoTagAsync(clipId, t.Id);
                }
            });
        }
        public IAuthenticatedClient AuthenticateClient(NameValueCollection parameters, string existingState = null)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (parameters.Count <= 0)
            {
                throw new ArgumentOutOfRangeException("parameters");
            }

            var state = parameters["state"];

            // CSRF (state) check.
            // NOTE: There is always a state provided. Even if an error is returned.
            if (!string.IsNullOrEmpty(existingState) && state != existingState)
            {
                throw new AuthenticationException(
                    "The states do not match. It's possible that you may be a victim of a CSRF.");
            }

            var reponse = RetrieveToken(parameters);
            var userInfo = RetrieveUserInfo(reponse);

            var result = new AuthenticatedClient(Name)
            {
                AccessToken = reponse.access_token,
                AccessTokenExpiresOn = DateTime.UtcNow.AddSeconds(int.Parse(reponse.expires_in)),
                UserInformation = new UserInformation
                {
                    Name = string.Join(" ", userInfo.first_name, userInfo.last_name),
                    Locale = userInfo.locale,
                    UserName = userInfo.name,
                    Id = userInfo.id,
                    Email = userInfo.emails.preferred,
                    Gender = (GenderType) Enum.Parse(typeof (GenderType), userInfo.gender ?? "Unknown", true)
                }
            };

            return result;
        }
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (queryStringParameters == null)
            {
                throw new ArgumentNullException("queryStringParameters");
            }

            if (queryStringParameters.Count <= 0)
            {
                throw new ArgumentOutOfRangeException("queryStringParameters");
            }

            var reponse = RetrieveToken(queryStringParameters, authenticationServiceSettings.CallBackUri);
            var userInfo = RetrieveUserInfo(reponse);

            var result = new AuthenticatedClient(Name)
                         {
                             AccessToken = reponse.AccessToken,
                             AccessTokenExpiresOn = DateTime.UtcNow.AddSeconds(int.Parse(reponse.ExpiresIn)),
                             UserInformation = new UserInformation
                                               {
                                                   Name = string.Join(" ", userInfo.first_name, userInfo.last_name),
                                                   Locale = userInfo.locale,
                                                   UserName = userInfo.name,
                                                   Id = userInfo.id,
                                                   Email = userInfo.emails.Preferred,
                                                   Gender =
                                                       (GenderType)
                                                       Enum.Parse(typeof (GenderType), userInfo.gender ?? "Unknown",
                                                                  true)
                                               }
                         };

            return result;
        }