public PlatformTypeServiceTest() { _uow = new Mock <IUnitOfWork>(); var log = new Mock <ILog>(); _mapper = MapperConfigUi.GetMapper().CreateMapper(); _sut = new PlatformTypeService(_uow.Object, _mapper, log.Object); _fakePlatformTypeId = Guid.NewGuid(); _fakePlatformTypeName = "PlatformType1"; _fakePlatformType = new PlatformType { Id = _fakePlatformTypeId, NameEn = _fakePlatformTypeName }; _fakePlatformTypes = new List <PlatformType>() { _fakePlatformType, new PlatformType() { Id = new Guid() } }; }
public void Setup() { mockPlatformTypeRepo = new Mock <IPlatformTypeRepository>(); mockPlatformTypeService = new Mock <IPlatformTypeService>(); fixture = new Fixture(); fixture.Behaviors.OfType <ThrowingRecursionBehavior>().ToList() .ForEach(b => fixture.Behaviors.Remove(b)); fixture.Behaviors.Add(new OmitOnRecursionBehavior()); platformTypeService = new PlatformTypeService(mockPlatformTypeRepo.Object); }
public void Check_That_Platform_Type_Service_Gets_All_Platform_Types() { //Arrange var testList = new List <PlatformType> { new PlatformType(), new PlatformType(), }; var mock = new Mock <IUnitOfWork>(); mock.Setup(m => m.PlatformTypeRepository.GetAll()) .Returns(testList); var platformTypeService = new PlatformTypeService(mock.Object); //Act IEnumerable <PlatformTypeModel> platformTypes = platformTypeService.GetAll(); //Assert Assert.IsTrue(testList.Count == platformTypes.Count()); }
public void TestInitializer() { #region initialization entities platformTypes = new[] { new PlatformType { Id = 1, Type = "Type1" }, new PlatformType { Id = 2, Type = "Type2" }, new PlatformType { Id = 3, Type = "Type3" }, new PlatformType { Id = 4, Type = "Type4" } }; games = new[] { new Game { Id = 1, Name = "Game1", Description = "Description1", Key = "game_1", PlatformTypes = new[] { platformTypes[0], platformTypes[1] } }, new Game { Id = 2, Name = "Game2", Description = "Description2", Key = "game_2", PlatformTypes = new[] { platformTypes[2] } }, new Game { Id = 3, Name = "Game3", Description = "Description3", Key = "game_3", PlatformTypes = new[] { platformTypes[3] } } }; #endregion #region initialization repositories, unit of work, logger, validation factory and game service _gameRepositoryMock = new Mock <IGameRepository>(); _gameRepositoryMock.Setup(_ => _.Get()).Returns(games); _gameRepositoryMock.Setup(_ => _.Get(It.IsAny <int>())) .Returns((int id) => games.FirstOrDefault(_ => _.Id == id)); _gameRepositoryMock.Setup(_ => _.Find(It.IsAny <Func <Game, bool> >())) .Returns((Func <Game, bool> predicate) => games.Where(predicate)); _platformTypeRepositoryMock = new Mock <IPlatformTypeRepository>(); _platformTypeRepositoryMock.Setup(_ => _.Get()).Returns(platformTypes); _platformTypeRepositoryMock.Setup(_ => _.Get(It.IsAny <int>())) .Returns((int id) => platformTypes.FirstOrDefault(_ => _.Id == id)); _platformTypeRepositoryMock.Setup(_ => _.Find(It.IsAny <Func <PlatformType, bool> >())) .Returns((Func <PlatformType, bool> predicate) => platformTypes.Where(predicate)); _unitOfWorkMock = new Mock <IUnitOfWork>(); _unitOfWorkMock.Setup(_ => _.GetGames()).Returns(_gameRepositoryMock.Object); _unitOfWorkMock.Setup(_ => _.GetPlatformTypes()).Returns(_platformTypeRepositoryMock.Object); _validationFactoryMock = new Mock <IValidatorFactory>(); _validationFactoryMock.Setup(_ => _.GetValidator <CreateUpdateGameInput>()) .Returns(new CreateUpdateGameInputValidator()); _validationFactoryMock.Setup(_ => _.GetValidator <GetDeleteGameInput>()) .Returns(new GetDeleteGameInputValidator(_unitOfWorkMock.Object)); _validationFactoryMock.Setup(_ => _.GetValidator <CreateUpdatePlatformTypeInput>()) .Returns(new CreateUpdatePlatformTypeInputValidator(_unitOfWorkMock.Object)); _validationFactoryMock.Setup(_ => _.GetValidator <GetDeletePlatformTypeInput>()) .Returns(new GetDeletePlatformTypeInputValidator(_unitOfWorkMock.Object)); _loggerMock = new Mock <ILogger>(); _platformTypeService = new PlatformTypeService( _unitOfWorkMock.Object, _validationFactoryMock.Object, _loggerMock.Object); #endregion }