private async Task CreateTestDataIfNotExistAsync()
        {
            var dataBaseResponse = await _cosmosClient.CreateDatabaseIfNotExistsAsync("APIView");

            var containerResponse = await dataBaseResponse.Database.CreateContainerIfNotExistsAsync("Reviews", "/id");

            if (containerResponse.StatusCode.Equals(HttpStatusCode.Created))
            {
                foreach (int value in Enumerable.Range(1, 2))
                {
                    string[] languages = new String[] { "TestLanguageOne", "TestLanguageTwo" };
                    foreach (string language in languages)
                    {
                        ReviewType[] reviewTypes = new ReviewType[] { ReviewType.Manual, ReviewType.Automatic, ReviewType.PullRequest, ReviewType.All };
                        foreach (ReviewType reviewType in reviewTypes)
                        {
                            bool[] boolvalues = new bool[] { true, false };
                            foreach (var boolValue in boolvalues)
                            {
                                foreach (var boolVal in boolvalues)
                                {
                                    var         container = containerResponse.Container;
                                    ReviewModel review    = new ReviewModel
                                    {
                                        Name               = $"TestReview{value}_For_{language}_For_{reviewType.ToString()}_For{boolValue}_For{boolVal}",
                                        Author             = $"TestReviewAuthor{value}",
                                        CreationDate       = DateTime.Now,
                                        IsClosed           = boolValue,
                                        FilterType         = reviewType,
                                        ServiceName        = $"TestServiceName{value}",
                                        PackageDisplayName = $"TestPackageDisplayName{value}"
                                    };
                                    var revisions = new ReviewRevisionModelList(review);
                                    foreach (int val in Enumerable.Range(1, 2))
                                    {
                                        var revision = new ReviewRevisionModel
                                        {
                                            Name = $"TestRevision{value}_{val}",
                                        };

                                        if (boolVal)
                                        {
                                            revision.Approvers.Add($"TestApprover{value}_{val}");
                                        }

                                        foreach (int v in Enumerable.Range(1, 2))
                                        {
                                            var file = new ReviewCodeFileModel
                                            {
                                                Name     = $"TestFile{value}_{val}_{v}",
                                                Language = language
                                            };
                                            revision.Files.Add(file);
                                        }
                                        revisions.Add(revision);
                                    }
                                    review.Revisions = revisions;
                                    await _cosmosReviewRepository.UpsertReviewAsync(review);
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
 public ReviewModel()
 {
     Revisions = new ReviewRevisionModelList(this);
 }