protected override void Init()
        {
            Serializer = new Serializer(new SerializerOptions(preserveObjectReferences: true));
            var a = new CyclicClassA();
            var b = new CyclicClassB();

            a.B    = b;
            b.A    = a;
            cyclic = a;

            virtualObject = new VirtualTestClass
            {
                DateProp   = DateTime.Now,
                GuidProp   = Guid.NewGuid(),
                IntProp    = 812342354,
                StringProp = new string('x', 30)
            };

            sealedObject = LargeSealedClass.MakeRandom();

            genericObject = new GenericClass <int, string, bool, DateTime, Guid>(123, "hello-world", true, DateTime.Now, Guid.NewGuid());
        }
Exemple #2
0
        protected override void Init()
        {
            var baseOptions = new SerializerOptions(preserveObjectReferences: true);

            Serializer = new Serializer(baseOptions);

            var filteredOptions = baseOptions
                                  .WithTypeFilter(
                TypeFilterBuilder.Create()
                .Include <CyclicClassA>()
                .Include <CyclicClassB>()
                .Include <VirtualTestClass>()
                .Include <LargeSealedClass>()
                .Include <GenericClass <int, string, bool, DateTime, Guid> >()
                .Include <TestEnum>()
                .Build());

            _filteredSerializer = new Serializer(filteredOptions);

            var a = new CyclicClassA();
            var b = new CyclicClassB();

            a.B    = b;
            b.A    = a;
            cyclic = a;

            virtualObject = new VirtualTestClass
            {
                DateProp   = DateTime.Now,
                GuidProp   = Guid.NewGuid(),
                IntProp    = 812342354,
                StringProp = new string('x', 30)
            };

            sealedObject = LargeSealedClass.MakeRandom();

            genericObject = new GenericClass <int, string, bool, DateTime, Guid>(123, "hello-world", true, DateTime.Now, Guid.NewGuid());
        }
        public static LargeSealedClass MakeRandom()
        {
            var rnd = counter++;

            var data = new LargeSealedClass
            {
                FirstName        = NaturalTextGenerator.GenerateFirstName(),
                MiddleName       = NaturalTextGenerator.GenerateFirstName(),
                LastName         = NaturalTextGenerator.GenerateLastName(),
                DOB              = DateTime.Now.AddYears(5),
                Salary           = 55435345,
                YearsOfService   = 25,
                CreditScore      = 0.7562,
                RegisteredToVote = (DateTime.UtcNow.Ticks & 1) == 0,
                TestEnum         = TestEnum.HatesAll,
                Address1         = NaturalTextGenerator.GenerateAddressLine(),
                Address2         = NaturalTextGenerator.GenerateAddressLine(),
                AddressCity      = NaturalTextGenerator.GenerateCityName(),
                AddressState     = "CA",
                AddressZip       = "91606",
                HomePhone        = (DateTime.UtcNow.Ticks & 1) == 0 ? "(555) 123-4567" : null,
                EMail            = NaturalTextGenerator.GenerateEMail()
            };

            if (0 != (rnd & (1 << 32)))
            {
                data.Notes = NaturalTextGenerator.Generate(45);
            }
            if (0 != (rnd & (1 << 31)))
            {
                data.SkypeID = NaturalTextGenerator.GenerateEMail();
            }
            if (0 != (rnd & (1 << 30)))
            {
                data.YahooID = NaturalTextGenerator.GenerateEMail();
            }

            if (0 != (rnd & (1 << 29)))
            {
                data.IsSmoker = 0 != (rnd & (1 << 17));
            }
            if (0 != (rnd & (1 << 28)))
            {
                data.IsLoving = 0 != (rnd & (1 << 16));
            }
            if (0 != (rnd & (1 << 27)))
            {
                data.IsLoved = 0 != (rnd & (1 << 15));
            }
            if (0 != (rnd & (1 << 26)))
            {
                data.IsDangerous = 0 != (rnd & (1 << 14));
            }
            if (0 != (rnd & (1 << 25)))
            {
                data.IsEducated = 0 != (rnd & (1 << 13));
            }

            if (0 != (rnd & (1 << 24)))
            {
                data.LastSmokingDate = DateTime.Now.AddYears(-10);
            }


            if (0 != (rnd & (1 << 23)))
            {
                data.DesiredSalary = rnd / 1000m;
            }
            if (0 != (rnd & (1 << 22)))
            {
                data.ProbabilityOfSpaceFlight = rnd / (double)int.MaxValue;
            }

            if (0 != (rnd & (1 << 21)))
            {
                data.CurrentFriendCount = rnd % 123;
                data.DesiredFriendCount = rnd % 121000;
            }

            return(data);
        }