Exemplo n.º 1
0
 internal MyClassFixture()
 {
     this.Things = new List <Thing>();
     this.Register <IMyInterface>(() =>
     {
         var fake = new FakeMyInterface();
         this.Things.ToList().ForEach(t =>
                                      fake.AddThing(t));
         return(fake);
     });
 }
Exemplo n.º 2
0
        public void NumberSumIsCorrect_AutoFixture()
        {
            // Arrange
            Fixture      fixture = new Fixture();
            IMyInterface fake    = new FakeMyInterface();

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

            var things = fixture.CreateMany <Thing>().ToList();

            things.ForEach(t => fake.AddThing(t));
            int expectedSum = things.Select(t => t.Number).Sum();

            MyClass sut = fixture.Create <MyClass>();
            // Act
            int result = sut.CalculateSumOfThings();

            // Assert
            Assert.Equal <int>(expectedSum, result);
        }