Esempio 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);
        }
Esempio n. 2
0
        public void CreateUploadShare_SmsRecipientsNoAccessPw_Fail()
        {
            // ARRANGE
            CreateUploadShareRequest req = FactoryShare.CreateUploadShareRequest;

            req.AccessPassword  = null;
            req.SmsRecipients   = new List <string>();
            req.EmailRecipients = null;
            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();

            // ACT - ASSERT
            Assert.Throws <ArgumentException>(() => s.CreateUploadShare(req));
            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(c.Executor);
        }
Esempio n. 3
0
        public void CreateDownloadShare_NotEncryptedNoAccessPw_Fail()
        {
            // ARRANGE
            Node node = FactoryNode.Node;

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

            req.AccessPassword     = "";
            req.EncryptionPassword = null;
            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, true)).DoNothing().Occurs(1);
            Mock.Arrange(() => Arg.AnyString.MustNotNullOrEmptyOrWhitespace(Arg.AnyString, false)).Throws(new ArgumentException()).Occurs(1);
            Mock.Arrange(() => Arg.IsAny <int?>().NullableMustPositive(Arg.AnyString)).DoNothing().Occurs(1);

            // ACT - ASSERT
            Assert.Throws <ArgumentException>(() => s.CreateDownloadShare(req));
            Mock.Assert(() => Arg.IsAny <CreateDownloadShareRequest>().MustNotNull(Arg.AnyString));
            Mock.Assert(() => Arg.AnyString.MustNotNullOrEmptyOrWhitespace(Arg.AnyString, true));
            Mock.Assert(() => Arg.AnyString.MustNotNullOrEmptyOrWhitespace(Arg.AnyString, false));
            Mock.Assert(() => Arg.IsAny <int?>().NullableMustPositive(Arg.AnyString));
            Mock.Assert(c.NodesImpl);
            Mock.Assert(c.Executor);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public void DeleteUploadShare()
        {
            // ARRANGE
            IInternalDracoonClient c = FactoryClients.InternalDracoonClientMock(true);
            DracoonSharesImpl      s = new DracoonSharesImpl(c);

            Mock.Arrange(() => Arg.AnyLong.MustPositive(Arg.AnyString)).DoNothing().Occurs(1);
            Mock.Arrange(() => c.Builder.DeleteUploadShare(Arg.AnyLong)).Returns(FactoryRestSharp.DeleteUploadShareMock(2134)).Occurs(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <VoidResponse>(Arg.IsAny <IRestRequest>(), RequestType.DeleteUploadShare, 0)).DoNothing().Occurs(1);

            // ACT
            s.DeleteUploadShare(5);

            // ASSERT
            Mock.Assert(() => Arg.AnyLong.MustPositive(Arg.AnyString));
            Mock.Assert(c.Builder);
            Mock.Assert(c.Executor);
        }
Esempio n. 7
0
        public void CreateDownloadShare_EncryptedNoFile_Fail()
        {
            // ARRANGE
            Node node = FactoryNode.Node;

            node.IsEncrypted = true;
            node.Type        = NodeType.Room;
            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);

            try {
                // ACT
                s.CreateDownloadShare(FactoryShare.CreateDownloadShareRequest);
            } catch (DracoonApiException e) {
                // ASSERT
                Assert.Equal(DracoonApiCode.VALIDATION_DL_SHARE_CANNOT_CREATE_ON_ENCRYPTED_ROOM_FOLDER, e.ErrorCode);
                Mock.Assert(() => Arg.IsAny <CreateDownloadShareRequest>().MustNotNull(Arg.AnyString));
                Mock.Assert(c.NodesImpl);
                Mock.Assert(c.Executor);
            }
        }