コード例 #1
0
        protected override void DoHandleWork(WorkContext work)
        {
            var cnt    = work.MatchedVars["cnt"].AsInt(10);
            var pretty = work.MatchedVars["pretty"].AsBool(true);

            if (cnt > 10000)
            {
                cnt = 10000;
            }
            if (cnt < 0)
            {
                cnt = 1;
            }

            var lst = new List <object>();

            for (var i = 0; i < cnt; i++)
            {
                lst.Add(new {
                    FirstName  = NaturalTextGenerator.GenerateFirstName(),
                    MiddleName = NaturalTextGenerator.GenerateFirstName(),
                    LastName   = NaturalTextGenerator.GenerateLastName(),
                    Address    = "{0}\n{1}".Args(NaturalTextGenerator.GenerateAddressLine(),
                                                 NaturalTextGenerator.GenerateUSCityStateZip()),
                    Email = NaturalTextGenerator.GenerateEMail()
                });
            }

            work.Response.WriteJSON(lst, pretty ?
                                    NFX.Serialization.JSON.JSONWritingOptions.PrettyPrint :
                                    NFX.Serialization.JSON.JSONWritingOptions.Compact);
        }
コード例 #2
0
 public static N3_PartyAddress Make()
 {
     return(new N3_PartyAddress
     {
         AddressInformation1 = NaturalTextGenerator.GenerateAddressLine(),
         AddressInformation2 = NaturalTextGenerator.GenerateUSCityStateZip()
     });
 }
コード例 #3
0
 public void GenerateUSCityStateZipNames()
 {
     for (var i = 0; i < 100; i++)
     {
         var txt = NaturalTextGenerator.GenerateUSCityStateZip();
         Console.WriteLine(txt);
         Assert.IsTrue(txt.IsNotNullOrWhiteSpace());
         Assert.IsTrue(txt.Length >= 3);
         Assert.IsTrue(txt.Length <= 50);
     }
 }
コード例 #4
0
        public void PerfFullInfo()
        {
            const int CNT = 1000000;
            var       sw  = Stopwatch.StartNew();

            for (var i = 0; i < CNT; i++)
            {
                var name = NaturalTextGenerator.GenerateFirstName() + " " + NaturalTextGenerator.GenerateLastName();
                var addr = NaturalTextGenerator.GenerateAddressLine();
                var csz  = NaturalTextGenerator.GenerateUSCityStateZip();
            }

            var elapsed = sw.ElapsedMilliseconds;
            var ops     = CNT / (elapsed / 1000d);

            Console.WriteLine("Genereated {0} full infos, in {1:n0} ms at {2:n0} ops/sec", CNT, elapsed, ops);
            Assert.IsTrue(ops > 180000);//180,000 ops/sec
        }
コード例 #5
0
        public void PerfFullInfo_Parallel()
        {
            const int CNT = 3000000;
            var       sw  = Stopwatch.StartNew();

            System.Threading.Tasks.Parallel.For(0, CNT,
                                                (i) =>
            {
                var name = NaturalTextGenerator.GenerateFirstName() + " " + NaturalTextGenerator.GenerateLastName();
                var addr = NaturalTextGenerator.GenerateAddressLine();
                var csz  = NaturalTextGenerator.GenerateUSCityStateZip();
            });

            var elapsed = sw.ElapsedMilliseconds;
            var ops     = CNT / (elapsed / 1000d);

            Assert.IsTrue(ops > 750000);//750,000 ops/sec

            Console.WriteLine("Genereated {0} full infos, in {1:n0} ms at {2:n0} ops/sec", CNT, elapsed, ops);
        }
コード例 #6
0
 public void GenerateFullInfo()
 {
     for (var i = 0; i < 100; i++)
     {
         var name = NaturalTextGenerator.GenerateFirstName() + " " + NaturalTextGenerator.GenerateLastName();
         var addr = NaturalTextGenerator.GenerateAddressLine();
         var csz  = NaturalTextGenerator.GenerateUSCityStateZip();
         Console.WriteLine(name);
         Console.WriteLine(addr);
         Console.WriteLine(csz);
         Console.WriteLine("-------------------------------------------");
         Assert.IsTrue(name.IsNotNullOrWhiteSpace());
         Assert.IsTrue(addr.IsNotNullOrWhiteSpace());
         Assert.IsTrue(csz.IsNotNullOrWhiteSpace());
         Assert.IsTrue(name.Length >= 3);
         Assert.IsTrue(name.Length <= 100);
         Assert.IsTrue(addr.Length >= 3);
         Assert.IsTrue(addr.Length <= 100);
         Assert.IsTrue(csz.Length >= 3);
         Assert.IsTrue(csz.Length <= 100);
     }
 }