コード例 #1
0
        public void CreateDownloadShare_Success()
        {
            // ARRANGE
            Node node = FactoryNode.Node;

            node.IsEncrypted = true;
            node.Type        = NodeType.File;
            CreateDownloadShareRequest req = FactoryShare.CreateDownloadShareRequest;

            req.EmailRecipients = new List <string> {
                "985678"
            };
            req.EmailBody     = "Any body!";
            req.EmailSubject  = "Any subject!";
            req.SmsRecipients = new List <string> {
                "28436054"
            };
            IInternalDracoonClient c = FactoryClients.InternalDracoonClientMock(true);
            DracoonSharesImpl      s = new DracoonSharesImpl(c);

            Mock.Arrange(() => Arg.IsAny <CreateDownloadShareRequest>().MustNotNull(Arg.AnyString)).DoNothing().Occurs(1);
            Mock.Arrange(() => c.NodesImpl.GetNode(Arg.AnyLong)).Returns(node).Occurs(1);
            Mock.Arrange(() => Arg.AnyString.MustNotNullOrEmptyOrWhitespace(Arg.AnyString, Arg.AnyBool)).DoNothing().OccursAtLeast(1);
            Mock.Arrange(() => Arg.IsAny <int?>().NullableMustPositive(Arg.AnyString)).DoNothing().Occurs(1);
            Mock.Arrange(() => Arg.IsAny <IEnumerable <string> >().EnumerableMustNotNullOrEmpty(Arg.AnyString)).DoNothing();
            Mock.Arrange(() => ShareMapper.ToUnencryptedApiCreateDownloadShareRequest(Arg.IsAny <CreateDownloadShareRequest>()))
            .Returns(FactoryShare.ApiCreateDownloadShareRequest).Occurs(1);
            Mock.Arrange(() => c.AccountImpl.GetAndCheckUserKeyPair()).Returns(FactoryUser.UserKeyPair).Occurs(1);
            Mock.Arrange(() => c.NodesImpl.GetEncryptedFileKey(Arg.AnyLong)).Returns(FactoryFile.EncryptedFileKey).Occurs(1);
            Mock.Arrange(() => c.NodesImpl.DecryptFileKey(Arg.IsAny <EncryptedFileKey>(), Arg.IsAny <UserPrivateKey>(), Arg.IsAny <long?>())).Returns(FactoryFile.PlainFileKey).Occurs(1);
            Mock.Arrange(() => c.AccountImpl.GenerateNewUserKeyPair(Arg.AnyString)).Returns(FactoryUser.UserKeyPair);
            Mock.Arrange(() => c.NodesImpl.EncryptFileKey(Arg.IsAny <PlainFileKey>(), Arg.IsAny <UserPublicKey>(), Arg.IsAny <long?>())).Returns(FactoryFile.EncryptedFileKey).Occurs(1);
            Mock.Arrange(() => UserMapper.ToApiUserKeyPair(Arg.IsAny <UserKeyPair>())).Returns(FactoryUser.ApiUserKeyPair).Occurs(1);
            Mock.Arrange(() => FileMapper.ToApiFileKey(Arg.IsAny <EncryptedFileKey>())).Returns(FactoryFile.ApiFileKey).Occurs(1);
            Mock.Arrange(() => c.Builder.PostCreateDownloadShare(Arg.IsAny <ApiCreateDownloadShareRequest>())).Returns(FactoryRestSharp.PostCreateDownloadShareMock()).Occurs(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiDownloadShare>(Arg.IsAny <IRestRequest>(), RequestType.PostCreateDownloadShare, 0))
            .Returns(FactoryShare.ApiDownloadShare).Occurs(1);
            Mock.Arrange(() => ShareMapper.FromApiDownloadShare(Arg.IsAny <ApiDownloadShare>())).Returns(FactoryShare.DownloadShare).Occurs(1);

            // ACT
            DownloadShare actual = s.CreateDownloadShare(req);

            // ASSERT
            Assert.NotNull(actual);
            Mock.Assert(() => Arg.IsAny <CreateDownloadShareRequest>().MustNotNull(Arg.AnyString));
            Mock.Assert(() => Arg.AnyString.MustNotNullOrEmptyOrWhitespace(Arg.AnyString, Arg.AnyBool));
            Mock.Assert(() => Arg.IsAny <int?>().NullableMustPositive(Arg.AnyString));
            Mock.Assert(() => Arg.IsAny <IEnumerable <string> >().EnumerableMustNotNullOrEmpty(Arg.AnyString));
            Mock.Assert(() => ShareMapper.ToUnencryptedApiCreateDownloadShareRequest(Arg.IsAny <CreateDownloadShareRequest>()));
            Mock.Assert(() => UserMapper.ToApiUserKeyPair(Arg.IsAny <UserKeyPair>()));
            Mock.Assert(() => FileMapper.ToApiFileKey(Arg.IsAny <EncryptedFileKey>()));
            Mock.Assert(() => ShareMapper.FromApiDownloadShare(Arg.IsAny <ApiDownloadShare>()));
            Mock.Assert(c.NodesImpl);
            Mock.Assert(c.AccountImpl);
            Mock.Assert(c.Builder);
            Mock.Assert(c.Executor);
        }
コード例 #2
0
        public void FromApiDownloadShare()
        {
            // ARRANGE
            DownloadShare expected = FactoryShare.DownloadShare;

            expected.Classification = Classification.Confidential;

            ApiDownloadShare param = new ApiDownloadShare {
                ShareId               = expected.ShareId,
                NodeId                = expected.NodeId,
                NodePath              = expected.NodePath,
                Name                  = expected.Name,
                Notes                 = expected.Notes,
                Classification        = (int)expected.Classification,
                ExpireAt              = expected.ExpireAt,
                AccessKey             = expected.AccessKey,
                ShowCreatorName       = expected.ShowCreatorName,
                ShowCreatorUserName   = expected.ShowCreatorUserName,
                NotifyCreator         = expected.NotifyCreator,
                MaxAllowedDownloads   = expected.MaxAllowedDownloads,
                CurrentDownloadsCount = expected.CurrentDownloadsCount,
                CreatedAt             = expected.CreatedAt,
                CreatedBy             = new ApiUserInfo {
                    AvatarUuid  = expected.CreatedBy.AvatarUUID,
                    DisplayName = expected.CreatedBy.DisplayName,
                    Id          = expected.CreatedBy.Id.Value
                },
                IsProtected = expected.IsProtected,
                IsEncrypted = expected.IsEncrypted
            };

            Mock.Arrange(() => EnumConverter.ConvertClassificationEnumToValue(expected.Classification)).Returns((int)expected.Classification);
            Mock.Arrange(() => UserMapper.FromApiUserInfo(param.CreatedBy)).Returns(expected.CreatedBy);

            // ACT
            DownloadShare actual = ShareMapper.FromApiDownloadShare(param);

            // ASSERT
            Assert.Equal(expected, actual, new DownloadShareComparer());
        }
コード例 #3
0
        internal static DownloadShare FromApiDownloadShare(ApiDownloadShare apiDownloadShare)
        {
            DownloadShare downloadShare = new DownloadShare {
                ShareId               = apiDownloadShare.ShareId,
                NodeId                = apiDownloadShare.NodeId,
                NodePath              = apiDownloadShare.NodePath,
                Name                  = apiDownloadShare.Name,
                Notes                 = apiDownloadShare.Notes,
                Classification        = EnumConverter.ConvertValueToClassificationEnum(apiDownloadShare.Classification),
                ExpireAt              = apiDownloadShare.ExpireAt,
                AccessKey             = apiDownloadShare.AccessKey,
                ShowCreatorName       = apiDownloadShare.ShowCreatorName,
                ShowCreatorUserName   = apiDownloadShare.ShowCreatorUserName,
                NotifyCreator         = apiDownloadShare.NotifyCreator,
                MaxAllowedDownloads   = apiDownloadShare.MaxAllowedDownloads,
                CurrentDownloadsCount = apiDownloadShare.CurrentDownloadsCount,
                CreatedAt             = apiDownloadShare.CreatedAt,
                CreatedBy             = UserMapper.FromApiUserInfo(apiDownloadShare.CreatedBy),
                IsProtected           = apiDownloadShare.IsProtected,
                IsEncrypted           = apiDownloadShare.IsEncrypted
            };

            return(downloadShare);
        }