public void BugSplatUtils_GetStringValueOrDefault_ShouldReturnDefaultValueIfValuesIsNullOrEmpty()
        {
            string value        = null;
            var    defaultValue = "SplatBugs";

            var result = BugSplatUtils.GetStringValueOrDefault(value, defaultValue);

            Assert.AreEqual(defaultValue, result);
        }
        public void BugSplatUtils_GetStringValueOrDefault_ShouldReturnValueIfNotNullOrEmpty()
        {
            var value        = "BugSplat";
            var defaultValue = "SplatBugs";

            var result = BugSplatUtils.GetStringValueOrDefault(value, defaultValue);

            Assert.AreEqual(value, result);
        }
Beispiel #3
0
        private MultipartFormDataContent CreateMultiPartFormDataContent(BugSplatPostOptions options = null)
        {
            var additionalFormDataParams = options?.AdditionalFormDataParams ?? new List <IFormDataParam>();
            var description = BugSplatUtils.GetStringValueOrDefault(options?.Description, Description);
            var email       = BugSplatUtils.GetStringValueOrDefault(options?.Email, Email);
            var key         = BugSplatUtils.GetStringValueOrDefault(options?.Key, Key);
            var user        = BugSplatUtils.GetStringValueOrDefault(options?.User, User);

            var body = new MultipartFormDataContent
            {
                { new StringContent(database), "database" },
                { new StringContent(application), "appName" },
                { new StringContent(version), "appVersion" },
                { new StringContent(description), "description" },
                { new StringContent(email), "email" },
                { new StringContent(key), "appKey" },
                { new StringContent(user), "user" }
            };

            foreach (var param in additionalFormDataParams)
            {
                if (!string.IsNullOrEmpty(param.FileName))
                {
                    body.Add(param.Content, param.Name, param.FileName);
                    continue;
                }

                body.Add(param.Content, param.Name);
            }

            if (options != null)
            {
                Attachments.AddRange(options.AdditionalAttachments);
            }

            for (var i = 0; i < Attachments.Count; i++)
            {
                byte[] bytes = null;
                using (var fileStream = File.Open(Attachments[i].FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        fileStream.CopyTo(memoryStream);
                        bytes = memoryStream.ToArray();
                    }
                }

                if (bytes != null)
                {
                    var name = Attachments[i].Name;
                    body.Add(new ByteArrayContent(bytes), name, name);
                }
            }

            return(body);
        }