Ejemplo n.º 1
0
        public void GetUploadShares()
        {
            // ARRANGE
            UploadShareList        expected = FactoryShare.UploadShareList;
            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.GetUploadShares(Arg.IsAny <long?>(), Arg.IsAny <long?>(), Arg.IsAny <GetUploadSharesFilter>(), Arg.IsAny <SharesSort>())).Returns(FactoryRestSharp.GetUploadSharesMock()).Occurs(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiUploadShareList>(Arg.IsAny <IRestRequest>(), RequestType.GetUploadShares, 0))
            .Returns(FactoryShare.ApiUploadShareList).Occurs(1);
            Mock.Arrange(() => ShareMapper.FromApiUploadShareList(Arg.IsAny <ApiUploadShareList>())).Returns(FactoryShare.UploadShareList).Occurs(1);

            // ACT
            UploadShareList actual = s.GetUploadShares();

            // ASSERT
            Assert.NotNull(actual);
            Mock.Assert(() => Arg.IsAny <long?>().NullableMustNotNegative(Arg.AnyString));
            Mock.Assert(() => Arg.IsAny <long?>().NullableMustPositive(Arg.AnyString));
            Mock.Assert(() => ShareMapper.FromApiUploadShareList(Arg.IsAny <ApiUploadShareList>()));
            Mock.Assert(c.Builder);
            Mock.Assert(c.Executor);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
0
        public void FromApiUploadShareList()
        {
            // ARRANGE
            UploadShareList expected = FactoryShare.UploadShareList;

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

            foreach (UploadShare current in expected.Items)
            {
                ApiUploadShare currentApi = new ApiUploadShare {
                    ShareId       = current.ShareId,
                    NodeId        = current.NodeId,
                    NodePath      = current.NodePath,
                    Name          = current.Name,
                    Notes         = current.Notes,
                    ExpireAt      = current.ExpireAt,
                    AccessKey     = current.AccessKey,
                    NotifyCreator = current.NotifyCreator,
                    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,
                    CurrentDoneUploadsCount   = current.CurrentDoneUploadsCount,
                    CurrentUploadedFilesCount = current.CurrentUploadedFilesCount,
                    MaxAllowedTotalSizeOverAllUploadedFiles = current.MaxAllowedTotalSizeOverAllUploadedFiles,
                    MaxAllowedUploads             = current.MaxAllowedUploads,
                    ShowUploadedFiles             = current.ShowUploadedFiles,
                    UploadedFilesExpirationPeriod = current.UploadedFilesExpirationPeriod
                };
                param.Items.Add(currentApi);
                Mock.Arrange(() => ShareMapper.FromApiUploadShare(currentApi)).Returns(current);
            }

            // ACT
            UploadShareList actual = ShareMapper.FromApiUploadShareList(param);

            // ASSERT
            Assert.Equal(expected, actual, new UploadShareListComparer());
        }
Ejemplo n.º 5
0
        public void ToUnencryptedApiCreateDownloadShareRequest(string smsRecipients, string emailRecipients)
        {
            // ARRANGE
            ApiCreateDownloadShareRequest expected = FactoryShare.ApiCreateDownloadShareRequest;

            List <string> smsRecList = null;

            if (smsRecipients != null)
            {
                smsRecList = new List <string>();
                smsRecList.AddRange(smsRecipients.Split(','));
                expected.SmsRecipients = smsRecipients;
                expected.SendSms       = true;
            }

            List <string> emailRecList = null;

            if (emailRecipients != null)
            {
                emailRecList = new List <string>();
                emailRecList.AddRange(emailRecipients.Split(','));
                expected.MailBody       = "Some body";
                expected.MailSubject    = "You received a DRACOON share!";
                expected.MailRecipients = emailRecipients;
                expected.SendMail       = true;
            }

            CreateDownloadShareRequest param = new CreateDownloadShareRequest(expected.NodeId)
            {
                Name                = expected.Name,
                Notes               = expected.Notes,
                Expiration          = expected.Expiration.ExpireAt,
                ShowCreatorName     = expected.ShowCreatorName,
                ShowCreatorUserName = expected.ShowCreatorUserName,
                NotifyCreator       = expected.NotifyCreator,
                MaxAllowedDownloads = expected.MaxAllowedDownloads,
                AccessPassword      = expected.Password,
                EmailRecipients     = emailRecList,
                EmailBody           = expected.MailBody,
                EmailSubject        = expected.MailSubject,
                SmsRecipients       = smsRecList
            };

            // ACT
            ApiCreateDownloadShareRequest actual = ShareMapper.ToUnencryptedApiCreateDownloadShareRequest(param);

            // ASSERT
            Assert.Equal(expected, actual, new ApiCreateDownloadShareRequestComparer());
        }
Ejemplo n.º 6
0
        public UploadShareList GetUploadShares(long?offset = null, long?limit = null, GetUploadSharesFilter filter = null, SharesSort sort = null)
        {
            _client.Executor.CheckApiServerVersion();

            #region Parameter Validation

            offset.NullableMustNotNegative(nameof(offset));
            limit.NullableMustPositive(nameof(limit));

            #endregion

            IRestRequest       restRequest = _client.Builder.GetUploadShares(offset, limit, filter, sort);
            ApiUploadShareList result      =
                _client.Executor.DoSyncApiCall <ApiUploadShareList>(restRequest, DracoonRequestExecutor.RequestType.GetUploadShares);
            return(ShareMapper.FromApiUploadShareList(result));
        }
Ejemplo n.º 7
0
        public void CreateUploadShare()
        {
            // ARRANGE
            CreateUploadShareRequest req = FactoryShare.CreateUploadShareRequest;

            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 <CreateUploadShareRequest>().MustNotNull(Arg.AnyString)).DoNothing().Occurs(1);
            Mock.Arrange(() => Arg.AnyLong.MustPositive(Arg.AnyString)).DoNothing().Occurs(1);
            Mock.Arrange(() => Arg.AnyString.MustNotNullOrEmptyOrWhitespace(Arg.AnyString, Arg.AnyBool)).DoNothing().OccursAtLeast(1);
            Mock.Arrange(() => Arg.IsAny <int?>().NullableMustPositive(Arg.AnyString)).DoNothing().Occurs(2);
            Mock.Arrange(() => Arg.IsAny <long?>().NullableMustPositive(Arg.AnyString)).DoNothing().Occurs(1);
            Mock.Arrange(() => Arg.IsAny <IEnumerable <string> >().EnumerableMustNotNullOrEmpty(Arg.AnyString)).DoNothing();
            Mock.Arrange(() => ShareMapper.ToApiCreateUploadShareRequest(Arg.IsAny <CreateUploadShareRequest>()))
            .Returns(FactoryShare.ApiCreateUploadShareRequest).Occurs(1);
            Mock.Arrange(() => c.Builder.PostCreateUploadShare(Arg.IsAny <ApiCreateUploadShareRequest>())).Returns(FactoryRestSharp.PostCreateUploadShareMock()).Occurs(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiUploadShare>(Arg.IsAny <IRestRequest>(), RequestType.PostCreateUploadShare, 0))
            .Returns(FactoryShare.ApiUploadShare).Occurs(1);
            Mock.Arrange(() => ShareMapper.FromApiUploadShare(Arg.IsAny <ApiUploadShare>())).Returns(FactoryShare.UploadShare).Occurs(1);

            // ACT
            UploadShare actual = s.CreateUploadShare(req);

            // ASSERT
            Assert.NotNull(actual);
            Mock.Assert(() => Arg.IsAny <CreateUploadShareRequest>().MustNotNull(Arg.AnyString));
            Mock.Assert(() => Arg.AnyLong.MustPositive(Arg.AnyString));
            Mock.Assert(() => Arg.AnyString.MustNotNullOrEmptyOrWhitespace(Arg.AnyString, Arg.AnyBool));
            Mock.Assert(() => Arg.IsAny <int?>().NullableMustPositive(Arg.AnyString));
            Mock.Assert(() => Arg.IsAny <long?>().NullableMustPositive(Arg.AnyString));
            Mock.Assert(() => Arg.IsAny <IEnumerable <string> >().EnumerableMustNotNullOrEmpty(Arg.AnyString));
            Mock.Assert(() => ShareMapper.ToApiCreateUploadShareRequest(Arg.IsAny <CreateUploadShareRequest>()));
            Mock.Assert(() => ShareMapper.FromApiUploadShare(Arg.IsAny <ApiUploadShare>()));
            Mock.Assert(c.Builder);
            Mock.Assert(c.Executor);
        }
Ejemplo n.º 8
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());
        }
Ejemplo n.º 9
0
        public UploadShare CreateUploadShare(CreateUploadShareRequest request)
        {
            _client.Executor.CheckApiServerVersion();

            #region Parameter Validation

            request.MustNotNull(nameof(request));
            request.NodeId.MustPositive(nameof(request.NodeId));
            request.Name.MustNotNullOrEmptyOrWhitespace(nameof(request.Name));
            request.MaxAllowedUploads.NullableMustPositive(nameof(request.MaxAllowedUploads));
            request.MaxAllowedTotalSizeOverAllUploadedFiles.NullableMustPositive(nameof(request.MaxAllowedTotalSizeOverAllUploadedFiles));
            request.UploadedFilesExpirationPeriod.NullableMustPositive(nameof(request.UploadedFilesExpirationPeriod));
            if (request.EmailRecipients != null)
            {
                request.EmailRecipients.EnumerableMustNotNullOrEmpty(nameof(request.EmailRecipients));
                request.EmailRecipients.ForEach(current => current.MustNotNullOrEmptyOrWhitespace(nameof(request.EmailRecipients) + " element"));
                request.EmailBody.MustNotNullOrEmptyOrWhitespace(nameof(request.EmailBody));
                request.EmailSubject.MustNotNullOrEmptyOrWhitespace(nameof(request.EmailSubject));
            }

            if (request.SmsRecipients != null)
            {
                request.SmsRecipients.EnumerableMustNotNullOrEmpty(nameof(request.SmsRecipients));
                request.SmsRecipients.ForEach(current => current.MustNotNullOrEmptyOrWhitespace(nameof(request.SmsRecipients) + " element"));
                if (string.IsNullOrEmpty(request.AccessPassword))
                {
                    throw new ArgumentException("If a SMS should be sent, a access password must be set.");
                }
            }

            #endregion

            ApiCreateUploadShareRequest apiRequest = ShareMapper.ToApiCreateUploadShareRequest(request);
            IRestRequest   restRequest             = _client.Builder.PostCreateUploadShare(apiRequest);
            ApiUploadShare resultShare             =
                _client.Executor.DoSyncApiCall <ApiUploadShare>(restRequest, DracoonRequestExecutor.RequestType.PostCreateUploadShare);
            return(ShareMapper.FromApiUploadShare(resultShare));
        }
Ejemplo n.º 10
0
        public void FromApiUploadShare()
        {
            // ARRANGE
            UploadShare expected = FactoryShare.UploadShare;

            ApiUploadShare param = new ApiUploadShare {
                ShareId       = expected.ShareId,
                NodeId        = expected.NodeId,
                NodePath      = expected.NodePath,
                Name          = expected.Name,
                IsProtected   = expected.IsProtected,
                AccessKey     = expected.AccessKey,
                NotifyCreator = expected.NotifyCreator,
                CreatedAt     = expected.CreatedAt,
                CreatedBy     = new ApiUserInfo {
                    AvatarUuid  = expected.CreatedBy.AvatarUUID,
                    DisplayName = expected.CreatedBy.DisplayName,
                    Id          = expected.CreatedBy.Id.Value
                },
                ExpireAt    = expected.ExpireAt,
                IsEncrypted = expected.IsEncrypted,
                Notes       = expected.Notes,
                UploadedFilesExpirationPeriod           = expected.UploadedFilesExpirationPeriod,
                CurrentDoneUploadsCount                 = expected.CurrentDoneUploadsCount,
                CurrentUploadedFilesCount               = expected.CurrentUploadedFilesCount,
                ShowUploadedFiles                       = expected.ShowUploadedFiles,
                MaxAllowedUploads                       = expected.MaxAllowedUploads,
                MaxAllowedTotalSizeOverAllUploadedFiles = expected.MaxAllowedTotalSizeOverAllUploadedFiles
            };

            Mock.Arrange(() => UserMapper.FromApiUserInfo(param.CreatedBy)).Returns(expected.CreatedBy);

            // ACT
            UploadShare actual = ShareMapper.FromApiUploadShare(param);

            // ASSERT
            Assert.Equal(expected, actual, new UploadShareComparer());
        }
Ejemplo n.º 11
0
        public DownloadShare CreateDownloadShare(CreateDownloadShareRequest request)
        {
            _client.Executor.CheckApiServerVersion();

            #region Parameter Validation

            request.MustNotNull(nameof(request));

            Node targetNode = _client.NodesImpl.GetNode(request.NodeId);
            // Node id is still checked in previous called getNode()
            // To save much effort throw this restriction instantly and not let the rest api throw this error
            if (targetNode.IsEncrypted.GetValueOrDefault(false) && targetNode.Type != NodeType.File)
            {
                throw new DracoonApiException(DracoonApiCode.VALIDATION_DL_SHARE_CANNOT_CREATE_ON_ENCRYPTED_ROOM_FOLDER);
            }

            request.Name.MustNotNullOrEmptyOrWhitespace(nameof(request.Name), true);
            request.MaxAllowedDownloads.NullableMustPositive(nameof(request.MaxAllowedDownloads));
            if (targetNode.IsEncrypted.GetValueOrDefault(false) && string.IsNullOrWhiteSpace(request.EncryptionPassword) &&
                !string.IsNullOrWhiteSpace(request.AccessPassword))
            {
                throw new ArgumentException("Download share of a encrypted node must have a encryption password and no access password.");
            }

            if (!targetNode.IsEncrypted.GetValueOrDefault(false) && string.IsNullOrWhiteSpace(request.AccessPassword) &&
                !string.IsNullOrWhiteSpace(request.EncryptionPassword))
            {
                throw new ArgumentException("Download share of a not encrypted node must have a access password and no encryption password.");
            }

            if (targetNode.IsEncrypted.GetValueOrDefault(false) && string.IsNullOrWhiteSpace(request.EncryptionPassword))
            {
                throw new ArgumentException("Download share of a encrypted node must have a encryption password.");
            }

            if (!targetNode.IsEncrypted.GetValueOrDefault(false))
            {
                request.AccessPassword?.MustNotNullOrEmptyOrWhitespace(nameof(request.AccessPassword));
            }

            if (request.EmailRecipients != null)
            {
                request.EmailRecipients.EnumerableMustNotNullOrEmpty(nameof(request.EmailRecipients));
                request.EmailRecipients.ForEach(current => current.MustNotNullOrEmptyOrWhitespace(nameof(request.EmailRecipients) + " element"));
                request.EmailBody.MustNotNullOrEmptyOrWhitespace(nameof(request.EmailBody));
                request.EmailSubject.MustNotNullOrEmptyOrWhitespace(nameof(request.EmailSubject));
            }

            if (request.SmsRecipients != null)
            {
                request.SmsRecipients.EnumerableMustNotNullOrEmpty(nameof(request.SmsRecipients));
                request.SmsRecipients.ForEach(current => current.MustNotNullOrEmptyOrWhitespace(nameof(request.SmsRecipients) + " element"));
                if (string.IsNullOrEmpty(request.AccessPassword))
                {
                    throw new ArgumentException("If a SMS should be sent, a access password must be set.");
                }
            }

            #endregion

            ApiCreateDownloadShareRequest apiRequest = ShareMapper.ToUnencryptedApiCreateDownloadShareRequest(request);
            if (targetNode.IsEncrypted.GetValueOrDefault(false))
            {
                UserKeyPair      creatorKeyPair          = _client.AccountImpl.GetAndCheckUserKeyPair();
                EncryptedFileKey creatorEncryptedFileKey = _client.NodesImpl.GetEncryptedFileKey(request.NodeId);
                PlainFileKey     plainFileKey            = _client.NodesImpl.DecryptFileKey(creatorEncryptedFileKey, creatorKeyPair.UserPrivateKey, request.NodeId);
                UserKeyPair      newGeneratedKeyPair     = _client.AccountImpl.GenerateNewUserKeyPair(request.EncryptionPassword);
                EncryptedFileKey newEncryptedFileKey     =
                    _client.NodesImpl.EncryptFileKey(plainFileKey, newGeneratedKeyPair.UserPublicKey, request.NodeId);

                apiRequest.KeyPair = UserMapper.ToApiUserKeyPair(newGeneratedKeyPair);
                apiRequest.FileKey = FileMapper.ToApiFileKey(newEncryptedFileKey);
            }

            IRestRequest     restRequest = _client.Builder.PostCreateDownloadShare(apiRequest);
            ApiDownloadShare resultShare =
                _client.Executor.DoSyncApiCall <ApiDownloadShare>(restRequest, DracoonRequestExecutor.RequestType.PostCreateDownloadShare);
            return(ShareMapper.FromApiDownloadShare(resultShare));
        }