Exemplo n.º 1
0
        public void SortedByMake_ShouldReturnSortedListOfCarsByMake()
        {
            // Arrange
            var datebase = new List <Car>();
            var firstCar = new Car {
                Id = 1, Make = "Audi", Model = "A5", Year = 2005
            };
            var secondCar = new Car {
                Id = 2, Make = "Moskvich", Model = "12-tak", Year = 1980
            };
            var thirdCar = new Car {
                Id = 3, Make = "Lada", Model = "7-marka", Year = 1991
            };

            datebase.Add(firstCar);
            datebase.Add(secondCar);
            datebase.Add(thirdCar);

            var mock = new Mock <IDatabase>();

            mock.Setup(m => m.Cars).Returns(datebase);
            var fakeDB         = mock.Object;
            var carsRepository = new CarsRepository(fakeDB);

            // Act
            var sortedListByMake = carsRepository.SortedByMake();
            var expected         = "Audi";

            // Assert
            Assert.AreEqual(expected, (sortedListByMake.First()).Make);
        }
Exemplo n.º 2
0
        public void SortedByMake_ShouldReturnACollectionSortedInAlphabeticalOrder()
        {
            // Arrange

            // Step 1: Build list of cars
            var dbListOfCars = new List <Car>();

            for (int i = 0; i < 26; i++)
            {
                var newCar = new FakeCar();
                newCar.Make = ((char)('z' - i)).ToString();
                //newCar.SetupGet(car => car.Make).Returns(((char)('z' - i)).ToString());
                dbListOfCars.Add(newCar);
            }

            // Step 2: Init Database and CarRepo
            var mockDb = new Mock <IDatabase>();

            mockDb.SetupGet(db => db.Cars).Returns(dbListOfCars);

            var carRepo = new CarsRepository(mockDb.Object);

            // Act
            var actualSortedList = carRepo.SortedByMake();
            var expected         = "a";

            Assert.AreEqual(expected, (actualSortedList.First()).Make);
        }
Exemplo n.º 3
0
        public void CarsRepositorySortedByMake_ShouldReturnSortedCollection(int numberOfCars)
        {
            var collection = new List <Car>();
            var rng        = new Random();

            // make car with random make
            for (int i = 0; i < numberOfCars; i++)
            {
                var makeString = new string(((char)(65 + rng.Next(26))), rng.Next(10));
                makeString = (i % 2) == 0 ? makeString : makeString.ToUpper();

                var car = new CarChild(make: makeString);
                collection.Add(car);
            }

            var mockDb = new Mock <IDatabase>();

            mockDb.Setup(x => x.Cars).Returns(collection);

            var repo = new CarsRepository(mockDb.Object);

            var expected = collection
                           .OrderBy(x => x.Make)
                           .ToList();

            CollectionAssert.AreEqual(expected, repo.SortedByMake());
        }
        public void TestCarsRepository_SortedByMake_ShouldWorkCorrectly()
        {
            var carRepo = new CarsRepository();

            foreach (var car in cars)
            {
                carRepo.Add(car);
            }

            Assert.AreEqual(cars.OrderBy(c => c.Make).ToList(), carRepo.SortedByMake());
        }
Exemplo n.º 5
0
        public void CarsRepositorySortedByMake_ShouldReturnSortedByMakeCollection()
        {
            var numberOfCars = 10;
            var rng          = new Random();

            var collection = new List <ICar>();

            for (int i = 0; i < numberOfCars; i++)
            {
                var car  = Mock.Create <ICar>();
                var make = new string((char)(65 + rng.Next(26)), rng.Next(10));

                if (i % 2 == 0)
                {
                    make = make.ToUpper();
                }

                Mock.Arrange(() => car.Make).Returns(make);

                collection.Add(car);
            }

            var mockDb = Mock.Create <IDatabase>();

            Mock.Arrange(() => mockDb.Cars).Returns(collection);

            var repo = new CarsRepository(mockDb);

            var expected = collection
                           .OrderBy(x => x.Make)
                           .ToList();

            var result = repo
                         .SortedByMake()
                         .ToList();

            var areEquls = expected.Count == result.Count;

            if (areEquls)
            {
                for (int i = 0; i < numberOfCars; i++)
                {
                    if (!expected[i].Equals(result[i]))
                    {
                        areEquls = false;
                    }
                }
            }

            Assert.IsTrue(areEquls);
        }