public async Task <ChallengePermissionResponse> Handle(ChallengePermissionQuery message) { var challenegModel = await Get(message.Id); int balance; var isValidInput = !(string.IsNullOrEmpty(message.Balance) || string.IsNullOrEmpty(message.ChallengeElement1) || string.IsNullOrEmpty(message.ChallengeElement2) || !int.TryParse(message.Balance.Split('.')[0].Replace("£", string.Empty), out balance) || message.ChallengeElement1.Length != 1 || message.ChallengeElement2.Length != 1 ); var response = new ChallengePermissionResponse { Id = message.Id, Url = message.Url, IsValid = false }; if (challenegModel.StatusCode == SearchResponseCodes.Success) { if (isValidInput) { response.IsValid = await _challengeRepository.CheckData(challenegModel.Account, message); } response.Characters = challenegModel.Characters; } return(response); }
public async Task ItShouldReturnChallengeValidationJsonResultWhenTheChallengeEntryIsValid() { var challengeEntry = new ChallengeEntry { Id = "123", Balance = "£1000", Challenge1 = "1", Challenge2 = "A", FirstCharacterPosition = 1, SecondCharacterPosition = 4, Url = "https://tempuri.org/challenge/me/to/a/deul/any/time" }; var query = new ChallengePermissionQuery { Id = "123", Balance = "£1000", ChallengeElement1 = "1", ChallengeElement2 = "B", FirstCharacterPosition = 1, SecondCharacterPosition = 4, Url = "https://tempuri.org/challenge/me/to/a/deul/any/time" }; var response = new ChallengePermissionResponse { Id = challengeEntry.Id, Url = challengeEntry.Url, IsValid = true }; MockChallengeHandler.Setup(x => x.Handle(It.IsAny <ChallengePermissionQuery>())) .ReturnsAsync(response); var actual = await Unit.Index(challengeEntry.Id, challengeEntry); Assert.IsNotNull(actual); Assert.IsInstanceOf <JsonResult>(actual); var result = ((JsonResult)actual).Data as ChallengeValidationResult; Assert.IsNotNull(result); Assert.IsTrue(result.IsValidResponse); }
public async Task ItShouldReturnAViewModelWhenTheChallengeEntryIsInvalid() { var challengeEntry = new ChallengeEntry { Id = "123", Balance = "£1000", Challenge1 = "1", Challenge2 = "A", FirstCharacterPosition = 0, SecondCharacterPosition = 1, Url = "https://tempuri.org/challenge/me/to/a/deul/any/time" }; var query = new ChallengePermissionQuery { Id = "123", Balance = "£1000", ChallengeElement1 = "1", ChallengeElement2 = "A", FirstCharacterPosition = 1, SecondCharacterPosition = 2, Url = "https://tempuri.org/challenge/me/to/a/deul/any/time" }; var response = new ChallengePermissionResponse { Id = challengeEntry.Id, Url = challengeEntry.Url, IsValid = false }; MockChallengeHandler.Setup(x => x.Handle(It.IsAny <ChallengePermissionQuery>())) .ReturnsAsync(response); var actual = await Unit.Index(challengeEntry.Id, challengeEntry); Assert.IsNotNull(actual); Assert.IsInstanceOf <ViewResult>(actual); Assert.IsInstanceOf <ChallengeViewModel>(((ViewResult)actual).Model); Assert.AreEqual(true, ((ChallengeViewModel)((ViewResult)actual).Model).HasError); }