public AzureHDInsightStorageHandlerSimulatorFactory()
 {
     Instance = new AzureHDInsightStorageHandlerSimulator();
 }
        public void CanCallTheExecHiveCommand_UploadsFile()
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();
            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                AzureHDInsightClusterConnection connection = ConnectToCluster(runspace, creds);
                var storageHandlerSimulator = new AzureHDInsightStorageHandlerSimulator();
                AzureHDInsightStorageHandlerSimulatorFactory.Instance = storageHandlerSimulator;

                IInvokeHiveCommand execHiveCommand = ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateInvokeHive();
                execHiveCommand.JobDefinition = new AzureHDInsightHiveJobDefinition { Query = "show tables", JobName = "show tables" };
                execHiveCommand.CurrentSubscription = GetCurrentSubscription();
                execHiveCommand.Connection = connection;
                execHiveCommand.EndProcessing();

                string destinationPath = string.Format(
                    CultureInfo.InvariantCulture,
                    "http://{0}/{1}/user/{2}/",
                    connection.Cluster.DefaultStorageAccount.StorageAccountName,
                    connection.Cluster.DefaultStorageAccount.StorageContainerName,
                    connection.Cluster.HttpUserName);
                string outputContent = execHiveCommand.Output.Last();
                Assert.IsNotNull(storageHandlerSimulator.UploadedStream);
                storageHandlerSimulator.UploadedStream.Seek(0, SeekOrigin.Begin);
                string contents = new StreamReader(storageHandlerSimulator.UploadedStream).ReadToEnd();
                Assert.AreEqual("show tables", contents);
                Assert.IsFalse(string.IsNullOrEmpty(storageHandlerSimulator.Path.OriginalString));
                Assert.IsTrue(storageHandlerSimulator.Path.OriginalString.StartsWith(destinationPath, StringComparison.OrdinalIgnoreCase));

                Assert.AreEqual(5, execHiveCommand.Output.Count());
                Assert.AreEqual("hivesampletable", outputContent);
            }
        }
        public void CanCallTheExecHiveCommand_DoesNotUploadFile()
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();
            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                AzureHDInsightClusterConnection connection = ConnectToCluster(runspace, creds);
                var storageHandlerSimulator = new AzureHDInsightStorageHandlerSimulator();
                AzureHDInsightStorageHandlerSimulatorFactory.Instance = storageHandlerSimulator;

                IInvokeHiveCommand execHiveCommand = ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateInvokeHive();
                execHiveCommand.JobDefinition = new AzureHDInsightHiveJobDefinition { File = "query.hql", JobName = "show tables" };
                execHiveCommand.CurrentSubscription = GetCurrentSubscription();
                execHiveCommand.Connection = connection;
                execHiveCommand.EndProcessing();

                string outputContent = execHiveCommand.Output.Last();
                Assert.AreEqual(5, execHiveCommand.Output.Count());
                Assert.AreEqual("hivesampletable", outputContent);

                Assert.IsNull(storageHandlerSimulator.UploadedStream);
                Assert.IsNull(storageHandlerSimulator.Path);
            }
        }
 public AzureHDInsightStorageHandlerSimulatorFactory()
 {
     Instance = new AzureHDInsightStorageHandlerSimulator();
 }