public void CanPushDataToActualMongoDb() { var characterRepository = new MongoDbRepository <ICharacter>(MongoDatabase); var movementRepository = new MongoDbRepository <IMovement>(MongoDatabase); var moveRepository = new MongoDbRepository <IMove>(MongoDatabase); var characterAttributeRepository = new MongoDbRepository <ICharacterAttributeRow>(MongoDatabase); var uniqueDataRepository = new MongoDbRepository <IUniqueData>(MongoDatabase); //real api services using mocked repos var mockQueryMappingService = new Mock <IQueryMappingService>().Object; var dtoProvider = new DefaultDtoProvider(); var movementService = new DefaultMovementService(movementRepository, mockQueryMappingService); var moveService = new DefaultMoveService(moveRepository, mockQueryMappingService); var characterAttributeService = new DefaultCharacterAttributeService(characterAttributeRepository, new Mock <ICharacterAttributeNameProvider>().Object); var uniqueDataService = new DefaultUniqueDataService(uniqueDataRepository, mockQueryMappingService); var characterService = new DefaultCharacterService(characterRepository, dtoProvider, movementService, characterAttributeService, moveService, uniqueDataService, string.Empty); //real scraping from web to get data var captainFalcon = Characters.CaptainFalcon; _characterDataScraper.PopulateCharacterFromWeb(captainFalcon); int previousCount = characterRepository.GetAll().Count(); //insert data into mock repos using api services var seeder = new DefaultSeeder(_characterDataScraper); seeder.SeedCharacterData(captainFalcon, characterService, movementService, moveService, characterAttributeService, uniqueDataService); //assert data can be retrieved Assert.That(characterRepository.GetAll().Count(), Is.EqualTo(previousCount + 1)); Assert.That(moveRepository.GetAll().Count(), Is.GreaterThan(0)); Assert.That(movementRepository.GetAll().Count(), Is.GreaterThan(0)); Assert.That(characterAttributeRepository.GetAll().Count(), Is.GreaterThan(0)); //Assert.That(uniqueDataRepository.GetAll().Count(), Is.GreaterThan(0)); //no unique data for this character }
public void CanSeedCharacterData() { //fake data stores var characters = new List <ICharacter>(); var movements = new List <IMovement>(); var moves = new List <IMove>(); var characterAttributes = new List <ICharacterAttributeRow>(); var uniqueDataProperties = new List <IUniqueData>(); //mock repos var characterRepositoryMock = new Mock <IRepository <ICharacter> >(); characterRepositoryMock.Setup(c => c.Add(It.IsAny <ICharacter>())).Callback <ICharacter>(c => { characters.Add(c); }); characterRepositoryMock.Setup(c => c.GetAll()).Returns(() => characters); var movementRepositoryMock = new Mock <IRepository <IMovement> >(); movementRepositoryMock.Setup(c => c.AddMany(It.IsAny <IEnumerable <IMovement> >())) .Callback <IEnumerable <IMovement> >(c => { movements.AddRange(c); }); movementRepositoryMock.Setup(c => c.GetAll()).Returns(() => movements); var movesRepositoryMock = new Mock <IRepository <IMove> >(); movesRepositoryMock.Setup(c => c.AddMany(It.IsAny <IEnumerable <IMove> >())) .Callback <IEnumerable <IMove> >(c => { moves.AddRange(c); }); movesRepositoryMock.Setup(c => c.GetAll()).Returns(() => moves); var characterAttributeRepositoryMock = new Mock <IRepository <ICharacterAttributeRow> >(); characterAttributeRepositoryMock.Setup(c => c.AddMany(It.IsAny <IEnumerable <ICharacterAttributeRow> >())) .Callback <IEnumerable <ICharacterAttributeRow> >(c => { characterAttributes.AddRange(c); }); characterAttributeRepositoryMock.Setup(c => c.GetAll()).Returns(() => characterAttributes); var uniqueDataRepositoryMock = new Mock <IRepository <IUniqueData> >(); uniqueDataRepositoryMock.Setup(u => u.AddMany(It.IsAny <IEnumerable <IUniqueData> >())) .Callback <IEnumerable <IUniqueData> >(u => { uniqueDataProperties.AddRange(u); }); uniqueDataRepositoryMock.Setup(u => u.GetAll()).Returns(() => uniqueDataProperties); //real api services using mocked repos var movementService = new DefaultMovementService(movementRepositoryMock.Object, new Mock <IQueryMappingService>().Object); var moveService = new DefaultMoveService(movesRepositoryMock.Object, new Mock <IQueryMappingService>().Object); var characterAttributeService = new DefaultCharacterAttributeService(characterAttributeRepositoryMock.Object, new Mock <ICharacterAttributeNameProvider>().Object); var uniqueDataService = new DefaultUniqueDataService(uniqueDataRepositoryMock.Object, new Mock <IQueryMappingService>().Object); var dtoProvider = new DefaultDtoProvider(); var characterService = new DefaultCharacterService(characterRepositoryMock.Object, dtoProvider, movementService, characterAttributeService, moveService, uniqueDataService, string.Empty); //real scraping from web to get data var cloud = Characters.Cloud; _characterDataScraper.PopulateCharacterFromWeb(cloud); //insert data into mock repos using api services var seeder = new DefaultSeeder(_characterDataScraper); seeder.SeedCharacterData(cloud, characterService, movementService, moveService, characterAttributeService, uniqueDataService); //assert data can be retrieved Assert.That(characterRepositoryMock.Object.GetAll().Count(), Is.EqualTo(1)); Assert.That(movesRepositoryMock.Object.GetAll().Count(), Is.GreaterThan(0)); Assert.That(movementRepositoryMock.Object.GetAll().Count(), Is.GreaterThan(0)); Assert.That(characterAttributeRepositoryMock.Object.GetAll().Count(), Is.GreaterThan(0)); Assert.That(uniqueDataRepositoryMock.Object.GetAll().Count(), Is.GreaterThan(0)); }