Beispiel #1
0
        public IGen <Test> ItRendersOneLine() =>
        from value in Gen.Choose(DomainGen.Any(), DomainGen.AnyList())
        select Property.ForThese(() =>
        {
            var rendering = ExampleRenderer.Render(new object[] { value });

            rendering.Should().ContainSingle();
        });
        public NebulaCheck.IGen <Test> ItDoesNotConsumeRandomness() =>
        from value in DomainGen.Any()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Constant(value);

            var sample = gen.Advanced.SampleOneWithMetrics(seed: seed, size: size);

            sample.RandomnessConsumption.Should().Be(0);
        });
        public NebulaCheck.IGen <Test> ItCanGenerateAnEmptyRecord() =>
        from value in DomainGen.Any()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Create <EmptyRecord>();

            var instance = gen.SampleOne(seed: seed, size: size);

            instance.Should().NotBeNull();
        });
            public NebulaCheck.IGen <Test> ItIsPure() =>
            from input in DomainGen.Any().Two()
            from returnGen in DomainGen.Gen()
            from seed in DomainGen.Seed()
            from size in DomainGen.Size()
            select Property.ForThese(() =>
            {
                var gen = returnGen.FunctionOf <object, object, object>();

                var func = gen.SampleOne(seed: seed, size: size);

                func(input.Item1, input.Item2).Should().Be(func(input.Item1, input.Item2));
            });
        public NebulaCheck.IGen <Test> IfTheClassHasARecursiveProperty_ItErrors() =>
        from value in DomainGen.Any()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Create <ClassWithRecursiveProperty>();

            Action action = () => gen.SampleOne(seed: seed, size: size);

            action.Should()
            .Throw <GalaxyCheck.Exceptions.GenErrorException>()
            .WithMessage("Error while running generator ReflectedGen: detected circular reference on type '*ClassWithRecursiveProperty' at path '$.Property'");
        });
        public NebulaCheck.IGen <Test> ItCanOverrideANestedExternalInitProperty() =>
        from value in DomainGen.Any()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen
                      .Create <RecordWithOneNestedProperty>()
                      .OverrideMember(x => x.Property.Property, GalaxyCheck.Gen.Constant(value));

            var instance = gen.SampleOne(seed: seed, size: size);

            instance.Should().NotBeNull();
            instance.Property.Property.Should().Be(value);
        });
        public NebulaCheck.IGen <Test> ItProducesTheGivenValue() =>
        from value in DomainGen.Any()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Constant(value);

            var traversal = gen.Advanced
                            .SampleOneExampleSpace(seed: seed, size: size)
                            .TraverseExamples()
                            .Take(100)
                            .ToList();

            traversal
            .Should().ContainSingle()
            .Subject.Should().BeEquivalentTo(new Example <object>(ExampleId.Empty, value, 0));
        });
Beispiel #8
0
        public NebulaCheck.IGen <Test> ItCanGenerateAnObjectWithTwoProperties() =>
        from value1 in DomainGen.Any()
        from value2 in DomainGen.Any()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen
                      .Factory()
                      .RegisterType(GalaxyCheck.Gen.Int32().Where(x => x != 0))
                      .Create <ClassWithTwoProperties>();

            var instance = gen.SampleOne(seed: seed, size: size);

            instance.Should().NotBeNull();
            instance.Property1.Should().NotBe(0);
            instance.Property2.Should().NotBe(0);
        });
Beispiel #9
0
        public NebulaCheck.IGen <Test> IfTheReplayEncodesAPreconditionFailure_ItThrows() =>
        from value in DomainGen.Any()
        from replaySeed in Gen.Int32()
        from replaySize in Gen.Int32().Between(0, 100)
        from replayPath in Gen.Int32().ListOf()
        select Property.ForThese(() =>
        {
            var property = GalaxyCheck.Gen.Constant(value).ForAll((_) =>
            {
                GalaxyCheck.Property.Precondition(false);
            });
            var replay = ReplayEncoding.Encode(CreateReplay(replaySeed, replaySize, replayPath));

            Action test = () => property.Check(replay: replay);

            test.Should()
            .Throw <GalaxyCheck.Exceptions.GenErrorException>()
            .WithMessage("Error replaying last example, given replay string was no longer valid.*");
        });
 public static IGen <WeightedElement <object> > WeightedElement() =>
 from weight in Gen.Int32().Between(0, 100)
 from value in DomainGen.Any()
 select new WeightedElement <object>(weight, value);