|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Linq; |
| 3 | +using AzureDevOpsPolicyConfigurator.Data; |
| 4 | +using Xunit; |
| 5 | + |
| 6 | +namespace AzureDevOpsPolicyConfigurator.Tests |
| 7 | +{ |
| 8 | + /// <summary> |
| 9 | + /// Multi branch definition test class. |
| 10 | + /// </summary> |
| 11 | + public class MultiRepositoryDefinitionTests |
| 12 | + { |
| 13 | + [Fact(DisplayName = "Check multi repository definition")] |
| 14 | + private void TestMultiRepositoryDefinition() |
| 15 | + { |
| 16 | + var serializer = new JsonSerializer(); |
| 17 | + |
| 18 | + var policies = new List<Policy>() |
| 19 | + { |
| 20 | + new Policy() |
| 21 | + { |
| 22 | + Repositories = new List<string>() |
| 23 | + { |
| 24 | + "myrepo1", "myrepo2" |
| 25 | + } |
| 26 | + } |
| 27 | + }; |
| 28 | + |
| 29 | + policies = policies.FlattenRepositories(serializer).ToList(); |
| 30 | + |
| 31 | + Assert.Equal(2, policies.Count); |
| 32 | + Assert.Equal("myrepo1", policies[0].Repository); |
| 33 | + Assert.Null(policies[0].Repositories); |
| 34 | + Assert.Equal("myrepo2", policies[1].Repository); |
| 35 | + Assert.Null(policies[1].Repositories); |
| 36 | + } |
| 37 | + |
| 38 | + [Fact(DisplayName = "Check multi repository with overriding", Skip = SkippingInformation.SkippingReason)] |
| 39 | + private async void CheckMultiRepositoryWithOverriding() |
| 40 | + { |
| 41 | + var result = await new PolicyTester().RunTest(new TestData(@" |
| 42 | + { |
| 43 | + ""allowDeletion"": false, |
| 44 | + ""ignoreTypes"": [], |
| 45 | + ""applyTo"": { |
| 46 | + ""projects"": [ ""##Project##"" ], |
| 47 | + ""repositories"": [""##Repository##""] |
| 48 | + }, |
| 49 | + ""policies"": [ |
| 50 | + { |
| 51 | + ""type"": ""Minimum number of reviewers"", |
| 52 | +
|
| 53 | + ""project"": ""##Project##"", |
| 54 | + ""repository"": ""##Repository##"", |
| 55 | +
|
| 56 | + ""isBlocking"": true, |
| 57 | +
|
| 58 | + ""settings"": { |
| 59 | + ""minimumApproverCount"": 3, |
| 60 | + ""creatorVoteCounts"": false, |
| 61 | + ""allowDownvotes"": false, |
| 62 | + ""resetOnSourcePush"": false |
| 63 | + } |
| 64 | + }, |
| 65 | + { |
| 66 | + ""type"": ""Minimum number of reviewers"", |
| 67 | +
|
| 68 | + ""project"": """", |
| 69 | + ""repositories"": [ ""##Repository##"" ], |
| 70 | +
|
| 71 | + ""isBlocking"": true, |
| 72 | +
|
| 73 | + ""settings"": { |
| 74 | + ""minimumApproverCount"": 6, |
| 75 | + ""creatorVoteCounts"": false, |
| 76 | + ""allowDownvotes"": false, |
| 77 | + ""resetOnSourcePush"": false |
| 78 | + } |
| 79 | + } |
| 80 | + ] |
| 81 | + }")).ConfigureAwait(false); |
| 82 | + |
| 83 | + Assert.DoesNotContain(result[LogLevel.Debug], x => x.Contains("\"minimumApproverCount\": 3")); |
| 84 | + Assert.Contains(result[LogLevel.Debug], x => x.Contains("\"minimumApproverCount\": 6")); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments