Example #1
0
        public void ItMapsHorse()
        {
            // Arrange
            var service = new HorseService(_fakeRepository);
            var horse   = new HorseCreate
            {
                Name    = "Test",
                ColorId = 1,
                Win     = 2,
                Place   = 3,
                Show    = 4,
                Starts  = 5,
                SireId  = 6,
                DamId   = 7
            };

            // Act
            service.Create(horse);
            var actual = _fakeRepository.AddCalledWith;

            // Assert
            Assert.Equal(horse.Name, actual.Name);
            Assert.Equal(horse.ColorId, actual.ColorId);
            Assert.Equal(horse.Win, actual.RaceWins);
            Assert.Equal(horse.Place, actual.RacePlace);
            Assert.Equal(horse.Show, actual.RaceShow);
            Assert.Equal(horse.Starts, actual.RaceStarts);
            Assert.Equal(horse.SireId, actual.SireId);
            Assert.Equal(horse.DamId, actual.DamId);
        }
Example #2
0
        public GetAll()
        {
            _fakeRepository = new FakeHorseRepository();
            HorseFactory.Create(_fakeRepository);

            _horseService = new HorseService(_fakeRepository);
        }
Example #3
0
        public TestBase()
        {
            Repository   = new FakeRepository <Horse>();
            HorseService = new HorseService(Repository);

            Repository.DataSet.Add(new Horse());
        }
Example #4
0
        private HorseService CreateHorseService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new HorseService(userId);

            return(service);
        }
Example #5
0
        public ActionResult Index()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new HorseService(userId);
            var model   = service.GetHorses();

            return(View(model));
        }
        public void ItReturnsCollectionOfHorses()
        {
            // Arrange
            // Act
            var horses = HorseService.GetAll();

            // Assert
            Assert.IsAssignableFrom<IEnumerable<Dto.Horse>>(horses);
        }
        public void ItReturnsHorse()
        {
            // Arrange
            // Act
            var horse = HorseService.Get(_id);

            // Assert
            Assert.IsAssignableFrom <Dto.Horse>(horse);
        }
Example #8
0
 public HomeController(
     HorseService horseService,
     RaceService raceService,
     JokeyService jokeyService)
 {
     _horseService = horseService;
     _raceService  = raceService;
     _jokeyService = jokeyService;
 }
Example #9
0
        public void ItCallsRepositorySave()
        {
            // Arrange
            var service = new HorseService(_fakeRepository);

            // Act
            service.Create(new HorseCreate());

            // Assert
            Assert.True(_fakeRepository.SaveCalled);
        }
Example #10
0
        public void GivenHorseNotFoundThenNullHorse()
        {
            // Arrange
            var service = new HorseService(_fakeRepository);

            // Act
            var actualHorse = service.Get(-1);

            // Assert
            Assert.Null(actualHorse);
        }
Example #11
0
        public void ItReturnsHorseFromRepository(int id, string name)
        {
            // Arrange
            var expectedHorse = HorseFactory.Create(_fakeRepository, id, name).WithColor();
            var service       = new HorseService(_fakeRepository);

            // Act
            var actualHorse = service.Get(expectedHorse.Id);

            // Assert
            Assert.True(_fakeRepository.GetCalled);
            Assert.Equal(expectedHorse.Id, actualHorse.Id);
            Assert.Equal(expectedHorse.Name, actualHorse.Name);
        }
Example #12
0
        public async Task ShouldGetAllHorseInformationInPriceAscendingOrder()
        {
            //Arrange
            var appConfig = new AppConfig {
                JsonFilePath = "FeedData\\Wolferhampton_Race1.json", XmlFilePath = "FeedData\\Caulfield_Race1.xml"
            };
            var IOptionsMock = Options.Create(appConfig);

            var loggerMock = new Mock <ILogger <HorseService> >();

            var jsonFileParserMock = new Mock <IJsonFileParser>();

            jsonFileParserMock.Setup(service => service.ParseAsync()).ReturnsAsync(
                GetHorsesFromJsonFile()
                );

            var xmlFileParserMock = new Mock <IXmlFileParser>();

            xmlFileParserMock.Setup(service => service.ParseAsync()).ReturnsAsync(
                GetHorsesFromXmlFile()
                );

            var horseService = new HorseService(IOptionsMock, loggerMock.Object, jsonFileParserMock.Object, xmlFileParserMock.Object);
            //Act
            var horses = await horseService.GetHorsesWithPrice();

            Horse horse1 = horses.First();
            Horse horse2 = horses.Skip(1).First();
            Horse horse3 = horses.Skip(2).First();
            Horse horse4 = horses.Skip(3).First();

            //Assert
            Assert.True(horses.Count() == 4);
            Assert.True(horse1.Name == "Advancing" &&
                        horse1.Price == 4.2m);

            Assert.True(horse2.Name == "Fikhaar" &&
                        horse2.Price == 4.4m);

            Assert.True(horse3.Name == "Toolatetodelegate" &&
                        horse3.Price == 10m);

            Assert.True(horse4.Name == "Coronel" &&
                        horse4.Price == 12m);
        }
Example #13
0
        public void GetHorsesByWeight()
        {
            //initiallizing
            var horse           = new Horse();
            var unitOfWork      = new Mock <IUnitOfWork>();
            var finder          = new Mock <IHorseFinder>();
            var horseCollection = new Mock <IRepository <Horse> >();

            var service = new HorseService(unitOfWork.Object, finder.Object, horseCollection.Object);

            //act
            finder.Setup(x => x.FindHorsesByWeight(horse.Weight))
            .Returns(new List <Horse>());

            service.GetHorsesByWeight(horse.Weight);

            //assert
            finder.Verify(x => x.FindHorsesByWeight(It.IsAny <float>()));
        }
Example #14
0
        public void DeleteHorse()
        {
            //initiallizing
            var horse           = new Horse();
            var unitOfWork      = new Mock <IUnitOfWork>();
            var finder          = new Mock <IHorseFinder>();
            var horseCollection = new Mock <IRepository <Horse> >();

            var service = new HorseService(unitOfWork.Object, finder.Object, horseCollection.Object);

            //act
            horseCollection.Setup(x => x.Delete(horse))
            .Returns(horse);

            service.DeleteHorse(horse);

            //assert
            horseCollection.Verify(x => x.Delete(It.IsAny <Horse>()), Times.Once);
        }
Example #15
0
        public void GetAllHorses_ReturnsHorsesSortedByPriceAsc()
        {
            _mockCaulfieldRepository.GetMeeting().Returns(GetMockMeeting());
            _mockWolferhamptonRepository.GetFixture().Returns(GetMockFixture());

            var horseService = new HorseService(
                _mockCaulfieldRepository,
                _mockWolferhamptonRepository,
                Substitute.For <ILogger>()
                );

            var horses = horseService.GetAllHorses();

            Assert.True(horses[0].Name == "Caulfield Horse 2");
            Assert.True(horses[1].Name == "Wolferhampton Horse 2");
            Assert.True(horses[2].Name == "Wolferhampton Horse 1");
            Assert.True(horses[3].Name == "Caulfield Horse 1");
            Assert.True(horses[4].Name == "Wolferhampton Horse 3");
        }
Example #16
0
        static void Main(string[] args)
        {
            var horseViewModelList = new List <HorseViewModel>();
            var filePath           = Path.Combine(Environment.CurrentDirectory, "FeedData");

            string[] files = Directory.GetFiles(filePath);
            foreach (var fileName in files)
            {
                IFileReader fileReader   = ReaderFactory.CreateFileReader(fileName);
                var         horseService = new HorseService(fileReader);
                var         result       = horseService.GetHorseNameViewModels(fileName);
                horseViewModelList.AddRange(result.HorseViewModels);
            }

            foreach (var horse in horseViewModelList.OrderBy(x => x.Price))
            {
                Console.WriteLine($"Horse Name : {horse.Name}");
            }
            Console.ReadLine();
        }
 public HorsesController(HorseService horseService)
 {
     _horseService = horseService;
 }