Esempio n. 1
0
        public void CarListSorterSorts()
        {
            CarSorter sorter = new CarSorter()
            {
                Comparer = new CarPriceComparer()
            };

            Car[] cars = new Car[]
            {
                new Car()
                {
                    ID = 0, Make = "Audi", Model = "S3", Price = 20M
                },
                new Car()
                {
                    ID = 1, Make = "Audi", Model = "S4", Price = 30M
                },
                new Car()
                {
                    ID = 2, Make = "Suzuki", Model = "Splash", Price = 10M
                }
            };

            sorter.Sort(cars);

            Assert.IsTrue(cars.Select(c => c.ID).SequenceEqual(new[] { 2, 0, 1 }));

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <CarSorter> _sorter     = test.CreateVariable <CarSorter>();
            TestVariable <Car[]>     _carsBefore = test.CreateVariable <Car[]>();

            test.Arrange(_sorter, Expr(() => new CarSorter()
            {
                Comparer = new CarPriceComparer()
            }));
            test.Arrange(_carsBefore, Expr(() => new Car[]
            {
                new Car()
                {
                    ID = 0, Make = "Audi", Model = "S3", Price = 20M
                },
                new Car()
                {
                    ID = 1, Make = "Audi", Model = "S4", Price = 30M
                },
                new Car()
                {
                    ID = 2, Make = "Suzuki", Model = "Splash", Price = 10M
                }
            }));
            test.Act(Expr(_sorter, _carsBefore, (s, c) => s.Sort(c)));
            test.Assert.IsTrue(Expr(_carsBefore, c1 => c1.Select(c => c.ID).SequenceEqual(new[] { 2, 0, 1 })));
            test.Execute();
        }
Esempio n. 2
0
        public void CarSorterComparerInitializesToNull()
        {
            CarSorter sorter = new CarSorter();

            Assert.IsNull(sorter.Comparer);

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <CarSorter> _sorter = test.CreateVariable <CarSorter>();

            test.Arrange(_sorter, Expr(() => new CarSorter()));
            test.Assert.IsNull(Expr(_sorter, s => s.Comparer));
            test.Execute();
        }