public void ThrowsArgumentExceptionWhereCharacterNameParameterEmptyForGetAllThrows()
        {
            var sut = new DefaultMoveService(new Mock <IRepository <IMove> >().Object, new GameParameterParserService("Smash4"));

            Assert.Throws <ArgumentNullException>(() =>
            {
                sut.GetAllThrowsWhereCharacterNameIs(string.Empty);
            });
        }
        public void VerifyGetAllThrowsForCharacterCallsGetAllWhere()
        {
            var items = new List <Move>
            {
                new Move {
                    Name = "test", Owner = "testowner"
                }
            };

            var mockRepository = new Mock <IRepository <IMove> >();

            ConfigureGetAllWhereOnMockRepository(mockRepository, items);

            var sut = new DefaultMoveService(mockRepository.Object, new GameParameterParserService("Smash4"));

            sut.GetAllThrowsWhereCharacterNameIs("dummyValue");

            mockRepository.VerifyAll();
        }
        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 GetThrowsForCharacterGetsOnlyThrowMovesForThatCharacter()
        {
            const string expectedCharacterName = "mario";
            const string throwName             = "throw";
            const string grabName = "grab";
            var          items    = new List <Move>
            {
                new Move {
                    Name = "fthrow", MoveType = MoveType.Throw.GetEnumDescription(), Owner = expectedCharacterName
                },
                new Move {
                    Name = "dash grab", MoveType = MoveType.Throw.GetEnumDescription(), Owner = "ganondorf"
                },
                new Move {
                    Name = "nair", MoveType = MoveType.Aerial.GetEnumDescription(), Owner = expectedCharacterName
                }
            };

            var mockRepository = new Mock <IRepository <IMove> >();

            ConfigureGetAllWhereOnMockRepository(mockRepository, items);

            var sut = new DefaultMoveService(mockRepository.Object, new GameParameterParserService("Smash4"));

            var results = sut.GetAllThrowsWhereCharacterNameIs(expectedCharacterName).ToList();

            Assert.That(results.Count, Is.EqualTo(1), $"{nameof(results.Count)}");

            results.ForEach(result =>
            {
                Assert.That(result.Owner, Is.EqualTo(expectedCharacterName), $"{result.Owner}");
                Assert.That(result.MoveType, Is.EqualTo(MoveType.Throw.GetEnumDescription()),
                            $"{nameof(result.MoveType)}");
                Assert.That(result.Name.Contains(throwName) || result.Name.Contains(grabName),
                            $"expecting name '{result.Name} to contain {throwName} or '{grabName}'");
            });
        }
        public void ReturnsEmptyEnumerableForNoThrowMovesForValidCharacter()
        {
            const string expectedCharacterName = "testCharacter";

            var items = new List <Move>
            {
                new Move {
                    Name = "test", Owner = expectedCharacterName, MoveType = MoveType.Aerial.GetEnumDescription()
                }
            };

            var mockRepository = new Mock <IRepository <IMove> >();

            ConfigureGetAllWhereOnMockRepository(mockRepository, items);

            var sut = new DefaultMoveService(mockRepository.Object, new GameParameterParserService("Smash4"));

            var results = sut.GetAllThrowsWhereCharacterNameIs(expectedCharacterName);

            // ReSharper disable once PossibleMultipleEnumeration
            Assert.That(results, Is.Not.Null, "should not be null.");
            // ReSharper disable once PossibleMultipleEnumeration
            Assert.That(results, Is.Empty, "should be empty.");
        }
Пример #6
0
        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));
        }