|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using System.Collections.Specialized; |
| 5 | +using Xunit; |
| 6 | + |
| 7 | +namespace NuGetGallery.Helpers |
| 8 | +{ |
| 9 | + public class UploadHelperFacts |
| 10 | + { |
| 11 | + public class TheGetUploadTracingKeyMethod |
| 12 | + { |
| 13 | + private const string EmptyGuid = "00000000-0000-0000-0000-000000000000"; |
| 14 | + |
| 15 | + [Fact] |
| 16 | + public void ReturnsEmptyGuidForMissingHeader() |
| 17 | + { |
| 18 | + var headers = new NameValueCollection(); |
| 19 | + |
| 20 | + var result = UploadHelper.GetUploadTracingKey(headers); |
| 21 | + |
| 22 | + Assert.Equal(EmptyGuid, result); |
| 23 | + } |
| 24 | + |
| 25 | + [Theory] |
| 26 | + [InlineData(null)] |
| 27 | + [InlineData("")] |
| 28 | + [InlineData("not-a-guid")] |
| 29 | + [InlineData("00000000-0000-0000-0000-000000000000")] |
| 30 | + [InlineData(" 00000000-0000-0000-0000-000000000000 ")] |
| 31 | + public void ReturnsEmptyGuidForInvalidOrEmptyGuid(string value) |
| 32 | + { |
| 33 | + var headers = new NameValueCollection(); |
| 34 | + headers["upload-id"] = value; |
| 35 | + |
| 36 | + var result = UploadHelper.GetUploadTracingKey(headers); |
| 37 | + |
| 38 | + Assert.Equal(EmptyGuid, result); |
| 39 | + } |
| 40 | + |
| 41 | + [Theory] |
| 42 | + [InlineData("3bcf7d12-eb0a-46c9-98a8-c160801e8134")] |
| 43 | + [InlineData("3bcf7d12eb0a46c998a8c160801e8134")] |
| 44 | + [InlineData("3BCF7D12-EB0A-46C9-98A8-C160801E8134")] |
| 45 | + [InlineData(" 3bcf7d12-eb0a-46c9-98a8-c160801e8134 ")] |
| 46 | + public void ReturnsGuidForValidGuid(string value) |
| 47 | + { |
| 48 | + var headers = new NameValueCollection(); |
| 49 | + headers["upload-id"] = value; |
| 50 | + |
| 51 | + var result = UploadHelper.GetUploadTracingKey(headers); |
| 52 | + |
| 53 | + Assert.Equal("3bcf7d12-eb0a-46c9-98a8-c160801e8134", result); |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments