public async Task ItShouldReturnTheChallengeViewWithAModelWhenThereIsAMatch() { var challengeResponse = new ChallengeResponse { Account = new Core.Models.Account { AccountId = 123, HashedAccountId = "ERERER", DasAccountName = "Test Account" }, StatusCode = SearchResponseCodes.Success }; var id = "123"; MockChallengeHandler.Setup(x => x.Get(id)) .ReturnsAsync(challengeResponse); var actual = await Unit.Index(id); Assert.IsInstanceOf <ViewResult>(actual); var viewResult = (ViewResult)actual; Assert.IsInstanceOf <ChallengeViewModel>(viewResult.Model); }
public async Task ItShouldReturnHttpNoFoundWhenTheSearchFails() { var challengeResponse = new ChallengeResponse { Account = null, StatusCode = SearchResponseCodes.SearchFailed }; var id = "123"; MockChallengeHandler.Setup(x => x.Get(id)) .ReturnsAsync(challengeResponse); var actual = await Unit.Index(id); Assert.IsInstanceOf <HttpNotFoundResult>(actual); }
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); }