public async Task ChangeAppPath()
        {
            // [Setup]
            // setup webhost using appsettings with specific path

            var random          = new Bogus.Randomizer();
            var randomPathChars = random.Chars('a', 'z', random.Int(1, 10));
            var randomPath      = new string(randomPathChars);
            var randomSecret    = random.Words(10);



            var hostbuilder =
                WebHost
                .CreateDefaultBuilder()
                .ConfigureServices(s =>
            {
                s
                .AddOurOrders(appSettings =>
                {
                    appSettings.Path      = randomPath;
                    appSettings.JwtSecret = randomSecret;
                })
                .UseInMemoryDB();
            })
                .Configure(appbuilder =>
            {
                appbuilder
                .UseOurOrders();
            });

            var server     = new TestServer(hostbuilder);
            var httpClient = server.CreateClient();


            // [Exercise]
            // send a request to the webhost on the specified path
            var path     = $"/{randomPath}/account/current";
            var response = await httpClient.GetAsync(path);

            // [Verify]
            // check if request is successful
            Assert.True(response.IsSuccessStatusCode);

            // [Teardown]
            // shut down the server that we setup
            server.Dispose();
        }
Ejemplo n.º 2
0
        public static string BuildTestString(string pattern)
        {
            if (string.IsNullOrWhiteSpace(pattern))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(pattern));
            }

            var randomizer = new Bogus.Randomizer();

            const int noMatchPercentage = 50;

            if (WeightedMatch(noMatchPercentage))
            {
                return(randomizer.String());
            }

            const int charMatchPercentage = 95;
            var       strBuilder          = new StringBuilder(pattern.Length * 2);

            foreach (var patternCh in pattern)
            {
                if (patternCh == '?')
                {
                    strBuilder.Append(randomizer.AlphaNumeric(1));
                }
                else if (patternCh == '*')
                {
                    strBuilder.Append(randomizer.Words());
                }
                else
                {
                    if (WeightedMatch(charMatchPercentage))
                    {
                        strBuilder.Append(patternCh);
                    }
                }
            }

            var str = strBuilder.ToString();

            return(str);

            bool WeightedMatch(int percentage)
            {
                return(randomizer.Bool(percentage / 100f));
            }
        }