コード例 #1
0
        public void ToApiCreateUploadShareRequest(string smsRecipients, string emailRecipients)
        {
            // ARRANGE
            ApiCreateUploadShareRequest expected = FactoryShare.ApiCreateUploadShareRequest;

            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;
            }

            CreateUploadShareRequest param = new CreateUploadShareRequest(expected.NodeId, expected.Name)
            {
                Notes             = expected.Notes,
                Expiration        = expected.Expiration.ExpireAt,
                ShowUploadedFiles = expected.ShowUploadedFiles,
                NotifyCreator     = expected.NotifyCreator,
                MaxAllowedTotalSizeOverAllUploadedFiles = expected.MaxAllowedTotalSizeOverAllUploadedFiles,
                MaxAllowedUploads             = expected.MaxAllowedUploads,
                AccessPassword                = expected.AccessPassword,
                UploadedFilesExpirationPeriod = expected.UploadedFilesExpirationPeriod,
                EmailRecipients               = emailRecList,
                EmailBody     = expected.MailBody,
                EmailSubject  = expected.MailSubject,
                SmsRecipients = smsRecList
            };

            // ACT
            ApiCreateUploadShareRequest actual = ShareMapper.ToApiCreateUploadShareRequest(param);

            // ASSERT
            Assert.Equal(expected, actual, new ApiCreateUploadShareRequestComparer());
        }
コード例 #2
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);
        }
コード例 #3
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));
        }