Ejemplo n.º 1
0
        public void Customize(IFixture fixture)
        {
            Things = new List <Thing>();

            fixture.Register <IMyInterface>(() =>
            {
                var fake = new FakeMyInterface();
                Things
                .ToList()
                .ForEach(fake.AddThing);
                return(fake);
            });

            fixture.AddManyTo(Things);
        }
Ejemplo n.º 2
0
        internal MyClassFixture()
        {
            Things = new List <Thing>();

            this.Register <IMyInterface>(() =>
            {
                var fake = new FakeMyInterface();
                Things
                .ToList()
                .ForEach(fake.AddThing);
                return(fake);
            });

            this.AddManyTo(Things);
        }
        public void WithoutAutoFixture()
        {
            // Fixture setup
            var thing1 = new Thing
            {
                Number = 3
                ,
                Text = "Anonymous text 1"
            };
            var thing2 = new Thing
            {
                Number = 6
                ,
                Text = "Anonymous text 2"
            };
            var thing3 = new Thing
            {
                Number = 1
                ,
                Text = "Anonymous text 3"
            };

            var expectedSum = new[] { thing1, thing2, thing3 }
            .Select(t => t.Number).Sum();

            IMyInterface fake = new FakeMyInterface();

            fake.AddThing(thing1);
            fake.AddThing(thing2);
            fake.AddThing(thing3);

            var sut = new MyClass(fake);

            // Exercise system
            var result = sut.CalculateSumOfThings();

            // Verify outcome
            result.Should().Be(expectedSum);
            // Fixture teardown
        }
        public void ImperativeStyle()
        {
            // Fixture setup
            var fixture = new Fixture();
            var things  = fixture.CreateMany <Thing>().ToList();

            IMyInterface fake = new FakeMyInterface();

            fixture.Register <IMyInterface>(() => fake);

            things.ForEach(t => fake.AddThing(t));

            var expectedSum = things.Select(t => t.Number).Sum();

            var sut = fixture.Create <MyClass>();

            // Exercise system
            var result = sut.CalculateSumOfThings();

            // Verify outcome
            result.Should().Be(expectedSum);
            // Fixture teardown
        }