Example #1
0
        public TestRules()
        {
            _attributesDb    = new InMemoryEntityRepository <Campaigns.Model.Attribute>();
            _contributionsDb = new InMemoryEntityRepository <AttributeContribution>();
            _contributionsDb.AddForeignStore(_attributesDb);

            _contributingAttributes = new HashSet <Campaigns.Model.Attribute>();

            //
            // create attributes
            //

            _races = new Dictionary <string, Campaigns.Model.Attribute>
            {
                { "human", CreateAttribute("human", "races", isStandard: false) },
                { "gnome", CreateAttribute("gnome", "races", isStandard: false) }
            };

            _abilities = new Dictionary <string, Campaigns.Model.Attribute>
            {
                { "str", CreateAttribute("str", "abilities", isStandard: true) },
                { "int", CreateAttribute("int", "abilities", isStandard: true) }
            };

            _abilityMods =
                _abilities.Values
                .Select(attrib => CreateAttribute(attrib.Name, "ability-modifiers", isStandard: true))
                .ToDictionary(m => m.Name);

            _skills = new Dictionary <string, Campaigns.Model.Attribute>
            {
                { "athletics", CreateAttribute("athletics", "skills", isStandard: true) },
                { "arcana", CreateAttribute("arcana", "skills", isStandard: true) }
            };

            // TODO: this should be standard behaviour
            // ensure all standard attributes are contributing
            foreach (var attrib in AllAttributes.Where(a => a.IsStandard))
            {
                SetInitialValue(attrib, 0);
            }

            //
            // create attribute contribution links
            //

            foreach (var mod in _abilities.Keys)
            {
                var contribution = _abilities[mod].ContributionTo(_abilityMods[mod], srcVal => (srcVal / 2) - 5);
                _contributionsDb.Add(contribution);
            }

            // TODO:
            //  - only one contributing link between src and target allowed (overwrite)

            _contributionsDb.Add(_races["gnome"].ConstantContributionTo(_abilities["int"], 2));

            _contributionsDb.Add(_skills["athletics"].CopyContributionFrom(_abilityMods["str"]));
            _contributionsDb.Add(_skills["arcana"].CopyContributionFrom(_abilityMods["int"]));
        }
        public void InitTests()
        {
            _people = new InMemoryEntityRepository <Person>();
            _groups = new InMemoryEntityRepository <Group>();
            _pets   = new InMemoryEntityRepository <Pet>();

            _groups.AddForeignStore(_people);
            _people.AddForeignStore(_groups);
            _pets.AddForeignStore(_people);

            var g1 = new Group {
                Name = "Students"
            };

            _groups.Add(g1);

            var p1 = new Person {
                Name = "Amy", Group = g1
            };

            _people.Add(p1);
            _people.Add(new Person {
                Name = "Bernie", GroupId = g1.Id
            });

            _pets.Add(new Pet {
                Name = "Charlie", Owner = p1
            });
            _pets.Add(new Pet {
                Name = "Dover", OwnerId = p1.Id
            });
        }
Example #3
0
        public TestRules()
        {
            _attributesDb = new InMemoryEntityRepository<Campaigns.Model.Attribute>();
            _contributionsDb = new InMemoryEntityRepository<AttributeContribution>();
            _contributionsDb.AddForeignStore(_attributesDb);

            _contributingAttributes = new HashSet<Campaigns.Model.Attribute>();

            //
            // create attributes
            //

            _races = new Dictionary<string, Campaigns.Model.Attribute>
            {
                { "human", CreateAttribute("human", "races", isStandard: false) },
                { "gnome", CreateAttribute("gnome", "races", isStandard: false) }
            };

            _abilities = new Dictionary<string, Campaigns.Model.Attribute>
            {
                { "str", CreateAttribute("str", "abilities", isStandard: true) },
                { "int", CreateAttribute("int", "abilities", isStandard: true) }
            };

            _abilityMods =
                _abilities.Values
                .Select(attrib => CreateAttribute(attrib.Name, "ability-modifiers", isStandard: true))
                .ToDictionary(m => m.Name);

            _skills = new Dictionary<string, Campaigns.Model.Attribute>
            {
                { "athletics", CreateAttribute("athletics", "skills", isStandard: true) },
                { "arcana", CreateAttribute("arcana", "skills", isStandard: true) }
            };

            // TODO: this should be standard behaviour
            // ensure all standard attributes are contributing
            foreach (var attrib in AllAttributes.Where(a => a.IsStandard))
            {
                SetInitialValue(attrib, 0);
            }

            //
            // create attribute contribution links
            //

            foreach (var mod in _abilities.Keys)
            {
                var contribution = _abilities[mod].ContributionTo(_abilityMods[mod], srcVal => (srcVal / 2) - 5);
                _contributionsDb.Add(contribution);
            }

            // TODO:
            //  - only one contributing link between src and target allowed (overwrite)

            _contributionsDb.Add(_races["gnome"].ConstantContributionTo(_abilities["int"], 2));

            _contributionsDb.Add(_skills["athletics"].CopyContributionFrom(_abilityMods["str"]));
            _contributionsDb.Add(_skills["arcana"].CopyContributionFrom(_abilityMods["int"]));
        }
        public void InitTests()
        {
            _people = new InMemoryEntityRepository<Person>();
            _groups = new InMemoryEntityRepository<Group>();
            _pets = new InMemoryEntityRepository<Pet>();

            _groups.AddForeignStore(_people);
            _people.AddForeignStore(_groups);
            _pets.AddForeignStore(_people);

            var g1 = new Group { Name = "Students" };
            _groups.Add(g1);

            var p1 = new Person { Name = "Amy", Group = g1 };
            _people.Add(p1);
            _people.Add(new Person { Name = "Bernie", GroupId = g1.Id });

            _pets.Add(new Pet { Name = "Charlie", Owner = p1 });
            _pets.Add(new Pet { Name = "Dover", OwnerId = p1.Id });
        }
        public void TestEntitiesMayHaveNullForeignKeys()
        {
            _people.Add(new Person {
                Name = "Paul"
            });

            var p1 = _people.AsQueryable.FirstOrDefault(p => p.Name == "Paul");

            Assert.IsNotNull(p1);

            Assert.IsNull(p1.Group);
            Assert.AreEqual(0, p1.GroupId);
        }
        public void GivenEmptyRepository_FirstEntityIdShouldBe1(string name, int x, int y)
        {
            var entity = _sut.Add(name, x, y, new EntityAttribute[] { });

            entity.Id.Should().Be(1);
        }