コード例 #1
0
        public IsProficientCM buildIsProficientCM(Guid Character_id)
        {
            IsProficient foundRecord = _userAccess.GetProficiencyRecord(Character_id);
            ReadModelMapper <IsProficient, IsProficientCM> mapper = new ReadModelMapper <IsProficient, IsProficientCM>();
            IsProficientCM cm = mapper.mapDataModelToViewModel(foundRecord);

            return(cm);
        }
コード例 #2
0
        public static IsProficientCM mapIsProficientToIsProficientCM(IsProficient m)
        {
            ReadModelMapper <IsProficient, IsProficientCM> mapper = new ReadModelMapper <IsProficient, IsProficientCM>();
            IsProficientCM cm = new IsProficientCM();

            mapper.mapDataModelToViewModel(m, cm);
            return(cm);
        }
コード例 #3
0
        public void CreateCharacterPOST(Guid user_id, CharacterVM vm)
        {
            Guid character_id = Guid.NewGuid();
            CreateModelMapper <PrimaryTabVM, CharacterDM> characterMapper = new CreateModelMapper <PrimaryTabVM, CharacterDM>();
            CreateModelMapper <CombatCM, CharacterDM>     combatMapper    = new CreateModelMapper <CombatCM, CharacterDM>();
            CharacterDM character = characterMapper.mapViewModelToDataModel(vm.PrimaryTab);

            if (_commons.raceExists(vm.PrimaryTab.Race) == true)
            {
                character.Race_id = vm.PrimaryTab.Race;
            }
            ;
            combatMapper.mapViewModelToDataModel(vm.PrimaryTab.Combat, character);


            character.Character_id = character_id;
            Health       health = CharacterMapper.mapCombatCMToNewHealthEntity(vm.PrimaryTab.Combat);
            IsProficient skills = mapIsProficient(vm.PrimaryTab.Skills.isProficient);
            CreateModelMapper <SavesCM, IsProficient> mapSaves = new CreateModelMapper <SavesCM, IsProficient>();

            mapSaves.mapViewModelToDataModel(vm.PrimaryTab.Saves, skills);
            Stats    stats = CharacterMapper.mapStatsCMToNewEntity(vm.PrimaryTab.Stats);
            Currency money = CharacterMapper.mapCurrencyCMToNewEntity(vm.InventoryTab.Money);

            character.Character_id = character_id;
            character.User_id      = user_id;
            health.Character_id    = character_id;
            stats.Character_id     = character_id;
            skills.Character_id    = character_id;
            money.Character_id     = character_id;

            _userAccess.AddCharacter(character);
            _userAccess.AddHealthRecord(health);
            _userAccess.AddStatsRecord(stats);
            _userAccess.AddProficiencyRecord(skills);
            _userAccess.AddCurrencyRecord(money);
            LearnSpells(vm.SpellsTab.KnownSpells, character_id);
            SetInventory(vm.InventoryTab.Items, character_id);
            SetNotes(vm.NotesTab.Notes, character_id);
            SetClasses(vm.PrimaryTab.Classes.SelectedClasses, character_id);
            _userAccess.SaveChanges();
        }
コード例 #4
0
        public static IsProficient GetSampleIsProficient()
        {
            IsProficient isProficient = new IsProficient
            {
                Character_id     = Guid.Parse("11111111-2222-3333-4444-555555555555"),
                StrengthSave     = true,
                DexteritySave    = true,
                ConstitutionSave = true,
                IntelligenceSave = false,
                WisdomSave       = false,
                CharismaSave     = false,

                Acrobatics     = true,
                AnimalHandling = true,
                Arcana         = true,
                Athletics      = true,
                Deception      = true,

                History       = false,
                Intimidation  = false,
                Investigation = false,
                Medicine      = false,
                Nature        = false,

                Perception    = true,
                Performance   = true,
                Persuasion    = true,
                Religion      = true,
                SleightOfHand = true,

                Stealth  = false,
                Survival = false
            };

            return(isProficient);
        }
コード例 #5
0
 public void AddProficiencyRecord(IsProficient proficiencies)
 {
     _worker.ProficiencyRecords.Add(proficiencies);
 }
コード例 #6
0
        public void CreateCharacter_POST_DataAddedToSets()
        {
            //---------- Arrange ----------
            List <CharacterDM> characters = new List <CharacterDM>();
            var characterMockSet          = new Mock <DbSet <CharacterDM> >()
                                            .SetupData(characters, o =>
            {
                return(characters.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            List <Currency> heldMoney    = new List <Currency>();
            var             moneyMockSet = new Mock <DbSet <Currency> >()
                                           .SetupData(heldMoney, o =>
            {
                return(heldMoney.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            List <Health> healthRecords = new List <Health>();
            var           healthMockSet = new Mock <DbSet <Health> >()
                                          .SetupData(healthRecords, o =>
            {
                return(healthRecords.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            List <IsProficient> skills = new List <IsProficient>();
            var skillsMockSet          = new Mock <DbSet <IsProficient> >()
                                         .SetupData(skills, o =>
            {
                return(skills.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            List <Note> notes        = new List <Note>();
            var         notesMockSet = new Mock <DbSet <Note> >()
                                       .SetupData(notes, o =>
            {
                return(notes.Single(x => x.Note_id.CompareTo(o.First()) == 0));
            });
            List <Stats> stats        = new List <Stats>();
            var          statsMockSet = new Mock <DbSet <Stats> >()
                                        .SetupData(stats, o =>
            {
                return(stats.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });

            List <Character_Class_Subclass> CCSC_Records = new List <Character_Class_Subclass>();
            var ccscMockSet = new Mock <DbSet <Character_Class_Subclass> >()
                              .SetupData(CCSC_Records, o =>
            {
                return(CCSC_Records.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            List <Character_Item> inventories = new List <Character_Item>();
            var inventoryMockSet = new Mock <DbSet <Character_Item> >()
                                   .SetupData(inventories, o =>
            {
                return(inventories.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            List <Spell_Character> knownSpells = new List <Spell_Character>();
            var knownSpellsMockSet             = new Mock <DbSet <Spell_Character> >()
                                                 .SetupData(knownSpells, o =>
            {
                return(knownSpells.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });

            //---------- Expected ----------

            CharacterDM expectedCharacterDM = new CharacterDM
            {
                Character_id  = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),
                User_id       = Guid.Parse("7d210de0-58f7-48ec-8065-4f4304725933"),
                Name          = "Caleb Widowgast",
                Alignment     = "Chaotic Good",
                ArmorClass    = 14,
                Background    = "blah",
                Exp           = 0,
                Inspiration   = false,
                MovementSpeed = 30,
                Race_id       = Guid.Parse("14f91515-0107-4c79-a3da-be3cf48d7a26")
            };
            Currency expectedCurrency = new Currency
            {
                Character_id = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),
                GoldPieces   = 3,
                SilverPieces = 50
            };
            Health expectedHealth = new Health
            {
                Character_id       = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),
                MaxHP              = 15,
                CurrentHP          = 15,
                TempHP             = 0,
                DeathSaveFails     = 0,
                DeathSaveSuccesses = 0
            };
            IsProficient expectedSkills = new IsProficient
            {
                Character_id = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),

                StrengthSave     = false,
                DexteritySave    = false,
                ConstitutionSave = true,
                IntelligenceSave = true,
                WisdomSave       = false,
                CharismaSave     = false,

                Acrobatics     = false,
                AnimalHandling = false,
                Arcana         = true,
                Athletics      = false,
                Deception      = true,
                History        = true,
                Intimidation   = false,
                Investigation  = true,
                Medicine       = false,
                Nature         = false,
                Perception     = false,
                Performance    = false,
                Persuasion     = false,
                Religion       = true,
                SleightOfHand  = false,
                Stealth        = false,
                Survival       = true
            };
            List <Note> expectedNotes = new List <Note>();

            expectedNotes.Add(new Note
            {
                Character_id = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),
                Note_id      = Guid.Parse("b5c49d62-737e-4357-903b-e17cb30daf07"),
                Name         = "The Cat Prince",
                Contents     = "A children's picture book. The text is in Zemnian"
            });

            Stats expectedStats = new Stats
            {
                Character_id = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),
                Strength     = 10,
                Dexterity    = 12,
                Constitution = 14,
                Intelligence = 20,
                Wisdom       = 16,
                Charisma     = 16
            };

            List <Character_Class_Subclass> expected_CCSC = new List <Character_Class_Subclass>();

            expected_CCSC.Add(new Character_Class_Subclass
            {
                Character_id     = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),
                Class_id         = Guid.Parse("4e82620a-0496-4ecc-b6d4-05faa064310b"),
                Subclass_id      = Guid.Parse("c8d2e23a-a193-4e06-8814-9180d4830732"),
                RemainingHitDice = 12,
                ClassLevel       = 12
            });

            List <Character_Item> expected_inventory = new List <Character_Item>();

            expected_inventory.Add(new Character_Item
            {
                //Has a healing potion
                Character_id = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),
                Item_id      = Guid.Parse("2caa23dc-15e6-4a57-9bb6-62f6d8636ff7"),
                isEquipped   = false,
                IsAttuned    = false,
                count        = 1
            });

            List <Spell_Character> expected_knownSpells = new List <Spell_Character>();

            expected_knownSpells.Add(new Spell_Character
            {
                //Caleb knows firebolt
                Character_id = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),
                Spell_id     = Guid.Parse("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"),
                isPrepared   = false
            });

            bool saveCalled = false;

            //---------- Argument ----------
            var Argument = buildPOSTArgument();



            using (var mocks = AutoMock.GetLoose())
            {
                mocks.Mock <CharacterContext>()
                .Setup(x => x.Set <CharacterDM>()).Returns(characterMockSet.Object);
                mocks.Mock <CharacterContext>()
                .Setup(x => x.Set <Currency>()).Returns(moneyMockSet.Object);
                mocks.Mock <CharacterContext>()
                .Setup(x => x.Set <Health>()).Returns(healthMockSet.Object);
                mocks.Mock <CharacterContext>()
                .Setup(x => x.Set <IsProficient>()).Returns(skillsMockSet.Object);
                mocks.Mock <CharacterContext>()
                .Setup(x => x.Set <Note>()).Returns(notesMockSet.Object);
                mocks.Mock <CharacterContext>()
                .Setup(x => x.Set <Stats>()).Returns(statsMockSet.Object);

                mocks.Mock <PlayableClassContext>()
                .Setup(x => x.Set <Character_Class_Subclass>()).Returns(ccscMockSet.Object);
                mocks.Mock <ItemsContext>()
                .Setup(x => x.Set <Character_Item>()).Returns(inventoryMockSet.Object);
                mocks.Mock <SpellsContext>()
                .Setup(x => x.Set <Spell_Character>()).Returns(knownSpellsMockSet.Object);

                mocks.Mock <IBaseUserAccess>()
                .Setup(x => x.AddCharacter(It.IsAny <CharacterDM>()))
                .Callback <CharacterDM>((characterRecord) => characters.Add(characterRecord));
                mocks.Mock <IBaseUserAccess>()
                .Setup(x => x.AddCurrencyRecord(It.IsAny <Currency>()))
                .Callback <Currency>((currency) => heldMoney.Add(currency));
                mocks.Mock <IBaseUserAccess>()
                .Setup(x => x.AddHealthRecord(It.IsAny <Health>()))
                .Callback <Health>((health) => healthRecords.Add(health));
                mocks.Mock <IBaseUserAccess>()
                .Setup(x => x.AddProficiencyRecord(It.IsAny <IsProficient>()))
                .Callback <IsProficient>((IsProficient) => skills.Add(IsProficient));
                mocks.Mock <IBaseUserAccess>()
                .Setup(x => x.AddStatsRecord(It.IsAny <Stats>()))
                .Callback <Stats>((stat) => stats.Add(stat));
                mocks.Mock <IBaseUserAccess>()
                .Setup(x => x.AddNote(It.IsAny <Note>()))
                .Callback <Note>((theNote) => notes.Add(theNote));

                mocks.Mock <IBaseUserAccess>()
                .Setup(x => x.CharacterLearnsSpell(It.IsAny <Spell_Character>()))
                .Callback <Spell_Character>((sc) => knownSpells.Add(sc));

                mocks.Mock <IBaseUserAccess>()
                .Setup(x => x.CharacterObtainsItem(It.IsAny <Character_Item>()))
                .Callback <Character_Item>((ci) => inventories.Add(ci));

                mocks.Mock <IBaseUserAccess>()
                .Setup(x => x.CharacterLearnsClass(It.IsAny <Character_Class_Subclass>()))
                .Callback <Character_Class_Subclass>((record) => CCSC_Records.Add(record));

                mocks.Mock <IBaseUserAccess>()
                .Setup(x => x.SaveChanges())
                .Callback(() => saveCalled = true);

                mocks.Mock <ICharacterCommonFunctions>()
                .Setup(x => x.raceExists(Guid.Parse("14f91515-0107-4c79-a3da-be3cf48d7a26"))).Returns(true);

                //---------- act ----------
                var access  = mocks.Create <IBaseUserAccess>();
                var commons = mocks.Create <ICharacterCommonFunctions>();
                var toTest  = ProcessorFactory.getCreateCharacterProcessor(access, commons);
                toTest.CreateCharacterPOST(Guid.Parse("7d210de0-58f7-48ec-8065-4f4304725933"), Argument);

                //Assert
                characters.Should().ContainEquivalentOf(expectedCharacterDM, options =>
                                                        options.Excluding(x => x.Character_id));
                heldMoney.Should().ContainEquivalentOf(expectedCurrency, options =>
                                                       options.Excluding(x => x.Character_id));
                healthRecords.Should().ContainEquivalentOf(expectedHealth, options =>
                                                           options.Excluding(x => x.Character_id));
                stats.Should().ContainEquivalentOf(expectedStats, options =>
                                                   options.Excluding(x => x.Character_id));
                skills.Should().ContainEquivalentOf(expectedSkills, options =>
                                                    options.Excluding(x => x.Character_id));
                notes.Should().BeEquivalentTo(expectedNotes, options =>
                                              options.Excluding(x => x.Note_id)
                                              .Excluding(x => x.Character_id));
                saveCalled.Should().BeTrue();
            }
        }
コード例 #7
0
        public void CMBUilder_buildIsProficientCM()
        {
            Guid         Caleb_id    = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4");
            IsProficient CalebRecord = new IsProficient
            {
                Character_id     = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),
                StrengthSave     = false,
                DexteritySave    = false,
                ConstitutionSave = true,
                IntelligenceSave = false,
                WisdomSave       = false,
                CharismaSave     = false,

                Acrobatics     = false,
                AnimalHandling = false,
                Arcana         = true,
                Athletics      = false,
                Deception      = true,

                History       = true,
                Intimidation  = false,
                Investigation = true,
                Medicine      = false,
                Nature        = false,

                Perception    = false,
                Performance   = false,
                Persuasion    = false,
                Religion      = true,
                SleightOfHand = false,

                Stealth  = false,
                Survival = false
            };
            IsProficientCM Expected = new IsProficientCM
            {
                Acrobatics     = false,
                AnimalHandling = false,
                Arcana         = true,
                Athletics      = false,
                Deception      = true,

                History       = true,
                Intimidation  = false,
                Investigation = true,
                Medicine      = false,
                Nature        = false,

                Perception    = false,
                Performance   = false,
                Persuasion    = false,
                Religion      = true,
                SleightOfHand = false,

                Stealth  = false,
                Survival = false
            };

            using (var mockAccess = AutoMock.GetLoose())
            {
                mockAccess.Mock <IBaseUserAccess>()
                .Setup(x => x.GetProficiencyRecord(Caleb_id)).Returns(CalebRecord);

                //Act
                var access = mockAccess.Create <IBaseUserAccess>();
                ICharacterCMBuilder toTest = ProcessorFactory.GetCharacterCMBuilder(access);
                var actual = toTest.buildIsProficientCM(Caleb_id);

                //Assert
                actual.Should().BeEquivalentTo(Expected);
            }
        }
コード例 #8
0
        public void CMBuilder_buildProficiencyCM()
        {
            var skillBonus = new SkillBonusCM
            {
                Acrobatics     = 1,
                AnimalHandling = -3,
                Arcana         = 8,
                Athletics      = 0,
                Deception      = 6,

                History       = 8,
                Insight       = -3,
                Intimidation  = 3,
                Investigation = 8,
                Medicine      = -3,
                Nature        = 5,

                Perception    = -3,
                Performance   = 3,
                Persuasion    = 3,
                Religion      = 8,
                SleightOfHand = 1,

                Stealth  = 1,
                Survival = -3
            };
            var statBonus = new StatBonusCM
            {
                Strength     = 0,
                Dexterity    = 1,
                Constitution = 3,
                Intelligence = 5,
                Wisdom       = -3,
                Charisma     = 3
            };
            var proficiencies = new IsProficientCM
            {
                Acrobatics     = false,
                AnimalHandling = false,
                Arcana         = true,
                Athletics      = false,
                Deception      = true,

                History       = true,
                Intimidation  = false,
                Investigation = true,
                Medicine      = false,
                Nature        = false,

                Perception    = false,
                Performance   = false,
                Persuasion    = false,
                Religion      = true,
                SleightOfHand = false,

                Stealth  = false,
                Survival = false
            };
            var expected = new ProficiencyCM
            {
                ProficiencyBonus = 3,
                TotalBonus       = skillBonus,
                isProficient     = proficiencies
            };

            var proficiencyRecord = new IsProficient
            {
                Character_id     = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),
                StrengthSave     = false,
                DexteritySave    = false,
                ConstitutionSave = true,
                IntelligenceSave = false,
                WisdomSave       = false,
                CharismaSave     = false,

                Acrobatics     = false,
                AnimalHandling = false,
                Arcana         = true,
                Athletics      = false,
                Deception      = true,

                History       = true,
                Intimidation  = false,
                Investigation = true,
                Medicine      = false,
                Nature        = false,

                Perception    = false,
                Performance   = false,
                Persuasion    = false,
                Religion      = true,
                SleightOfHand = false,

                Stealth  = false,
                Survival = false
            };
            var Caleb_id = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4");

            using (var mockAccess = AutoMock.GetLoose())
            {
                mockAccess.Mock <IBaseUserAccess>()
                .Setup(x => x.GetProficiencyRecord(Caleb_id)).Returns(proficiencyRecord);

                //Act
                var access = mockAccess.Create <IBaseUserAccess>();
                ICharacterCMBuilder toTest = ProcessorFactory.GetCharacterCMBuilder(access);
                var actual = toTest.buildProficiencyCM(Caleb_id, statBonus, 12);

                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }