示例#1
0
        public void GetDownloadShares()
        {
            // ARRANGE
            DownloadShareList      expected = FactoryShare.DownloadShareList;
            IInternalDracoonClient c        = FactoryClients.InternalDracoonClientMock(true);
            DracoonSharesImpl      s        = new DracoonSharesImpl(c);

            Mock.Arrange(() => Arg.IsAny <long?>().NullableMustNotNegative(Arg.AnyString)).DoNothing().Occurs(1);
            Mock.Arrange(() => Arg.IsAny <long?>().NullableMustPositive(Arg.AnyString)).DoNothing().Occurs(1);
            Mock.Arrange(() => c.Builder.GetDownloadShares(Arg.IsAny <long?>(), Arg.IsAny <long?>(), Arg.IsAny <GetDownloadSharesFilter>(), Arg.IsAny <SharesSort>()))
            .Returns(FactoryRestSharp.GetDownloadSharesMock()).Occurs(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiDownloadShareList>(Arg.IsAny <IRestRequest>(), RequestType.GetDownloadShares, 0))
            .Returns(FactoryShare.ApiDownloadShareList).Occurs(1);
            Mock.Arrange(() => ShareMapper.FromApiDownloadShareList(Arg.IsAny <ApiDownloadShareList>())).Returns(FactoryShare.DownloadShareList).Occurs(1);

            // ACT
            DownloadShareList actual = s.GetDownloadShares();

            // ASSERT
            Assert.NotNull(actual);
            Mock.Assert(() => Arg.IsAny <long?>().NullableMustNotNegative(Arg.AnyString));
            Mock.Assert(() => Arg.IsAny <long?>().NullableMustPositive(Arg.AnyString));
            Mock.Assert(() => ShareMapper.FromApiDownloadShareList(Arg.IsAny <ApiDownloadShareList>()));
            Mock.Assert(c.Builder);
            Mock.Assert(c.Executor);
        }
示例#2
0
        public void FromApiDownloadShareList()
        {
            // ARRANGE
            Classification    expectedClassification = Classification.StrictlyConfidential;
            DownloadShareList expected = FactoryShare.DownloadShareList;

            ApiDownloadShareList param = new ApiDownloadShareList {
                Range = new ApiRange {
                    Offset = expected.Offset,
                    Limit  = expected.Limit,
                    Total  = expected.Total
                },
                Items = new List <ApiDownloadShare>(expected.Items.Count)
            };

            foreach (DownloadShare current in expected.Items)
            {
                current.Classification = expectedClassification;
                ApiDownloadShare currentApi = new ApiDownloadShare {
                    ShareId               = current.ShareId,
                    NodeId                = current.NodeId,
                    NodePath              = current.NodePath,
                    Name                  = current.Name,
                    Notes                 = current.Notes,
                    Classification        = (int)current.Classification,
                    ExpireAt              = current.ExpireAt,
                    AccessKey             = current.AccessKey,
                    ShowCreatorName       = current.ShowCreatorName,
                    ShowCreatorUserName   = current.ShowCreatorUserName,
                    NotifyCreator         = current.NotifyCreator,
                    MaxAllowedDownloads   = current.MaxAllowedDownloads,
                    CurrentDownloadsCount = current.CurrentDownloadsCount,
                    CreatedAt             = current.CreatedAt,
                    CreatedBy             = new ApiUserInfo {
                        AvatarUuid  = current.CreatedBy.AvatarUUID,
                        DisplayName = current.CreatedBy.DisplayName,
                        Id          = current.CreatedBy.Id.Value
                    },
                    IsProtected = current.IsProtected,
                    IsEncrypted = current.IsEncrypted
                };
                param.Items.Add(currentApi);
                Mock.Arrange(() => ShareMapper.FromApiDownloadShare(currentApi)).Returns(current);
            }

            // ACT
            DownloadShareList actual = ShareMapper.FromApiDownloadShareList(param);

            // ASSERT
            Assert.Equal(expected, actual, new DownloadShareListComparer());
        }
        internal static DownloadShareList FromApiDownloadShareList(ApiDownloadShareList apiDownloadShareList)
        {
            DownloadShareList shareList = new DownloadShareList {
                Offset = apiDownloadShareList.Range.Offset,
                Limit  = apiDownloadShareList.Range.Limit,
                Total  = apiDownloadShareList.Range.Total,
                Items  = new List <DownloadShare>()
            };

            foreach (ApiDownloadShare currentShare in apiDownloadShareList.Items)
            {
                shareList.Items.Add(FromApiDownloadShare(currentShare));
            }

            return(shareList);
        }