public void RankingHandler_WithoutToken_Error() { //Arrange var command = new CompetionRankingCommand(2021, "teste", ""); //Act var result = _handlerTest.GetRanking(command); //Assert Assert.IsTrue(result.IsError); Assert.IsFalse(result.IsSuccess); }
public void CreateCommand_WithoutAll_Invalid() { //Arrage //var competitionId = 2021; // var url = "footballUrl"; // var token = "token-football"; _commandTest = new CompetionRankingCommand(0, "", ""); //Act var invalid = _commandTest.Invalid(); //Assert Assert.IsTrue(invalid); }
public void CreateCommand_Valid() { //Arrage var competitionId = 2021; var url = "footballUrl"; var token = "token-football"; _commandTest = new CompetionRankingCommand(competitionId, url, token); //Act var invalid = _commandTest.Invalid(); //Assert Assert.IsFalse(invalid); }
public void RankingHandler_CreateCorrectUrl_Success() { //Arrange MockCorrectResponse(); var command = new CompetionRankingCommand(competitionId, url, "teste"); //Act var result = _handlerTest.GetRanking(command); //Assert var correctUrl = string.Format(url, competitionId); _webRequestFactory.Verify(s => s.Create(correctUrl)); }
public void RankingHandler_CreateStreamException_Error() { //Arrange MockCorrectResponse(); _streamFactory.Setup(s => s.Create(It.IsAny <Stream>())).Throws(new Exception()); var mockToken = "teste"; var command = new CompetionRankingCommand(competitionId, url, mockToken); //Act var result = _handlerTest.GetRanking(command); //Assert Assert.IsTrue(result.IsError); }
public void RankingHandler_GetResponseException_Error() { //Arrange MockCorrectResponse(); _webRequest.Setup(s => s.GetResponse()).Throws(new WebException()); var mockToken = "teste"; var command = new CompetionRankingCommand(competitionId, url, mockToken); //Act var result = _handlerTest.GetRanking(command); //Assert Assert.IsTrue(result.IsError); }
public void RankingHandler_CreateHeaderToken_Success() { //Arrange MockCorrectResponse(); var mockToken = "teste"; var command = new CompetionRankingCommand(competitionId, url, mockToken); //Act var result = _handlerTest.GetRanking(command); //Assert var token = _webRequest.Object.Headers["X-Auth-Token"]; Assert.IsNotNull(token); Assert.AreEqual(token, mockToken); }
public void RankingHandler_CantDeserialize_Error() { //Arrange MockCorrectResponse(); _deserealize.Setup(s => s.Deserialize(It.IsAny <string>())) .Throws(new Exception()); var mockToken = "teste"; var command = new CompetionRankingCommand(competitionId, url, mockToken); //Act var result = _handlerTest.GetRanking(command); //Assert Assert.IsTrue(result.IsError); }
public void RankingHandler_CompetitionNotFound_Error() { //Arrange MockCorrectResponse(); _deserealize.Setup(s => s.Deserialize(It.IsAny <string>())) .Returns((Ranking)null); var mockToken = "teste"; var command = new CompetionRankingCommand(competitionId, url, mockToken); //Act var result = _handlerTest.GetRanking(command); //Assert Assert.IsTrue(result.IsError); Assert.AreEqual(result.Error.Msg, "Competição não encontrada"); }
public void RankingHandler_ReturnRanking_Success() { //Arrange MockCorrectResponse(); var mockToken = "teste"; var command = new CompetionRankingCommand(competitionId, url, mockToken); var ranking = new Ranking(); _deserealize.Setup(s => s.Deserialize(It.IsAny <string>())).Returns(ranking); //Act var result = _handlerTest.GetRanking(command); //Assert Assert.IsTrue(result.IsSuccess); Assert.AreEqual(ranking, result.Success); }
public Result <Ranking> GetRanking(CompetionRankingCommand command) { try { if (command.Invalid()) { return("Parâmetros inválidos"); } var request = _webRequestFactory.Create(string.Format(command.FootballURL, command.CompetitionId)); request.Method = "GET"; request.Headers.Add("X-Auth-Token", command.Token); using (var response = request.GetResponse()) using (var streamReader = _streamFactory.Create(response.GetResponseStream())) { var result = _deserealize.Deserialize(streamReader.ReadToEnd()); if (result == null) { return("Competição não encontrada"); } return(result); } } catch (WebException ex) { if (ex.Response == null) { return(ex.Message); } using (var stream = ex.Response.GetResponseStream()) using (var reader = new StreamReader(stream)) return(reader.ReadToEnd()); } catch (Exception e) { return(e.Message); } }