public void ShouldDownloadWithSecureMessageAsRecipient()
        {
            var transactionHash = TestDataRepository
                                  .GetData(
                "UploaderSecureMessageIntegrationTests.ShouldUploadWithUseBlockchainSecureMessageAndRecipientPublicKey",
                "transactionHash");
            var param = DownloadParameter.Create(transactionHash)
                        .WithAccountPrivateKey(AccountPrivateKey2)
                        .Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.TransactionHash, transactionHash);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data.GetByteStream().GetContentAsString(), TestString);
            Assert.AreEqual(result.Data.ContentType, "text/plain");
            Assert.IsNotNull(result.Data.DataHash);
            Assert.AreEqual(result.Data.Description, "string description");
            Assert.AreEqual(result.Data.Name, "string name");
            Assert.IsNotNull(result.Data.Metadata);
            Assert.AreEqual(result.Data.Metadata.Count, 1);
            Assert.IsFalse(result.Data.Metadata.Except(new Dictionary <string, string> {
                { "keystring", "valstring" }
            })
                           .Any());
            Assert.IsNotNull(result.Data.Timestamp);
        }
        public void FailWhenInvalidTransactionHash()
        {
            var param = DownloadParameter
                .Create("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
                .Build();

            UnitUnderTest.Download(param);
        }
        public void FailDownloadOnGetByteStreamWhenContentTypeIsDirectory()
        {
            var transactionHash = TestDataRepository
                .GetData("UploaderIntegrationTests.ShouldUploadPath", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);
            result.Data.GetByteStream();
        }
        public void ShouldDownloadWithVersion()
        {
            var transactionHash = TestDataRepository
                .GetData("UploaderIntegrationTests.ShouldReturnVersion", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Version, SchemaVersion);
        }
        public void FailDownloadWithNoPrivateKey()
        {
            var transactionHash = TestDataRepository
                                  .GetData(
                "UploaderSecureMessageIntegrationTests.ShouldUploadWithUseBlockchainSecureMessageAndRecipientPublicKey",
                "transactionHash");
            var param = DownloadParameter.Create(transactionHash)
                        .Build();

            UnitUnderTest.Download(param);
        }
Exemplo n.º 6
0
        public void ShouldDownloadFromStorageConnection()
        {
            var transactionHash = TestDataRepository
                                  .GetData("UploaderStorageConnectionIntegrationTests.ShouldUploadToStorageConnection",
                                           "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Data.GetContentAsString(), TestString);
        }
        public void FailDownloadWithWrongPrivateKey()
        {
            var transactionHash = TestDataRepository
                                  .GetData(
                "UploaderSecureMessageIntegrationTests.ShouldUploadWithUseBlockchainSecureMessageAndRecipientPublicKey",
                "transactionHash");
            var param = DownloadParameter.Create(transactionHash)
                        .WithAccountPrivateKey("7FE209FAA5DE3E1EDEBD169091145788FF7B0847AD2FE04FB7706A660BFCAF0A")
                        .Build();

            UnitUnderTest.Download(param);
        }
        public void ShouldDownloadAsynchronouslyWithFailureCallback()
        {
            var param = DownloadParameter.Create("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").Build();
            var taskCompletionSource = new TaskCompletionSource <Exception>();
            var asyncCallbacks       = AsyncCallbacks <DownloadResult> .Create <DownloadResult>(
                null, ex => taskCompletionSource.SetResult(ex));

            UnitUnderTest.DownloadAsync(param, asyncCallbacks);
            taskCompletionSource.Task.Wait(5000);

            var exception = taskCompletionSource.Task.Result;

            Assert.IsInstanceOfType(exception, exception.GetType());
        }
        public void FailDownloadWithIncorrectNemKeys()
        {
            var transactionHash = TestDataRepository
                                  .GetData(
                "UploaderPrivacyStrategyIntegrationTests.ShouldUploadFileWithSecuredWithNemKeysPrivacyStrategy",
                "transactionHash");
            var param = DownloadParameter.Create(transactionHash)
                        .WithNemKeysPrivacy(AccountPrivateKey1, AccountPublicKey1)
                        .Build();

            var result = UnitUnderTest.Download(param);

            result.Data.GetByteStream().GetContentAsByteArray();
        }
        public void FailDownloadWithIncorrectPassword()
        {
            var transactionHash = TestDataRepository
                                  .GetData(
                "UploaderPrivacyStrategyIntegrationTests.ShouldUploadFileWithSecuredWithPasswordPrivacyStrategy",
                "transactionHash");
            var param = DownloadParameter.Create(transactionHash)
                        .WithPasswordPrivacy(TestPassword + "dummy")
                        .Build();

            var result = UnitUnderTest.Download(param);

            result.Data.GetByteStream().GetContentAsByteArray();
        }
        public void ShouldDownloadAsynchronouslyWithoutCallback()
        {
            var transactionHash = TestDataRepository
                                  .GetData("UploaderIntegrationTests.ShouldUploadByteArray", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var asyncTask = UnitUnderTest.DownloadAsync(param);

            while (!asyncTask.IsDone())
            {
                Thread.Sleep(50);
            }

            Assert.IsTrue(asyncTask.IsDone());
        }
        public void ShouldDownloadWithPlainPrivacy()
        {
            var transactionHash = TestDataRepository
                                  .GetData("UploaderPrivacyStrategyIntegrationTests.ShouldUploadFileWithPlainPrivacyStrategy",
                                           "transactionHash");
            var param = DownloadParameter.Create(transactionHash)
                        .WithPlainPrivacy()
                        .Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.PrivacyType, (int)PrivacyType.Plain);
            Assert.AreEqual(result.Data.GetByteStream().GetContentAsString(),
                            new FileStream(TestTextFile, FileMode.Open, FileAccess.Read).GetContentAsString());
        }
        public void ShouldDownloadAsynchronouslyWithSuccessCallback()
        {
            var transactionHash = TestDataRepository
                                  .GetData("UploaderIntegrationTests.ShouldUploadByteArray", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var taskCompletionSource = new TaskCompletionSource <DownloadResult>();
            var asyncCallbacks       = AsyncCallbacks <DownloadResult> .Create <DownloadResult>(
                downloadResult => taskCompletionSource.SetResult(downloadResult), null);

            UnitUnderTest.DownloadAsync(param, asyncCallbacks);
            taskCompletionSource.Task.Wait(5000);

            var result = taskCompletionSource.Task.Result;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Data.GetByteStream().GetContentAsByteArray());
        }
        public void ShouldDownloadString()
        {
            var transactionHash = TestDataRepository
                .GetData("UploaderIntegrationTests.ShouldUploadString", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.TransactionHash, transactionHash);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data.GetByteStream().GetContentAsString(), TestString);
            Assert.IsNull(result.Data.ContentType);
            Assert.IsNotNull(result.Data.DataHash);
            Assert.IsNull(result.Data.Description);
            Assert.IsNull(result.Data.Name);
            Assert.AreEqual(result.Data.Metadata.Count, 0);
            Assert.IsNotNull(result.Data.Timestamp);
        }
        public void ShouldDownloadFilesAsZipWithCompleteDetails()
        {
            var transactionHash = TestDataRepository
                .GetData("UploaderIntegrationTests.ShouldUploadFilesAsZipWithCompleteDetails", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.TransactionHash, transactionHash);
            Assert.IsNotNull(result.Data);
            Assert.IsNotNull(result.Data.GetByteStream().GetContentAsByteArray());
            Assert.AreEqual(result.Data.ContentType, "application/zip");
            Assert.IsNotNull(result.Data.DataHash);
            Assert.AreEqual(result.Data.Description, "zip description");
            Assert.AreEqual(result.Data.Name, "zip name");
            Assert.AreEqual(result.Data.Metadata.Count, 1);
            Assert.IsFalse(result.Data.Metadata.Except(new Dictionary<string, string> {{"zipkey", "zipvalue"}}).Any());
            Assert.IsNotNull(result.Data.Timestamp);
        }
        public void ShouldDownloadUrlResource()
        {
            var transactionHash = TestDataRepository
                                  .GetData("UploaderIntegrationTests.ShouldUploadUrlResource", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.TransactionHash, transactionHash);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data.GetByteStream().GetContentAsString(),
                            new FileStream(TestImagePngFile, FileMode.Open, FileAccess.Read).GetContentAsString());
            Assert.IsNull(result.Data.ContentType);
            Assert.IsNotNull(result.Data.DataHash);
            Assert.IsNull(result.Data.Description);
            Assert.IsNull(result.Data.Name);
            Assert.IsNull(result.Data.Metadata);
            Assert.IsNotNull(result.Data.Timestamp);
        }
        public void ShouldDownloadUrlResourceWithCompleteDetails()
        {
            var transactionHash = TestDataRepository
                .GetData("UploaderIntegrationTests.ShouldUploadUrlResourceWithCompleteDetails", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.TransactionHash, transactionHash);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data.GetByteStream().GetContentAsString(),
                new FileStream(TestImagePngFile, FileMode.Open, FileAccess.Read).GetContentAsString());
            Assert.AreEqual(result.Data.ContentType, "image/png");
            Assert.IsNotNull(result.Data.DataHash);
            Assert.AreEqual(result.Data.Description, "url description");
            Assert.AreEqual(result.Data.Name, "url name");
            Assert.AreEqual(result.Data.Metadata.Count, 1);
            Assert.IsFalse(result.Data.Metadata.Except(new Dictionary<string, string> {{"urlkey", "urlval"}}).Any());
            Assert.IsNotNull(result.Data.Timestamp);
        }
        public void ShouldDownloadStringWithCompleteDetails()
        {
            var transactionHash = TestDataRepository
                .GetData("UploaderIntegrationTests.ShouldUploadStringWithCompleteDetails", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.TransactionHash, transactionHash);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data.GetByteStream().GetContentAsString(), TestString);
            Assert.AreEqual(result.Data.ContentType, "text/plain");
            Assert.IsNotNull(result.Data.DataHash);
            Assert.AreEqual(result.Data.Description, "string description");
            Assert.AreEqual(result.Data.Name, "string name");
            Assert.AreEqual(result.Data.Metadata.Count, 1);
            Assert.IsFalse(result.Data.Metadata.Except(new Dictionary<string, string> {{"keystring", "valstring"}})
                .Any());
            Assert.IsNotNull(result.Data.Timestamp);
        }
        public void ShouldDownloadMultipleRequestsAsynchronously()
        {
            var transactionHash = TestDataRepository
                                  .GetData("UploaderIntegrationTests.ShouldUploadByteArray", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var taskCompletionSource1 = new TaskCompletionSource <DownloadResult>();
            var taskCompletionSource2 = new TaskCompletionSource <DownloadResult>();
            var taskCompletionSource3 = new TaskCompletionSource <DownloadResult>();
            var asyncCallbacks1       = AsyncCallbacks <DownloadResult> .Create <DownloadResult>(
                downloadResult => taskCompletionSource1.SetResult(downloadResult), null);

            var asyncCallbacks2 = AsyncCallbacks <DownloadResult> .Create <DownloadResult>(
                downloadResult => taskCompletionSource2.SetResult(downloadResult), null);

            var asyncCallbacks3 = AsyncCallbacks <DownloadResult> .Create <DownloadResult>(
                downloadResult => taskCompletionSource3.SetResult(downloadResult), null);

            UnitUnderTest.DownloadAsync(param, asyncCallbacks1);
            UnitUnderTest.DownloadAsync(param, asyncCallbacks2);
            UnitUnderTest.DownloadAsync(param, asyncCallbacks3);
            taskCompletionSource1.Task.Wait(5000);
            taskCompletionSource2.Task.Wait(5000);
            taskCompletionSource3.Task.Wait(5000);

            var result1 = taskCompletionSource1.Task.Result;

            Assert.IsNotNull(result1);
            Assert.IsNotNull(result1.Data.GetByteStream().GetContentAsByteArray());
            var result2 = taskCompletionSource1.Task.Result;

            Assert.IsNotNull(result2);
            Assert.IsNotNull(result2.Data.GetByteStream().GetContentAsByteArray());
            var result3 = taskCompletionSource1.Task.Result;

            Assert.IsNotNull(result3);
            Assert.IsNotNull(result3.Data.GetByteStream().GetContentAsByteArray());
        }