Пример #1
0
        public void Setup()
        {
            List <byte[]>      bytesList   = new List <byte[]>(Size);
            List <byte[]>      bytesList2  = new List <byte[]>(Size);
            List <byte[]>      bytesList3  = new List <byte[]>(Size);
            List <MyTestClass> testClasses = new List <MyTestClass>(Size);

            var bogus = new Bogus.Randomizer();

            for (int i = 0; i < Size; i++)
            {
                MyTestClass myTestClass = new MyTestClass();
                myTestClass.BoolProp = bogus.Bool();
                myTestClass.IntList  = new List <int>(100);
                for (int j = 0; j < 100; j++)
                {
                    myTestClass.IntList.Add(bogus.Int());
                }

                myTestClass.StringProp  = bogus.String(10, 100);
                myTestClass.StringProp2 = bogus.String(10, 100);

                bytesList.Add(JsonSerializer.Serialize(myTestClass));
                bytesList3.Add(System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(myTestClass));
                bytesList2.Add(MessagePack.MessagePackSerializer.Typeless.Serialize(myTestClass, ContractlessStandardResolver.Options));
                testClasses.Add(myTestClass);
            }

            _serializedObjectsUtf8Json    = bytesList.ToArray();
            _serializedObjectsMessagePack = bytesList2.ToArray();
            _serializedObjectsTextJson    = bytesList3.ToArray();
            _testClasses = testClasses.ToArray();
        }
Пример #2
0
        public void Sync_Reports_Add()
        {
            var rand     = new Bogus.Randomizer();
            var fromPath = base.GetTempFilePath(".crz3", "Sync_Reports_Add_fromFile");
            var toPath   = base.GetTempFilePath(".crz3", "Sync_Reports_Add_toFile");

            var syncOptions = new CruiseSyncOptions()
            {
                Processing = SyncFlags.Insert,
            };

            var cruiseID = Guid.NewGuid().ToString();
            var saleID   = Guid.NewGuid().ToString();

            using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID);

            fromDb.CopyTo(toPath, true);
            using var toDb = new CruiseDatastore_V3(toPath);

            var reportID = Guid.NewGuid().ToString();
            var report   = new Reports
            {
                CruiseID = cruiseID,
                ReportID = reportID,
                Title    = rand.String(),
            };

            fromDb.Insert(report);

            var syncer = new CruiseSyncer();

            syncer.Sync(cruiseID, fromDb, toDb, syncOptions);

            toDb.GetRowCount("Reports", "WHERE ReportID = @p1", reportID).Should().Be(1);
        }
Пример #3
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));
            }
        }