Example #1
0
        private async Task ValidateCharacterClassAbilities(MagusTtkCharacterClassDefinitionDto characterClassDefinition, Dictionary <string, int> classAbilities, IReadOnlyRepository <AbilityDefinition> abilityRepo, CancellationToken cancellationToken = default)
        {
            if (characterClassDefinition == null)
            {
                throw new ArgumentNullException(nameof(characterClassDefinition));
            }
            if (classAbilities == null)
            {
                throw new ArgumentNullException(nameof(classAbilities));
            }
            if (abilityRepo == null)
            {
                throw new ArgumentNullException(nameof(abilityRepo));
            }

            int expectedAbilityCount = await abilityRepo.Count(null, cancellationToken);

            // ha nem a várt darabszámú tulajdonság alap érték lenne megadva
            if (classAbilities.Count != expectedAbilityCount)
            {
                throw new ArgumentException($"Character class definition '{characterClassDefinition.Code}' has {classAbilities.Count} ability base value definitions, but should have {expectedAbilityCount}.");
            }

            int abilityValueSum = 0;

            // leellenőrizzük, h minden tulajdonságra legyen megadva a kaszt specifikus alap érték
            foreach (var ability in await abilityRepo.All(null, cancellationToken))
            {
                if (!classAbilities.TryGetValue(ability.Code, out var classAbilityBaseValue))
                {
                    throw new ArgumentException($"Ability base of '{ability.Code}' is missing from character class definition '{characterClassDefinition.Code}'.");
                }

                if ((classAbilityBaseValue < 6) || (classAbilityBaseValue > 10))
                {
                    throw new ArgumentOutOfRangeException($"Value '{classAbilityBaseValue}' of class ability '{ability.Code}' in character class definition '{characterClassDefinition.Code}' is out of range. Valid values are > 5 and < 11.");
                }

                abilityValueSum += classAbilityBaseValue;
            }

            // leellenőrizzük, hogy a class definícióban tényleg 80 tulajdonság pontot osztottak-e szét
            if (abilityValueSum != 80)
            {
                throw new ArgumentOutOfRangeException($"Sum of class ability base values '{abilityValueSum}' in character class definition '{characterClassDefinition.Code}' must equal to 80.");
            }
        }
        public void RegisterCustomReadOnlyRepository()
        {
            _services.AddReadOnlyRepository <Product, ProductRepository>();
            ServiceProvider serviceProvider = _services.BuildServiceProvider();

            serviceProvider.Should().NotBeNull();

            IRepository <Product> productRepository = serviceProvider.GetService <IRepository <Product> >();

            productRepository.Should().BeNull();

            IReadOnlyRepository <Product> productReadOnlyRepository = serviceProvider.GetRequiredService <IReadOnlyRepository <Product> >();

            productReadOnlyRepository.Should().NotBeNull().And.BeOfType <ProductRepository>();

            productReadOnlyRepository.Count().Should().Be(127);
        }