public static async Task performBlobOperation(TestDataBlobReference blobToUpload)
        {
            // Retrieve storage account from connection string.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Constants.AzureStorageConnectionString);

            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve reference to a previously created container.
            CloudBlobContainer container = blobClient.GetContainerReference("testrunresults");

            // Create the container if it doesn't already exist.
            await container.CreateIfNotExistsAsync().ConfigureAwait(false);

            //reading file name & file extention
            //string file_extension = Path.GetExtension(fileToUpload);
            //string filename_withExtension = Path.GetFileName(fileToUpload);

            //CloudBlockBlob cloudBlockBlob = container.GetBlockBlobReference(filename_withExtension);
            ////cloudBlockBlob.Properties.ContentType = file_extension;

            //// << reading the file as filestream from local machine >>
            //Stream file = new FileStream(fileToUpload, FileMode.Open);
            //await cloudBlockBlob.UploadFromStreamAsync(file); // << Uploading the file to the blob >>

            CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobToUpload.Filename);
            await blockBlob.UploadTextAsync(blobToUpload.Json);

            Console.WriteLine("Upload Completed!");
        }
Example #2
0
        /// <summary>
        /// Summarizes all of the results and returns the test result xml document with test cloud device values
        /// </summary>
        /// <returns></returns>
        //public XDocument GetCustomTestXml()
        //{
        //    if (_xmlResults_Custom != null)
        //        _xmlResults_Custom = null;

        //    var test = new XElement("test-run");
        //    test.Add(new XAttribute("id", "0"));
        //    test.Add(new XAttribute("testcasecount", TestCount));
        //    test.Add(new XAttribute("total", TestCount));
        //    test.Add(new XAttribute("passed", PassCount));
        //    test.Add(new XAttribute("failed", FailureCount));
        //    test.Add(new XAttribute("inconclusive", InconclusiveCount));
        //    test.Add(new XAttribute("skipped", SkipCount));
        //    test.Add(new XAttribute("asserts", AssertCount));
        //    test.Add(new XAttribute("result", OverallResult));

        //    test.Add(new XAttribute("xamarin-runner-version", typeof(ResultSummary).GetTypeInfo().Assembly.GetName().Version.ToString()));

        //    var startTime = _results.StartTime;
        //    var endTime = _results.EndTime;
        //    var duration = endTime.Subtract(startTime).TotalSeconds;

        //    test.Add(new XAttribute("start-time", startTime.ToString("u")));
        //    test.Add(new XAttribute("end-time", endTime.ToString("u")));
        //    test.Add(new XAttribute("duration", duration.ToString("0.000000", NumberFormatInfo.InvariantInfo)));

        //    string xtc_device_platform = DeviceInfo.Platform.ToString();
        //    //manufacturer_model
        //    string xtc_device_name = DeviceInfo.Manufacturer.ToString() + "_" + DeviceInfo.Model.ToString();
        //    string xtc_device_os = DeviceInfo.VersionString.ToString();

        //    string sourceString = AppInfo.Name;
        //    string removeString = "-Tests";
        //    int index = sourceString.IndexOf(removeString);
        //    string xtc_app_name = (index < 0) ? sourceString : sourceString.Remove(index, removeString.Length);

        //    test.Add(new XAttribute("xtc_framework", xtc_app_name));
        //    test.Add(new XAttribute("xtc_device_platform", xtc_device_platform));
        //    test.Add(new XAttribute("xtc_device_name", xtc_device_name));
        //    test.Add(new XAttribute("xtc_device_os", xtc_device_os));

        //    foreach (var result in _results.TestResults)
        //        test.Add(XElement.Parse(result.ToXml(true).OuterXml));

        //    _xmlResults_Custom = new XDocument(test);
        //    return _xmlResults_Custom;
        //}

        /// <summary>
        /// Summarizes all of the results and returns the test result JSON document with test cloud device values
        /// </summary>
        /// <returns></returns>
        public TestDataBlobReference GetCustomTestJSON()
        {
            string jsonData = null;
            TestDataBlobReference blobReference = null;
            TestData data = new TestData();

            try
            {
                //manufacturer_model
                string trim_device_manufacturer = String.Concat(DeviceInfo.Manufacturer.ToString().Where(c => !Char.IsWhiteSpace(c)));
                string trim_device_model        = String.Concat(DeviceInfo.Name.ToString().Where(c => !Char.IsWhiteSpace(c)));
                string xtc_device_name          = trim_device_manufacturer + "_" + trim_device_model;

                string sourceString = AppInfo.Name;
                string removeString = "-Tests";
                int    index        = sourceString.IndexOf(removeString);
                string xtc_app_name = (index < 0) ? sourceString : sourceString.Remove(index, removeString.Length);

                data.Framework        = xtc_app_name;
                data.FrameworkVersion = Constants.DBFrameworkVersionNumber;
                data.Device           = xtc_device_name;
                data.DevicePlatform   = DeviceInfo.Platform.ToString();
                data.DeviceOS         = DeviceInfo.VersionString.ToString();
                if (String.IsNullOrEmpty(Constants.AzureDevOpsBuildNumber))
                {
                    data.BuildNumber = "LOCALRUN";
                }
                else
                {
                    data.BuildNumber = Constants.AzureDevOpsBuildNumber;
                }

                data.Results = _xmlResults.Root
                               .Elements("test-suite")?
                               .Elements("test-suite")?
                               .Elements("test-suite")?
                               .Where(i => i.Attribute(XName.Get("runstate")).Value == "Runnable")
                               .Elements("test-suite")?
                               .Where(i => i.Attribute(XName.Get("type")).Value == "TestFixture")
                               .Elements("test-suite")?
                               .Elements("test-case")?
                               .Where(i => i.Elements("reason").Count() > 0)
                               .ToDictionary(
                    i => i.Attribute(XName.Get("name")).Value,
                    i => GetMessageValue(
                        i.Elements("reason")
                        .FirstOrDefault()
                        .Elements("message")
                        .FirstOrDefault().Value));

                jsonData = JsonConvert.SerializeObject(data, Formatting.Indented);

                blobReference = new TestDataBlobReference
                {
                    Filename = $"[{data.BuildNumber}] {data.DevicePlatform}-{data.Framework}-{data.FrameworkVersion}-{data.Device}.json",
                    Json     = jsonData
                };
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(blobReference);
        }