Exemple #1
0
        public async Task DataIsCorrectlyWrittenToResponse()
        {
            // Arrange
            var responseMsg = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(new byte[] { 1, 2, 3, 4 })
            };

            responseMsg.Content.Headers.ContentType   = new System.Net.Http.Headers.MediaTypeHeaderValue("video/mp4");
            responseMsg.Content.Headers.ContentLength = 4;

            var client = new Mock <IHttpClient>();

            client.Setup(c => c.GetAsync(new Uri("https://example.com"), null)).Returns(Task.FromResult(responseMsg));
            var proxy = new MediaProxyServer(client.Object);

            var request = new Mock <IHttpRequest>();

            request.Setup(c => c.GetQueryParameter("stream")).Returns("https://example.com");
            var responseStream = new MemoryStream();
            var response       = new Mock <IHttpResponse>();

            response.SetupGet(c => c.OutputStream).Returns(responseStream);
            response.Setup(c => c.SetContentInfo(4, "video/mp4", It.IsAny <byte[]>()));

            // Act
            await proxy.HandleRequest(request.Object, response.Object);

            // Assert
            CollectionAssert.AreEqual(new byte[] { 1, 2, 3, 4 }, responseStream.ToArray());
            response.Verify(c => c.SetContentInfo(4, "video/mp4", It.IsAny <byte[]>()), Times.Once());
        }
Exemple #2
0
        public async Task NotFoundIsPropagatedCorrectly()
        {
            // Arrange
            var responseMsg = new HttpResponseMessage(HttpStatusCode.NotFound);
            var client      = new Mock <IHttpClient>();

            client.Setup(c => c.GetAsync(new Uri("https://example.com"), null)).Returns(Task.FromResult(responseMsg));

            var proxy = new MediaProxyServer(client.Object);

            var request = new Mock <IHttpRequest>();

            request.Setup(c => c.GetQueryParameter("stream")).Returns("https://example.com");
            request.Setup(c => c.GetQueryParameter("user")).Returns(string.Empty);

            var response = new Mock <IHttpResponse>();

            response.Setup(c => c.SetStatus(404, It.IsAny <string>())).Verifiable();
            response.SetupGet(c => c.OutputStream).Returns(new MemoryStream());

            // Act
            await proxy.HandleRequest(request.Object, response.Object);

            // Assert
            response.Verify(c => c.SetStatus(404, It.IsAny <string>()), Times.Once());
        }
Exemple #3
0
        public App()
        {
            Kernel = new Kernel();

            Task.Run(() =>
            {
                Settings.UIMode       = UIMode.Full;
                Settings.MiniDumpType = MiniDumpType.Normal;
                Settings.StoragePath  = StoragePath.CurrentDirectory;
                Settings.UIProvider   = UIProvider.WPF;
                Settings.AdditionalReportFiles.Add("log*.txt");
                Settings.AdditionalReportFiles.Add(Constants.IO.ConfigFileName);
                Settings.SleepBeforeSend    = 20;
                Settings.StopReportingAfter = 100;
                Settings.AddDestinationFromConnectionString($"Type=Http;Url={Constants.Web.CrashReportUrl};");

                Settings.ReleaseMode = true;
            }).Forget();

            AppDomain.CurrentDomain.UnhandledException += Handler.UnhandledException;
            Current.DispatcherUnhandledException       += Handler.DispatcherUnhandledException;

            ProxyServer = new MediaProxyServer();

            Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata {
                DefaultValue = 30
            });
        }
        public void SetImages(IEnumerable <Uri> images)
        {
            Images.Clear();
            foreach (var url in images)
            {
                var displayUrl = MediaProxyServer.ExtractUrl(url);

                Images.Add(new ImageEntry(url, false, displayUrl.AbsoluteUri, displayUrl));
            }

            Center();
        }
Exemple #5
0
        public void HttpClientIsDisposed()
        {
            // Arrange
            var client = new Mock <IHttpClient>();

            client.Setup(c => c.Dispose()).Verifiable();
            var proxy = new MediaProxyServer(client.Object);

            // Act
            proxy.Dispose();

            // Assert
            client.Verify(c => c.Dispose(), Times.Once());
        }
Exemple #6
0
        public void StoppingStopsListener()
        {
            // Arrange
            var listener = new Mock <IHttpListener>();

            listener.Setup(c => c.Stop()).Verifiable();

            var proxy = new MediaProxyServer(null, listener.Object);

            // Act
            proxy.Stop();

            // Assert
            listener.Verify(c => c.Stop(), Times.Once());
        }
Exemple #7
0
        public UserViewModel(User user)
        {
            Model = user;

            ProfileImageUrlHttps     = user.ProfileImageUrlHttps;
            ProfileImageUrlHttpsOrig = user.ProfileImageUrlHttps?.Replace("_normal", "");
            ProfileImageUrlHttpsMini = user.ProfileImageUrlHttps?.Replace("_normal", "_mini");
            ProfileImageUrlHttpsBig  = user.ProfileImageUrlHttps?.Replace("_normal", "_bigger");
            if (!string.IsNullOrEmpty(ProfileImageUrlHttpsOrig))
            {
                BigProfileImageUrl = MediaProxyServer.BuildUrl(ProfileImageUrlHttpsOrig);
            }

            ScreenName = Constants.Twitter.Mention + Model.GetScreenName();
            Url        = Uri.IsWellFormedUriString(user.Url, UriKind.Absolute) ? new Uri(user.Url) : user.GetUserUrl();
            DisplayUrl = Url.AbsoluteUri;
        }
Exemple #8
0
        public App()
        {
            Settings.UIMode       = UIMode.Full;
            Settings.MiniDumpType = MiniDumpType.Tiny;
            Settings.StoragePath  = StoragePath.CurrentDirectory;
            Settings.UIProvider   = UIProvider.WPF;
            Settings.AdditionalReportFiles.Add("log*.txt");
            Settings.AdditionalReportFiles.Add(Constants.IO.ConfigFileName);
            Settings.SleepBeforeSend    = 20;
            Settings.StopReportingAfter = 100;
            Settings.AddDestinationFromConnectionString($"Type=Http;Url={Constants.Web.CrashReportUrl};");

            Settings.ReleaseMode = true;

            AppDomain.CurrentDomain.UnhandledException += Handler.UnhandledException;
            Current.DispatcherUnhandledException       += Handler.DispatcherUnhandledException;

            ProxyServer = new MediaProxyServer();
        }
        public StatusMediaViewModel(MediaEntity entity, ulong userId = 0)
        {
            Entity = entity;
            switch (entity.Type)
            {
            case "animated_gif":
            case "video":
                Url        = MediaProxyServer.BuildUrl(entity.VideoInfo.Variants[0].Url, userId);
                DisplayUrl = new Uri(entity.VideoInfo.Variants[0].Url);
                Type       = MediaType.Animated;
                break;

            default:
                Url        = MediaProxyServer.BuildUrl(entity.MediaUrl, userId);
                DisplayUrl = new Uri(entity.ExpandedUrl);
                Type       = MediaType.Image;
                break;
            }
        }
Exemple #10
0
        public async Task MissingArgumentThrowsException()
        {
            // Arrange
            var client = new Mock <IHttpClient>();
            var proxy  = new MediaProxyServer(client.Object);

            var request  = new Mock <IHttpRequest>();
            var response = new Mock <IHttpResponse>();

            // Act
            var respEx = await ExceptionAssert.CatchAsync <ArgumentNullException>(() => proxy.HandleRequest(request.Object, null));

            var reqEx = await ExceptionAssert.CatchAsync <ArgumentNullException>(() => proxy.HandleRequest(null, response.Object));

            // Assert
            Assert.IsNotNull(respEx);
            Assert.IsNotNull(reqEx);
            Assert.AreEqual("response", respEx.ParamName);
            Assert.AreEqual("request", reqEx.ParamName);
        }
Exemple #11
0
        public void StartingAddsPrefix()
        {
            // Arrange
            var listener = new Mock <IHttpListener>();

            listener.Setup(c => c.AddPrefix(It.IsAny <string>())).Verifiable();
            var proxy = new MediaProxyServer(null, listener.Object);

            // Act
            try
            {
                proxy.Start(null);
            }
            finally
            {
                proxy.Stop();
            }

            // Assert
            listener.Verify(c => c.AddPrefix(It.IsAny <string>()), Times.Once());
        }
Exemple #12
0
        public async Task MissingQueryParameterIsIgnored()
        {
            // Arrange
            var client = new Mock <IHttpClient>();

            client.Setup(c => c.GetAsync(It.IsAny <Uri>(), null)).Verifiable();
            var proxy = new MediaProxyServer(client.Object);

            var request = new Mock <IHttpRequest>();

            request.Setup(c => c.GetQueryParameter("stream")).Returns <string>(null);

            var response = new Mock <IHttpResponse>();

            response.SetupGet(c => c.OutputStream).Returns(new MemoryStream());

            // Act
            await proxy.HandleRequest(request.Object, response.Object);

            // Assert
            client.Verify(c => c.GetAsync(It.IsAny <Uri>(), null), Times.Never());
        }
 public StatusMediaViewModel(Uri url, Uri displayUrl = null)
 {
     Url        = MediaProxyServer.BuildUrl(url);
     DisplayUrl = displayUrl ?? url;
     Type       = MediaType.Image;
 }