public Resource Next(string subscriptionId, string resourceGroupName, string resourceGroupLocation, double sizeFactor = 1.0)
        {
            var resourceType = this.ResourceTypes.PickRandomItem();

            return(new Resource
            {
                SubscriptionId = subscriptionId,
                ResourceGroupName = resourceGroupName,
                ResourceId = $"{resourceType}/{RandomIdGenerator.GetBase62(RandomNumber.Next(8, 96))}",
                Location = this.Locations.PickRandomItem(),
                Zones = this.Zones.PickRandomItems(),
                ResourceGroupLocation = resourceGroupLocation,
                ProvisioningState = this.ProvisioningStates.PickRandomItem(),
                ManagedBy = RandomIdGenerator.GetBase62(16),
                Sku = this.Skus.GetValueOrDefault(resourceType),
                Kind = this.Kinds.GetValueOrDefault(resourceType),
                Tags = this.GenerateTags(sizeFactor),
                Plan = null,
                Scale = null,
                Identity = this.MsiResourceTypes.Contains(resourceType)
                    ? this.GenerateResourceIdentity(this.ExplicitIdentityCounts.PickRandomItem(), subscriptionId, resourceGroupName)
                    : null,
                CreatedTime = DateTime.Now,
                ChangedTime = DateTime.Now,
                EntityTag = RandomIdGenerator.GetBase36(16)
            });
        }
        private TagsDictionary GenerateTags(double sizeFactor = 1.0)
        {
            const int maxNumberOfTags   = 15;
            const int maxTagKeyLength   = 512;
            const int maxTagValueLength = 256;

            var factor = sizeFactor / 8.0;
            var tagCount = new[] { 0, 0, RandomNumber.Next(1, maxNumberOfTags + 1) }.PickRandomItem();

            return(new TagsDictionary(
                       dictionary: Enumerable
                       .Range(0, tagCount)
                       .ToDictionary(
                           i => RandomIdGenerator.GetBase62(RandomNumber.Next(3, (int)(maxTagKeyLength * factor))),
                           i => RandomIdGenerator.GetBase62(RandomNumber.Next(3, (int)(maxTagValueLength * factor))))));
        }
 public ResourceGenerator(int[][] patterns)
 {
     this.Subscriptions = patterns
                          .Select(sub => new Subscription
     {
         Id             = Guid.NewGuid().ToString(),
         ResourceGroups = sub
                          .Select(rg => new ResourceGroup
         {
             Name          = RandomIdGenerator.GetBase62(RandomNumber.Next(5, 64)),
             Location      = this.Locations.PickRandomItem(),
             ResourceCount = rg
         })
                          .ToArray()
     })
                          .ToArray();
 }
Esempio n. 4
0
 /// <summary>
 /// Produces the random interval less than the specified maximum.
 /// </summary>
 /// <param name="maximum">The maximum value.</param>
 public static TimeSpan Next(TimeSpan maximum)
 {
     return(RandomNumber.Next(TimeSpan.Zero, maximum));
 }