示例#1
0
        internal void RemainingTime_Returns_Null_If_AverageSpeed_Is_Null()
        {
            var i = new TransferInternal(TransferDirection.Download, string.Empty, string.Empty, 0);
            var d = new Transfer(i);

            Assert.Null(d.RemainingTime);
        }
示例#2
0
        internal void TransferStateChangedEventArgs_Instantiates_With_The_Given_Data(string username, string filename, int token, TransferStates transferStates)
        {
            var dl = new TransferInternal(TransferDirection.Download, username, filename, token);
            var d  = new TransferStateChangedEventArgs(transferStates, new Transfer(dl));

            Assert.Equal(transferStates, d.PreviousState);
        }
示例#3
0
        internal void ElapsedTime_Returns_Null_If_StartTime_Is_Null()
        {
            var i = new TransferInternal(TransferDirection.Download, string.Empty, string.Empty, 0);
            var d = new Transfer(i);

            Assert.Null(d.ElapsedTime);
        }
        internal void State_Transitions_Set_Time_Props()
        {
            var d = new TransferInternal(TransferDirection.Download, string.Empty, string.Empty, 0);

            var s1  = d.StartTime;
            var e1  = d.EndTime;
            var et1 = d.ElapsedTime;
            var rt1 = d.RemainingTime;

            d.State = TransferStates.InProgress;

            var s2  = d.StartTime;
            var e2  = d.EndTime;
            var et2 = d.ElapsedTime;
            var rt2 = d.RemainingTime;

            d.State = TransferStates.Completed;

            Assert.Null(s1);
            Assert.Null(e1);
            Assert.Null(et1);
            Assert.Null(rt1);

            Assert.NotNull(s2);
            Assert.Null(e2);
            Assert.NotNull(et2);
            Assert.Null(rt2);

            Assert.NotNull(d.StartTime);
            Assert.NotNull(d.EndTime);
            Assert.NotNull(d.ElapsedTime);
            Assert.Null(d.RemainingTime);
        }
        internal void Instantiates_With_The_Given_Data(string username, string filename, int token)
        {
            var d = new TransferInternal(TransferDirection.Download, username, filename, token);

            Assert.Equal(username, d.Username);
            Assert.Equal(filename, d.Filename);
            Assert.Equal(token, d.Token);
        }
示例#6
0
        internal void TransferEventArgs_Instantiates_With_The_Given_Data(TransferDirection direction, string username, string filename, int token, TransferOptions options)
        {
            var dl   = new TransferInternal(direction, username, filename, token, options);
            var xfer = new Transfer(dl);
            var d    = new TransferEventArgs(xfer);

            Assert.Equal(xfer, d.Transfer);
        }
        internal void ElapsedTime_Is_Not_Null_If_StartTime_Is_Not_Null()
        {
            var d = new TransferInternal(TransferDirection.Download, string.Empty, string.Empty, 0);

            var s = new DateTime(2019, 4, 25);

            d.SetProperty("StartTime", s);

            Assert.NotNull(d.ElapsedTime);
        }
        internal void UpdateProgress_Ignores_AverageSpeed_If_StarTime_And_lastProgressTime_Is_Null()
        {
            var d = new TransferInternal(TransferDirection.Download, string.Empty, string.Empty, 0);

            Assert.Equal(0, d.AverageSpeed);

            d.InvokeMethod("UpdateProgress", 100000);

            Assert.Equal(0, d.AverageSpeed);
        }
        internal void PercentComplete_Works()
        {
            var d = new TransferInternal(TransferDirection.Download, string.Empty, string.Empty, 0);

            Assert.Equal(0, d.PercentComplete);

            d.SetProperty("Size", 100L);
            d.SetProperty("BytesTransferred", 50);

            Assert.Equal(50, d.PercentComplete);
        }
示例#10
0
        internal void PercentComplete_Returns_0_If_Size_Is_0()
        {
            var i = new TransferInternal(TransferDirection.Download, string.Empty, string.Empty, 0)
            {
                Size = 0,
            };

            var d = new Transfer(i);

            Assert.Equal(0, d.PercentComplete);
        }
示例#11
0
        internal void TransferProgressUpdatedEventArgs_Instantiates_With_The_Given_Data(string username, string filename, int token, int size, int bytesDownloaded)
        {
            var dl = new TransferInternal(TransferDirection.Download, username, filename, token)
            {
                Size = size,
            };

            var d = new TransferProgressUpdatedEventArgs(bytesDownloaded, new Transfer(dl));

            Assert.Equal(bytesDownloaded, d.PreviousBytesTransferred);
        }
示例#12
0
        internal void UpdateProgress_Sets_AverageSpeed_To_Initial_Value()
        {
            var d = new TransferInternal(TransferDirection.Download, string.Empty, string.Empty, 0);

            Assert.Equal(0, d.AverageSpeed);

            d.SetField("progressUpdateLimit", 0);
            d.SetProperty("State", TransferStates.InProgress);
            d.InvokeMethod("UpdateProgress", 100000);

            Assert.NotEqual(0, d.AverageSpeed);
        }
示例#13
0
        internal void RemainingTime_Works()
        {
            var d = new TransferInternal(TransferDirection.Download, string.Empty, string.Empty, 0);

            Assert.Null(d.RemainingTime);

            d.SetProperty("AverageSpeed", 1);
            d.SetProperty("Size", 2L);
            d.SetProperty("BytesTransferred", 1);

            Assert.Equal(TimeSpan.FromSeconds(1), d.RemainingTime);
        }
示例#14
0
        internal void ElapsedTime_Returns_Elapsed_Time_Between_StartTime_And_EndTime()
        {
            var d = new TransferInternal(TransferDirection.Download, string.Empty, string.Empty, 0);

            var s = new DateTime(2019, 4, 25);
            var e = new DateTime(2019, 4, 26);

            d.SetProperty("StartTime", s);
            d.SetProperty("EndTime", e);

            Assert.Equal(e - s, d.ElapsedTime);
        }
示例#15
0
        internal void IPAddress_And_Port_Props_Return_Connection_Props(string username, string filename, int token, IPEndPoint endpoint)
        {
            var d = new TransferInternal(TransferDirection.Download, username, filename, token);

            var c = new Mock <IConnection>();

            c.Setup(m => m.IPEndPoint)
            .Returns(endpoint);

            d.Connection = c.Object;

            Assert.Equal(endpoint, d.IPEndPoint);
        }
示例#16
0
        internal void ElapsedTime_Works()
        {
            var d = new TransferInternal(TransferDirection.Download, string.Empty, string.Empty, 0);

            var s = new DateTime(2019, 4, 25);
            var e = new DateTime(2019, 4, 26);

            Assert.Equal(default(TimeSpan), d.ElapsedTime);

            d.SetProperty("StartTime", s);

            Assert.NotEqual(default(TimeSpan), d.ElapsedTime);

            d.SetProperty("EndTime", e);

            Assert.Equal(e - s, d.ElapsedTime);
        }
示例#17
0
        internal void UpdateProgress_Updates_AverageSpeed_On_Subsequent_Call()
        {
            var d = new TransferInternal(TransferDirection.Download, string.Empty, string.Empty, 0);

            Assert.Equal(0, d.AverageSpeed);

            d.SetField("progressUpdateLimit", 0);
            d.SetProperty("State", TransferStates.InProgress);
            d.InvokeMethod("UpdateProgress", 100000);

            var v1 = d.AverageSpeed;

            Assert.NotEqual(0, v1);

            d.InvokeMethod("UpdateProgress", 10);

            Assert.NotEqual(v1, d.AverageSpeed);
        }
示例#18
0
        public async Task GetDownloadPlaceInQueueAsync_Throws_TransferNotFoundException_When_Downloads_From_Username_Not_Found(string username, string filename)
        {
            using (var s = new SoulseekClient())
            {
                s.SetProperty("State", SoulseekClientStates.Connected | SoulseekClientStates.LoggedIn);

                var transfer = new TransferInternal(TransferDirection.Download, "different", filename, 1);
                var dict     = new ConcurrentDictionary <int, TransferInternal>();

                dict.TryAdd(1, transfer);

                s.SetProperty("Downloads", dict);

                var ex = await Record.ExceptionAsync(() => s.GetDownloadPlaceInQueueAsync(username, filename));

                Assert.NotNull(ex);
                Assert.IsType <TransferNotFoundException>(ex);
            }
        }
示例#19
0
        internal void Instantiates_With_Expected_Data_Given_TransferInternal(string username, string filename, int token)
        {
            var i = new TransferInternal(TransferDirection.Download, username, filename, token);
            var t = new Transfer(i);

            Assert.Equal(i.Direction, t.Direction);
            Assert.Equal(i.Username, t.Username);
            Assert.Equal(i.Filename, t.Filename);
            Assert.Equal(i.Token, t.Token);
            Assert.Equal(i.State, t.State);
            Assert.Equal(i.Size, t.Size);
            Assert.Equal(i.StartOffset, t.StartOffset);
            Assert.Equal(i.BytesTransferred, t.BytesTransferred);
            Assert.Equal(i.AverageSpeed, t.AverageSpeed);
            Assert.Equal(i.StartTime, t.StartTime);
            Assert.Equal(i.EndTime, t.EndTime);
            Assert.Equal(i.RemoteToken, t.RemoteToken);
            Assert.Equal(i.IPEndPoint, t.IPEndPoint);
        }
示例#20
0
        internal void Properties_Default_To_Expected_Values(string username, string filename, int token, TransferOptions options)
        {
            var d = new TransferInternal(TransferDirection.Download, username, filename, token, options);

            Assert.Null(d.Connection);
            Assert.Null(d.IPEndPoint);
            Assert.Null(d.RemoteToken);
            Assert.Equal(0, d.Size);
            Assert.Equal(TransferStates.None, d.State);
            Assert.Equal(0, d.AverageSpeed);
            Assert.Equal(0, d.BytesTransferred);
            Assert.Equal(0, d.BytesRemaining);
            Assert.Equal(default(TimeSpan), d.ElapsedTime);
            Assert.Equal(default(TimeSpan), d.RemainingTime);
            Assert.Null(d.StartTime);
            Assert.Null(d.EndTime);
            Assert.Equal(0, d.PercentComplete);
            Assert.Null(d.RemoteToken);
            Assert.Equal(options, d.Options);
        }
示例#21
0
        public void Throws_Download_Wait_On_PeerUploadFailed_Message(string username, IPEndPoint endpoint, string filename)
        {
            var(handler, mocks) = GetFixture(username, endpoint);

            var dict     = new ConcurrentDictionary <int, TransferInternal>();
            var download = new TransferInternal(TransferDirection.Download, username, filename, 0);

            dict.TryAdd(0, download);

            mocks.Client.Setup(m => m.Downloads)
            .Returns(dict);

            mocks.PeerConnection.Setup(m => m.Username)
            .Returns(username);

            var message = new MessageBuilder()
                          .WriteCode(MessageCode.Peer.UploadFailed)
                          .WriteString(filename)
                          .Build();

            handler.HandleMessageRead(mocks.PeerConnection.Object, message);

            mocks.Waiter.Verify(m => m.Throw(download.WaitKey, It.IsAny <TransferException>()), Times.Once);
        }
示例#22
0
        internal void Wait_Key_Is_Expected_Value(string username, string filename, int token, TransferDirection direction)
        {
            var d = new TransferInternal(direction, username, filename, token);

            Assert.Equal(new WaitKey(Constants.WaitKey.Transfer, direction, username, filename, token), d.WaitKey);
        }