Exemplo n.º 1
0
        public async Task Add_Correct_Character_To_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()
            };

            // Act
            var result = await controller.AddNewCharacterAsync(cmd);

            // Assert
            var response = AssertResponse(result);
            Assert.IsTrue(response.IsOk);
        }
Exemplo n.º 2
0
        public async Task send_invalid_command_to_create_character(Guid id, string name, string @class, string faction, int level, string race)
        {
            // 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 = id,
                Name = name,
                Class = @class,
                Faction = faction,
                Level = level,
                Race = race
            };

            // Act
            var result = await controller.AddNewCharacterAsync(cmd);

            // Assert
            var response = AssertResponse(result);
            Assert.IsFalse(response.IsOk);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public async Task<ActionResult> AddNewCharacterAsync(CreateCharacterCmd cmd)
        {
            var cmdValidation = new CommandValidation();

            Domain.Model.Faction faction = null;
            Domain.Model.Race race = null;
            Domain.Model.Class @class = null;

            cmdValidation.validate(() => cmd.Id == Guid.Empty, "id cannot be empty");
            cmdValidation.validate(() => string.IsNullOrEmpty(cmd.Name), "name cannot be empty");
            cmdValidation.validate(() => !Domain.Model.ClassFactory.TryParse(cmd.Class, out @class), "class is not known");
            cmdValidation.validate(() => !Domain.Model.FactionFactory.TryParse(cmd.Faction, out faction), "faction is not known");
            cmdValidation.validate(() => !Domain.Model.RaceFactory.TryParse(cmd.Race, out race), "race is not known");
            //cmdValidation.validate(() => cmd.Level<1 || cmd.Level>100, "level is not available"); not in the rules.. :)

            if (!cmdValidation.IsValid())
                //todo give back some 4/5xx love?
                return Json(cmdValidation.ToResponse());
            else
            {
                var currentUser = _serviceUser.getCurrentUser();
                var result = await _serviceAccount.CreateCharacterAsync(currentUser.Id, cmd.Id, cmd.Name, cmd.Level, race, faction, @class);
                var executionResult = new ExecutionValidation(result );
                //todo give back some 4/5xx love if it failed?
                return Json(executionResult.ToResponse());
            }
                
        }