public void Register()
        {
            var anon = new AnonymousData();

            anon.Register <IModel>(_ => new Model());
            var result = (IModel)anon.Any(typeof(IModel));

            Assert.NotNull(result);
        }
Exemple #2
0
            public AnonymousDataContext(AnonymousData factory, Type resultType)
            {
                Argument.NotNull(factory, nameof(factory));
                Argument.NotNull(resultType, nameof(resultType));

                this.factory = factory;
                ResultType   = resultType;
                current      = this.factory.customizations.Count;
            }
Exemple #3
0
        public void AnyString()
        {
            var anon = new AnonymousData();

            var result = anon.AnyString();

            Assert.NotNull(result);
            Assert.True(result.All(c => char.IsLetter(c)));
        }
        public void RegisterDefault()
        {
            var anon = new AnonymousData();

            // Registration happens in the class fixture AnonymousDataTestsFixture.
            var result = anon.Any <GloballyRegisteredModel>();

            Assert.Equal("xyzzy", result.Value);
        }
        public void FreezeValue()
        {
            var anon = new AnonymousData();

            anon.Freeze(42);
            var result = anon.Any <int>();

            Assert.Equal(42, result);
        }
        public void Register_DerivedPropertyExpression()
        {
            var anon  = new AnonymousData();
            var value = anon.Any <string>();

            anon.Register((DerivedModel m) => m.Unset, _ => value);
            var result = anon.Any <DerivedModel>(PopulateOption.Deep);

            Assert.Same(value, result.Unset);
        }
Exemple #7
0
        public void TestAnyEnumerable_TypeMinMaxLength()
        {
            var anon = new AnonymousData();

            var result = anon.AnyEnumerable(typeof(int), 4, 10);
            var count  = result.OfType <int>().Count();

            Assert.NotNull(result);
            Assert.True(count >= 4 && count <= 10);
        }
        public void Any_Predicate_ShouldEnsurePredicate()
        {
            var anon = new AnonymousData();

            bool Predicate(int i) => (i % 2) == 0;

            var result = anon.Any <int>(Predicate);

            Assert.True(Predicate(result));
        }
Exemple #9
0
        public void Register_PropertyExpression()
        {
            var anon  = new AnonymousData();
            var model = anon.Any <Model>();

            anon.Register((DeepModel m) => m.Model, a => model);
            var result = anon.Any <DeepModel>(PopulateOption.Deep);

            Assert.Same(model, result.Model);
        }
Exemple #10
0
        public void TestAnyEnumerableT_MinMaxLength()
        {
            var anon = new AnonymousData();

            var result = anon.AnyEnumerable <int>(4, 10);
            var count  = result.Count();

            Assert.NotNull(result);
            Assert.True(count >= 4 && count <= 10);
        }
Exemple #11
0
        public void RegisterDefault_PropertyExpression()
        {
            var anon  = new AnonymousData();
            var model = new AnonymousDataTestsFixture.GloballyRegisteredModel();

            // Registration happens in the class fixture AnonymousDataTestsFixture.
            anon.Populate(model);

            Assert.Equal("xyzzy", model.Value);
        }
Exemple #12
0
        public void Any_PopulateShallow_ShouldPopulateFirstLevel()
        {
            var anon = new AnonymousData();

            var result = anon.Any <DeepModel>(PopulateOption.Shallow);

            Assert.NotNull(result);
            Assert.NotNull(result.Model);
            Assert.Equal(result.Model.Value, nameof(Model));
        }
Exemple #13
0
        public void Customize()
        {
            var anon = new AnonymousData();

            anon.Customize(new Customization());

            var result = (IModel)anon.Any(typeof(IModel));

            Assert.NotNull(result);
        }
Exemple #14
0
        public void AnyString_MinMaxLengthDistribution()
        {
            var anon = new AnonymousData();

            var result = anon.AnyString(4, 10, Distribution.Uniform);

            Assert.NotNull(result);
            Assert.True(result.All(c => char.IsLetter(c)));
            Assert.True(result.Length >= 4 && result.Length <= 10);
        }
        public void AnyAlphaChar()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <char>();

            classifier.AddClassification("Alpha", d => char.IsLetter(d));

            classifier.Classify(() => anon.AnyAlphaChar());

            Assert.True(classifier["Alpha"] == 1.0);
        }
Exemple #16
0
        public void SetMinMaxItemsConstrainsSize()
        {
            var anon = new AnonymousData();

            anon.SetMinimumItemCount(2);
            anon.SetMaximumItemCount(2);

            var result = anon.Any <List <int> >();

            Assert.Equal(2, result.Count);
        }
        public void AnyLatinSupplementChar()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <char>();

            classifier.AddClassification("Alpha", d => d >= 0xa0 && d <= 0xff);

            classifier.Classify(() => anon.AnyLatinSupplementChar());

            Assert.True(classifier["Alpha"] == 1.0);
        }
        public void AnyPrintableChar()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <char>();

            classifier.AddClassification("Alpha", d => (d >= 0x20 && d <= 0x7f) || (d >= 0xa0 && d <= 0xff));

            classifier.Classify(() => anon.AnyPrintableChar());

            Assert.True(classifier["Alpha"] == 1.0);
        }
        public void AnyBasicLatinChar_Distribution()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <char>();

            classifier.AddClassification("Alpha", d => d >= 0x20 && d <= 0x7f);

            classifier.Classify(() => anon.AnyBasicLatinChar(Distribution.Uniform));

            Assert.True(classifier["Alpha"] == 1.0);
        }
        public void AnyAlphaNumericChar_Distribution()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <char>();

            classifier.AddClassification("Alpha", d => char.IsLetterOrDigit(d));

            classifier.Classify(() => anon.AnyAlphaNumericChar(Distribution.Uniform));

            Assert.True(classifier["Alpha"] == 1.0);
        }
Exemple #21
0
        public void AnyFullName()
        {
            var anon = new AnonymousData();

            // Do this a few times to cover all branches.
            for (int i = 0; i < 50; ++i)
            {
                var name = anon.AnyFullName();

                Assert.NotNull(name);
            }
        }
Exemple #22
0
        public void Any_PopulateDeepWithCollections_ShouldPopulateCollections()
        {
            var anon = new AnonymousData();

            var result = anon.Any <DeepModelWithCollection>(PopulateOption.Deep);

            Assert.NotNull(result);
            Assert.NotEmpty(result.ReadOnlyNames);
            Assert.NotEmpty(result.InitializedNames);
            Assert.NotEmpty(result.UninitializedNames);
            Assert.NotEmpty(result.Dictionary);
        }
        public void Any_Populate_ShouldPopulateFirstLevel()
        {
            var anon = new AnonymousData();

            var result = anon.Any <DeepModel>();

            anon.Populate(result);

            Assert.NotNull(result);
            Assert.NotNull(result.Model);
            Assert.Equal(nameof(Model), result.Model.Value);
        }
Exemple #24
0
        public void Any_Double()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <double>();

            classifier.AddClassification("GT", d => d > 0);
            classifier.AddClassification("LT", d => d < 0);

            classifier.Classify(() => (double)anon.Any(typeof(double)));

            Assert.True(classifier["GT"] > 0.4);
            Assert.True(classifier["LT"] > 0.4);
        }
        public void AnyChar()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <char>();

            classifier.AddClassification("GT", d => d > (char.MaxValue / 2));
            classifier.AddClassification("LT", d => d < (char.MaxValue / 2));

            classifier.Classify(() => anon.AnyChar());

            Assert.True(classifier["GT"] > 0.4);
            Assert.True(classifier["LT"] > 0.4);
        }
        public void AnyInt64()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <long>();

            classifier.AddClassification("GT", d => d > 0);
            classifier.AddClassification("LT", d => d < 0);

            classifier.Classify(() => anon.AnyInt64());

            Assert.True(classifier["GT"] > 0.4);
            Assert.True(classifier["LT"] > 0.4);
        }
Exemple #27
0
        public void AnyDouble_MinMaxDistribution()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <double>();

            classifier.AddClassification("GT", d => d > 0);
            classifier.AddClassification("LT", d => d < 0);

            classifier.Classify(() => anon.AnyDouble(float.MinValue, float.MaxValue, Distribution.Uniform));

            Assert.True(classifier["GT"] > 0.4);
            Assert.True(classifier["LT"] > 0.4);
        }
        public void AnyDateTimeOffset()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <DateTimeOffset>();

            classifier.AddClassification("GT", d => d.Ticks > (DateTimeOffset.MaxValue.Ticks / 2));
            classifier.AddClassification("LT", d => d.Ticks < (DateTimeOffset.MaxValue.Ticks / 2));

            classifier.Classify(() => anon.AnyDateTimeOffset());

            Assert.True(classifier["GT"] > 0.4);
            Assert.True(classifier["LT"] > 0.4);
        }
Exemple #29
0
        public void AnyInt16_MinMax()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <short>();

            classifier.AddClassification("GT", d => d > 0);
            classifier.AddClassification("LT", d => d < 0);

            classifier.Classify(() => anon.AnyInt16(short.MinValue, short.MaxValue));

            Assert.True(classifier["GT"] > 0.4);
            Assert.True(classifier["LT"] > 0.4);
        }
Exemple #30
0
        public void AnyInt16_Distribution()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <short>();

            classifier.AddClassification("GT", d => d > 0);
            classifier.AddClassification("LT", d => d < 0);

            classifier.Classify(() => anon.AnyInt16(Distribution.Uniform));

            Assert.True(classifier["GT"] > 0.4);
            Assert.True(classifier["LT"] > 0.4);
        }