Ejemplo n.º 1
0
        public async void AddTempHP_InvalidCharacter_FailingTest()
        {
            CharacterHealthService characterHealthService = InitilizeEnvironment();
            Exception ex = await Assert.ThrowsAsync <KeyNotFoundException>(() => characterHealthService.AddTempHPToCharacter("TEST", 5));

            Assert.Equal("Character not found for identifier", ex.Message);
        }
Ejemplo n.º 2
0
        public async void AddTempHP_InvalidArguments_FailingTest()
        {
            CharacterHealthService characterHealthService = InitilizeEnvironment();
            Exception ex = await Assert.ThrowsAsync <ArgumentException>(() => characterHealthService.AddTempHPToCharacter("", 5));

            Assert.Equal("Invalid arguments", ex.Message);
        }
Ejemplo n.º 3
0
        public async void AddTempHP_PassingTest()
        {
            CharacterHealthService characterHealthService = InitilizeEnvironment();
            Character character = await characterHealthService.AddTempHPToCharacter("Briv", 5);

            Assert.True(character.HP.Total == character.HP.Max + 5); //no damage done to character yet, should be max
        }
Ejemplo n.º 4
0
        private CharacterHealthService InitilizeEnvironment()
        {
            //Typically would use a faking library to fake the repository and not use concrete classes, but since the repository is fake anyway this seemed easier for now and gets the general point across
            CharacterRepository    characterRepository    = new CharacterRepository();
            CharacterHealthService characterHealthService = new CharacterHealthService(characterRepository);
            List <Character>       characters             = new List <Character>();

            characters.Add(DemoStartup.InitilizeDemoCharacter(characterHealthService));
            CharacterRepository.InitilizeCharacterArray(characters);
            return(characterHealthService);
        }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            Infrastructure.InfrastructureModule.RegisterServices(services);
            Domain.DomainModule.RegisterServices(services);

            //for the purposes of a demo i am creating my first character here on startup. A bit messy with DI, typically i might have something in the
            //  infrastructure layer that did any initlizing, with entity framework there is version seeding for instance
            List <Character>       characters             = new List <Character>();
            CharacterRepository    characterRepository    = new CharacterRepository();
            CharacterHealthService characterHealthService = new CharacterHealthService(characterRepository);

            characters.Add(DemoStartup.InitilizeDemoCharacter(characterHealthService));
            CharacterRepository.InitilizeCharacterArray(characters);
        }
Ejemplo n.º 6
0
        public async void HealCharacter_PassingTest()
        {
            CharacterHealthService characterHealthService = InitilizeEnvironment();
            Character character = await characterHealthService.HealCharacter("Briv", 5);

            Assert.True(character.HP.Current == character.HP.Max); //no damage done to character yet, should be max
            CharacterDamage[] characterDamages = new CharacterDamage[1];
            characterDamages[0] = new CharacterDamage()
            {
                Amount = 10,
                Type   = "piercing"
            };
            await characterHealthService.DamageCharacter("Briv", characterDamages);

            character = await characterHealthService.HealCharacter("Briv", 5);

            Assert.True(character.HP.Current == character.HP.Max - 5);
        }
Ejemplo n.º 7
0
        public async void DamageCharacter_PassingTest()
        {
            CharacterHealthService characterHealthService = InitilizeEnvironment();
            Character character = await characterHealthService.AddTempHPToCharacter("Briv", 5);

            CharacterDamage[] characterDamages = new CharacterDamage[1];
            characterDamages[0] = new CharacterDamage()
            {
                Amount = 4,
                Type   = "piercing"
            };
            //testing that the health correctly removes from temp before it removes from current health
            character = await characterHealthService.DamageCharacter("Briv", characterDamages);

            Assert.True(character.HP.Total == character.HP.Max + 1);
            character = await characterHealthService.DamageCharacter("Briv", characterDamages);

            Assert.True(character.HP.Total == character.HP.Max - 3);
            await characterHealthService.HealCharacter("Briv", 3); //bring back to full for next part

            characterDamages = new CharacterDamage[4];
            //testing damage that includes a resistance, immunity, and normal. we've tested normal already above. This also tests that a null record should be skipped correct, the 4th index is not initilized
            characterDamages[0] = new CharacterDamage()
            {
                Amount = 10,
                Type   = "fire"
            };
            characterDamages[1] = new CharacterDamage()
            {
                Amount = 5,
                Type   = "slashing"
            };
            characterDamages[2] = new CharacterDamage()
            {
                Amount = 2,
                Type   = "psychic"
            };
            character = await characterHealthService.DamageCharacter("Briv", characterDamages); //This should deal 4 damage total because the fire is restited

            Assert.True(character.HP.Total == character.HP.Max - 4);
        }