public async Task retrieve_empty_guid_character_from_account() { // Arrange var wowId = Guid.NewGuid(); var wowId2 = Guid.NewGuid(); IRepoAccount repoAccount = createFakeRepoAccount(wowId, wowId2); IRepoUser repoUser = createFakeRepoUser(wowId, wowId2); User mutableAccount = null; Action<User> saveUserToSession = (account) => mutableAccount = account; Func<User> getFromSession = () => mutableAccount; IServiceUser serviceUser = new ServiceUser(repoUser, saveUserToSession, getFromSession); IServiceAccount serviceAccount = new ServiceAccount(repoAccount); serviceUser.authenticate("wow", "wow"); AccountController controller = new AccountController(serviceUser, serviceAccount); var cmd = new CreateCharacterCmd() { Id = Guid.NewGuid(), Name = "Orgrim Doomhammer", Class = ClassFactory.Warrior.ToString(), Faction = FactionFactory.Horde.ToString(), Level = 100, Race = RaceFactory.Orc.ToString() }; await controller.AddNewCharacterAsync(cmd); var currentUser = serviceUser.getCurrentUser(); var characters = await serviceAccount.GetCharactersAsync(currentUser.Id); await controller.RemoveCharacterAsync(new RemoveCharacterCmd() { Id = characters.ElementAt(0).Id }); var retrieveCmd = new RetrieveCharacterCmd() { Id = Guid.Empty }; // Act var result = await controller.RetrieveCharacterAsync(retrieveCmd); // Assert var response = AssertResponse(result); Assert.IsFalse(response.IsOk); }
public async Task<ActionResult> RetrieveCharacterAsync(RetrieveCharacterCmd cmd) { var cmdValidation = new CommandValidation(); cmdValidation.validate(() => cmd.Id == Guid.Empty, "idCharacter cannot be empty"); if (!cmdValidation.IsValid()) //todo give back some 4/5xx love? return Json( cmdValidation.ToResponse()); else { var currentUser = _serviceUser.getCurrentUser(); var result = await _serviceAccount.RetrieveCharacterAsync(currentUser.Id, cmd.Id); var executionResult = new ExecutionValidation(result); //todo give back some 4/5xx love if it failed? return Json( executionResult.ToResponse()); } }