public async Task FindAsync_Returns_results() { // arrange var boardGamesList = new BoardGameListDto() { BoardGames = DataProvider.GetBoardGameResults() }; var apiProviderMock = new Mock <IApiProvider>(MockBehavior.Strict); apiProviderMock .Setup(x => x.BuildUri(ApiEndPoint.BoardGame, "100", It.IsAny <NameValueCollection>())) .Returns(new Uri("http://fake/url")); apiProviderMock .Setup(x => x.CallWebServiceGetAsync <BoardGameListDto>(It.IsAny <Uri>())) .ReturnsAsync(boardGamesList); apiProviderMock .Setup(x => x.GetQueryPropertyName <BoardGameQueryParameters>("Comments")) .Returns("comments"); var modelFactory = new ModelFactory(); var service = BoardGameService.Create(apiProviderMock.Object, modelFactory); service.Where(x => x.Comments, true); // act var result = await service.FindAsync(new[] { "100" }); // assert Assert.True(result.IsSuccess); Assert.Equal(boardGamesList.BoardGames.Count, result.Value.Count); }
public ActionResult Edit(int gameId) { BoardGameService boardGameService = GetService(); BoardGame boardGame = boardGameService.GetFromDb(gameId); return(View(boardGame)); }
}//end of method Post //now we need a get method to get all public IHttpActionResult Get() { BoardGameService service = new BoardGameService(); var boardGames = service.GetBoardGames(); return(Ok(boardGames)); }//end of method get to get all
}//end of method get to get all //get by id method public IHttpActionResult Get(int id) { BoardGameService service = new BoardGameService(); var boardGame = service.GetBoardGameById(id); return(Ok(boardGame)); }//end of method get by id
// GET: BoardGame public ActionResult Index(int gameId) { BoardGameService boardGameService = new BoardGameService(ConfigData.Instance.BoardGamesConnectionString, Source.Application); BoardGame boardGame = boardGameService.GetFromDb(gameId); return(RedirectToAction("Details", new { gameId })); }
public BoardGame GetGameDetails(int id) { BoardGameService boardGameService = new BoardGameService(ConfigData.Instance.BoardGamesConnectionString, Source.Rest); BoardGame boardGame = boardGameService.GetFromDb(id); return(boardGame); }
public void Create_Not_Null() { // arrange, act var service = BoardGameService.Create(); // assert Assert.NotNull(service); }
public void GetBoardGame() { //Arrange _boardGameRepositoryMock.Setup(mock => mock.Get(It.IsAny<int>())); var boardGameService = new BoardGameService(_boardGameRepositoryMock.Object); //Act boardGameService.Get(_testBoardGame.Id); //Assert _boardGameRepositoryMock.Verify(mock => mock.Get(_testBoardGame.Id), Times.Once()); }
public ActionResult Edit(BoardGame boardGame) { if (ModelState.IsValid) { BoardGameService boardGameService = GetService(); boardGameService.UpdateEntity(boardGame); return(RedirectToAction("Index", "BoardGameLite")); } return(View()); }
public ActionResult Details(int gameId) { BoardGameService boardGameService = new BoardGameService(ConfigData.Instance.BoardGamesConnectionString, Source.Application); BoardGame boardGame = boardGameService.GetFromDb(gameId); LogService logService = new LogService(ConfigData.Instance.BoardGamesConnectionString, Source.Application); ViewBag.Logs = logService.GetEntityLogs(gameId, 10); return(View(boardGame)); }
public void AddBoardGameToBoardGamesList() { //Arrange _boardGameRepositoryMock.Setup(mock => mock.Add(It.IsAny<BoardGame>())); var boardGameService = new BoardGameService(_boardGameRepositoryMock.Object); //Act boardGameService.Add(_testBoardGame); //Assert _boardGameRepositoryMock.Verify(mock => mock.Add(It.Is<BoardGame>(i => i.Equals(_testBoardGame))), Times.Once); }
public void DeactivateBoardGame() { //Arrange _boardGameRepositoryMock.Setup(mock => mock.Deactivate(It.IsAny<int>())); var boardGameService = new BoardGameService(_boardGameRepositoryMock.Object); //Act boardGameService.DeactivateBoardGame(_testBoardGame.Id); //Assert _boardGameRepositoryMock.Verify(mock => mock.Deactivate(It.Is<int>(x => x.Equals(_testBoardGame.Id))), Times.Once()); }
public void Where_Null_Property_Throws() { // arrange var apiProviderMock = new Mock <IApiProvider>(MockBehavior.Strict); var modelFactory = new Mock <IModelFactory>(MockBehavior.Strict); var service = BoardGameService.Create(apiProviderMock.Object, modelFactory.Object); // act, assert var result = Assert.Throws <ArgumentNullException>(() => service.Where(null, "value1")); Assert.Equal("property", result.ParamName); }
public void EditBoardGame() { //Arrange _boardGameRepositoryMock.Setup(mock => mock.Edit(It.IsAny<BoardGame>())); var boardGameService = new BoardGameService(_boardGameRepositoryMock.Object); //Act boardGameService.Edit(_testBoardGame); //Assert _boardGameRepositoryMock.Verify(mock => mock.Edit(It.Is<BoardGame>(x => x.Equals(_testBoardGame))), Times.Once()); }
}//end of method put to change existing boardGame //finally the delete by id method public IHttpActionResult Delete(int id) { var service = new BoardGameService(); if (!service.DeleteBoardGame(id)) { return(InternalServerError()); }//end of if not able to delete //once again, we get here... return(Ok()); } //end of method delete by id
public void GetBoardGameList() { //Arrange _boardGameRepositoryMock.Setup(mock => mock.GetAll()).Returns(new List<BoardGame> {new BoardGame()}); var boardGameService = new BoardGameService(_boardGameRepositoryMock.Object); //Act var boardGames = boardGameService.GetAll(); //Assert Assert.AreEqual(1, boardGames.Count()); _boardGameRepositoryMock.Verify(mock => mock.GetAll(), Times.Once()); }
public ActionResult Create(BoardGame boardGame) { if (ModelState.IsValid) { if (boardGame.MinPlayersNumber < 1 || boardGame.MaxPlayersNumber < 1 || boardGame.MaxPlayersNumber < boardGame.MinPlayersNumber) { TempData["InvalidDataMessage"] = "Number of players is invalid"; return(View()); } BoardGameService boardGameService = GetService(); boardGameService.InsertEntityToDb(boardGame); return(RedirectToAction("Index", "BoardGameLite")); } return(View()); }
}//end of method get by id //edit existing boardGaem in database public IHttpActionResult Put(BoardGameEdit boardGame) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); }//end of if model is not valid var service = new BoardGameService(); if (!service.UpdateBoardGame(boardGame)) { return(InternalServerError()); }//end of if unable to update the boardGame //if we get here... good! return(Ok()); }//end of method put to change existing boardGame
public void Where_Adds_Parameter() { // arrange var apiProviderMock = new Mock <IApiProvider>(MockBehavior.Strict); apiProviderMock .Setup(x => x.GetQueryPropertyName <BoardGameQueryParameters>(It.IsAny <string>())) .Returns("comments"); var modelFactory = new Mock <IModelFactory>(MockBehavior.Strict); var service = BoardGameService.Create(apiProviderMock.Object, modelFactory.Object); // act var result = service.Where(x => x.Comments, true); Assert.NotNull(result); Assert.Equal(service, result); }
public async Task FindAsync_Failure() { // arrange var apiProviderMock = new Mock <IApiProvider>(MockBehavior.Strict); apiProviderMock .Setup(x => x.BuildUri(ApiEndPoint.Search, It.IsAny <NameValueCollection>())) .Throws(new Exception("my error")); var modelFactory = new Mock <IModelFactory>(MockBehavior.Strict); var service = BoardGameService.Create(apiProviderMock.Object, modelFactory.Object); // act var result = await service.FindAsync(new[] { "5", "10" }); // assert Assert.False(result.IsSuccess); }
//build out our crud //start with create public IHttpActionResult Post(BoardGameCreate boardGame) { //start by checking validity of the model state if (!ModelState.IsValid) { return(BadRequest(ModelState)); }//end of if model is not valid //create a service instance var service = new BoardGameService(); //now that the service exists, return an error if we can't create the boardGame if (!service.CreateBoardGame(boardGame)) { return(InternalServerError()); }//end of if doesnt save //to get here it had to work soo return(Ok()); }//end of method Post
public BoardGamesController(BoardGameService service) { _boardGameService = service; _boardGameService.Initialize(); }
public BoardGameAppService(BoardGameService boardGameService) { _boardGameService = boardGameService; BoardGames = new ObservableCollection <BoardGame>(); }