Esempio n. 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"]));
        }
Esempio n. 2
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
            });
        }
Esempio n. 4
0
        public void TestInit()
        {
            _attributes = new InMemoryEntityRepository<Campaigns.Model.Attribute>();
            _contributions = new InMemoryEntityRepository<Campaigns.Model.AttributeContribution>();
            _contributions.AddForeignStore(_attributes);

            _characterSheets = new InMemoryEntityRepository<Campaigns.Model.CharacterSheet>();
            _characters = new InMemoryEntityRepository<Campaigns.Model.Character>();
            _characters.AddForeignStore(_characterSheets);

            _attributes.AddRange(new[]
            {
                new Campaigns.Model.Attribute { Name = "human", Category = "race", IsStandard = false },
                new Campaigns.Model.Attribute { Name = "gnome", Category = "race", IsStandard = false },
                new Campaigns.Model.Attribute { Name = "str", Category = "abilities", IsStandard = true },
                new Campaigns.Model.Attribute { Name = "int", Category = "abilities", IsStandard = true },
                new Campaigns.Model.Attribute { Name = "str", Category = "ability-mods", IsStandard = true },
                new Campaigns.Model.Attribute { Name = "int", Category = "ability-mods", IsStandard = true },
            });

            _contributions.AddRange(new[]
            {
                Attrib("gnome", "race").ConstantContributionTo(Attrib("int", "abilities"), 2),
                Attrib("str", "abilities").ContributionTo(Attrib("str", "ability-mods"), n => n / 2 - 5),
                Attrib("int", "abilities").ContributionTo(Attrib("int", "ability-mods"), n => n / 2 - 5),
            });

            _rules = new RulesService(
                _attributes,
                _contributions,
                _characterSheets,
                _characters);

            _gnomeAllocations = new []
            {
                new AttributeAllocation { Attribute = Attrib("gnome", "race") },
                new AttributeAllocation { Attribute = Attrib("str", "abilities"), Value = 8 },
                new AttributeAllocation { Attribute = Attrib("int", "abilities"), Value = 8 },
            };

            _superStrongUpdate = new CharacterUpdate
            {
                AddedOrUpdatedAllocations = new []
                {
                    new AttributeAllocation { Attribute = Attrib("str", "abilities"), Value = 20 },
                }
            };
        }
        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 });
        }
Esempio n. 6
0
        public void RemoveEntity_WhenInvokedWithMatchingName_ShouldRemoveEntity()
        {
            // Arrange
            var entities = new[]
            {
                new SimpleEntity("ent 1"),
                new SimpleEntity("ent 2"),
                new SimpleEntity("ent 3")
            };
            var fixture = new InMemoryEntityRepository(entities);

            // Act
            fixture.RemoveEntity("ent 2");
            var allEntities = fixture.GetAllEntities();

            // Assert
            allEntities.Should().BeEquivalentTo(new[]
            {
                new SimpleEntity("ent 1"),
                new SimpleEntity("ent 3")
            });
        }
Esempio n. 7
0
        public void GetAllEntities_WhenInvoked_ShouldReturnListOfEntities()
        {
            // Arrange
            var entities = new[]
            {
                new SimpleEntity("ent 1"),
                new SimpleEntity("ent 2"),
                new SimpleEntity("ent 3")
            };
            var fixture = new InMemoryEntityRepository(entities);

            // Act
            var response = fixture.GetAllEntities();

            // Assert
            response.Should().BeEquivalentTo(new[]
            {
                new SimpleEntity("ent 1"),
                new SimpleEntity("ent 2"),
                new SimpleEntity("ent 3")
            });
        }
Esempio n. 8
0
        public void UpdateEntity_WhenInvokedWithNonMatchingName_ShouldHaveNoEffect()
        {
            // Arrange
            var entities = new[]
            {
                new SimpleEntity("ent 1"),
                new SimpleEntity("ent 2"),
                new SimpleEntity("ent 3")
            };
            var fixture = new InMemoryEntityRepository(entities);

            // Act
            fixture.UpdateEntity("ent 5", new SimpleEntity("updated 1"));
            var allEntities = fixture.GetAllEntities();

            // Assert
            allEntities.Should().BeEquivalentTo(new[]
            {
                new SimpleEntity("ent 1"),
                new SimpleEntity("ent 2"),
                new SimpleEntity("ent 3")
            });
        }
Esempio n. 9
0
        public void AddEntity_WhenInvoked_ShouldAddEntity()
        {
            // Arrange
            var entities = new[]
            {
                new SimpleEntity("ent 1"),
                new SimpleEntity("ent 2"),
                new SimpleEntity("ent 3")
            };
            var fixture = new InMemoryEntityRepository(entities);

            // Act
            fixture.AddEntity(new SimpleEntity("new 1"));
            var allEntities = fixture.GetAllEntities();

            // Assert
            allEntities.Should().BeEquivalentTo(new[]
            {
                new SimpleEntity("ent 1"),
                new SimpleEntity("ent 2"),
                new SimpleEntity("ent 3"),
                new SimpleEntity("new 1")
            });
        }
Esempio n. 10
0
        public void TestInit()
        {
            _attributes    = new InMemoryEntityRepository <Campaigns.Model.Attribute>();
            _contributions = new InMemoryEntityRepository <Campaigns.Model.AttributeContribution>();
            _contributions.AddForeignStore(_attributes);

            _characterSheets = new InMemoryEntityRepository <Campaigns.Model.CharacterSheet>();
            _characters      = new InMemoryEntityRepository <Campaigns.Model.Character>();
            _characters.AddForeignStore(_characterSheets);

            _attributes.AddRange(new[]
            {
                new Campaigns.Model.Attribute {
                    Name = "human", Category = "race", IsStandard = false
                },
                new Campaigns.Model.Attribute {
                    Name = "gnome", Category = "race", IsStandard = false
                },
                new Campaigns.Model.Attribute {
                    Name = "str", Category = "abilities", IsStandard = true
                },
                new Campaigns.Model.Attribute {
                    Name = "int", Category = "abilities", IsStandard = true
                },
                new Campaigns.Model.Attribute {
                    Name = "str", Category = "ability-mods", IsStandard = true
                },
                new Campaigns.Model.Attribute {
                    Name = "int", Category = "ability-mods", IsStandard = true
                },
            });

            _contributions.AddRange(new[]
            {
                Attrib("gnome", "race").ConstantContributionTo(Attrib("int", "abilities"), 2),
                Attrib("str", "abilities").ContributionTo(Attrib("str", "ability-mods"), n => n / 2 - 5),
                Attrib("int", "abilities").ContributionTo(Attrib("int", "ability-mods"), n => n / 2 - 5),
            });

            _rules = new RulesService(
                _attributes,
                _contributions,
                _characterSheets,
                _characters);

            _gnomeAllocations = new []
            {
                new AttributeAllocation {
                    Attribute = Attrib("gnome", "race")
                },
                new AttributeAllocation {
                    Attribute = Attrib("str", "abilities"), Value = 8
                },
                new AttributeAllocation {
                    Attribute = Attrib("int", "abilities"), Value = 8
                },
            };

            _superStrongUpdate = new CharacterUpdate
            {
                AddedOrUpdatedAllocations = new []
                {
                    new AttributeAllocation {
                        Attribute = Attrib("str", "abilities"), Value = 20
                    },
                }
            };
        }
 public InMemoryEntityRepositoryTests()
 {
     _sut = _fixture.Create <InMemoryEntityRepository>();
 }
        public void SetUp()
        {
            sut = new SnapShotService();

            bus = MockRepository.GenerateMock<IBus>();
            eventConvertor = MockRepository.GenerateMock<IEventConvertor>();

            var entityRepository = new InMemoryEntityRepository();
            domainRepository = new DomainRepository(new DomainEventStorageService(entityRepository, new DateTimeService()), bus, eventConvertor);
        }