private void GetSelectableClasses(ClassRowCM[] classRowCMs) { //Pull class data from DB, map it to a set of Class list models. List <PlayableClass> PCs = _userAccess.GetAllPlayableClasses().ToList(); ReadModelMapper <PlayableClass, ClassesListModel> mapper = new ReadModelMapper <PlayableClass, ClassesListModel>(); List <ClassesListModel> playableList = new List <ClassesListModel>(); foreach (PlayableClass pc in PCs) { ClassesListModel lm = mapper.mapDataModelToViewModel(pc); playableList.Add(lm); } //add copies of that set of list models to each CM. foreach (ClassRowCM rowCM in classRowCMs) { rowCM.playableClasses = playableList.ToArray(); if (rowCM.SelectedClass_id != null) { //get that CM's subclasses, turn it into a set of Subclasses List Models, and set. List <Subclass> foundSubclasses = _userAccess.GetAllSubclassesForClass(rowCM.SelectedClass_id).ToList(); ReadModelMapper <Subclass, SubclassesListModel> subclassMapper = new ReadModelMapper <Subclass, SubclassesListModel>(); List <SubclassesListModel> subclasses = new List <SubclassesListModel>(); foreach (Subclass sc in foundSubclasses) { SubclassesListModel lm = subclassMapper.mapDataModelToViewModel(sc); subclasses.Add(lm); } rowCM.subclasses = subclasses.ToArray(); } } }
public ClassRowCM buildKnownClassRowCM(int Index, Character_Class_Subclass ccsc, ClassesListModel[] CLM) { // Takes the set of list models as an argument, as //being passed references to the same set is more efficient than searching and obtaining the set again and again. //Still have to search for each class' subclasses, as that changes depending on the class. ReadModelMapper <Subclass, SubclassesListModel> subclassMapper = new ReadModelMapper <Subclass, SubclassesListModel>(); List <Subclass> foundSubclasses = _userAccess.GetAllSubclassesForClass(ccsc.Class_id).ToList(); List <SubclassesListModel> sclm = new List <SubclassesListModel>(); foreach (Subclass x in foundSubclasses) { SubclassesListModel lm = subclassMapper.mapDataModelToViewModel(x); sclm.Add(lm); } ClassRowCM cm = new ClassRowCM { Index = Index, playableClasses = CLM, SelectedClass_id = ccsc.Class_id, Level = ccsc.ClassLevel, RemainingHitDice = ccsc.RemainingHitDice, subclasses = sclm.ToArray(), SelectedSubclass_id = ccsc.Subclass_id }; return(cm); }
public void CreateCharacter_INVALID_ReferenceDataReset() { //Arrange var argument = buildPOSTArgument(); var Wizard_id = Guid.Parse("4e82620a-0496-4ecc-b6d4-05faa064310b"); argument.PrimaryTab.Classes.SelectedClasses[0].SelectedClass_id = Wizard_id; var expected = argument; var selectableClasses = new List <ClassesListModel>(); //set classes ReadModelMapper <PlayableClass, ClassesListModel> classesMapper = new ReadModelMapper <PlayableClass, ClassesListModel>(); foreach (PlayableClass pc in CreateTestData.GetPlayableClasses()) { ClassesListModel lm = classesMapper.mapDataModelToViewModel(pc); selectableClasses.Add(lm); } foreach (ClassRowCM cm in expected.PrimaryTab.Classes.SelectedClasses) { cm.playableClasses = selectableClasses.ToArray(); //set subclasses List <SubclassesListModel> subclasses = new List <SubclassesListModel>(); ReadModelMapper <Subclass, SubclassesListModel> subclassesMapper = new ReadModelMapper <Subclass, SubclassesListModel>(); foreach (Subclass sc in CreateTestData.GetListOfSubclass().Where(x => x.Class_id == cm.SelectedClass_id)) { SubclassesListModel lm = subclassesMapper.mapDataModelToViewModel(sc); subclasses.Add(lm); } cm.subclasses = subclasses.ToArray(); } //set races ReadModelMapper <Race, RaceListModel> racesMapper = new ReadModelMapper <Race, RaceListModel>(); List <RaceListModel> raceList = new List <RaceListModel>(); foreach (Race r in CreateTestData.GetListOfRace()) { RaceListModel lm = racesMapper.mapDataModelToViewModel(r); } //I need to obtain and replace the reference data for available races, classes, and subclasses. using (var mocks = AutoMock.GetLoose()) { mocks.Mock <IBaseUserAccess>() .Setup(x => x.GetAllRaces()).Returns(CreateTestData.GetListOfRace()); mocks.Mock <IBaseUserAccess>() .Setup(x => x.GetAllPlayableClasses()).Returns(CreateTestData.GetPlayableClasses()); mocks.Mock <IBaseUserAccess>() .Setup(x => x.GetAllSubclassesForClass(Wizard_id)) .Returns(CreateTestData.GetListOfSubclass().Where(x => x.Class_id == Wizard_id)); mocks.Mock <ICharacterCommonFunctions>() .Setup(x => x.itemExists(Guid.NewGuid())).Returns(false); var access = mocks.Create <IBaseUserAccess>(); var commons = mocks.Create <ICharacterCommonFunctions>(); //Act var toTest = ProcessorFactory.getCreateCharacterProcessor(access, commons); var actual = toTest.CreateCharacterINVALID(argument); actual.Should().BeEquivalentTo(expected); } }
public void CMBuilder_buildKnownClassRowCM() { //Arrange var Wizard_id = Guid.Parse("4e82620a-0496-4ecc-b6d4-05faa064310b"); var Caleb_id = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"); var Transmutation_id = Guid.Parse("c8d2e23a-a193-4e06-8814-9180d4830732"); List <PlayableClass> playableClasses = CreateTestData.GetPlayableClasses(); List <ClassesListModel> ClassesLM = new List <ClassesListModel>(); foreach (PlayableClass playableClass in playableClasses) { ReadModelMapper <PlayableClass, ClassesListModel> mapper = new ReadModelMapper <PlayableClass, ClassesListModel>(); ClassesListModel lm = mapper.mapDataModelToViewModel(playableClass); ClassesLM.Add(lm); } List <Subclass> playableSubclasses = CreateTestData.GetListOfSubclass(); List <SubclassesListModel> SubclassesLM = new List <SubclassesListModel>(); foreach (Subclass subclass in playableSubclasses.Where(x => x.Class_id == Wizard_id)) { ReadModelMapper <Subclass, SubclassesListModel> mapper = new ReadModelMapper <Subclass, SubclassesListModel>(); SubclassesListModel lm = mapper.mapDataModelToViewModel(subclass); SubclassesLM.Add(lm); } Character_Class_Subclass Caleb_Wizard_Transmutation = 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 }; ClassRowCM expected = new ClassRowCM { Index = 1, playableClasses = ClassesLM.ToArray(), SelectedClass_id = Wizard_id, Level = 12, RemainingHitDice = 12, subclasses = SubclassesLM.ToArray(), SelectedSubclass_id = Transmutation_id }; using (var mockAccess = AutoMock.GetLoose()) { mockAccess.Mock <IBaseUserAccess>() .Setup(x => x.GetKnownClassRecordOfCharaterAndClass(Caleb_id, Wizard_id)) .Returns(Caleb_Wizard_Transmutation); mockAccess.Mock <IBaseUserAccess>() .Setup(x => x.GetAllSubclassesForClass(Wizard_id)) .Returns(playableSubclasses.Where(x => x.Class_id == Wizard_id)); IBaseUserAccess access = mockAccess.Create <IBaseUserAccess>(); //Act ICharacterCMBuilder toTest = ProcessorFactory.GetCharacterCMBuilder(access); var actual = toTest.buildKnownClassRowCM(1, Caleb_Wizard_Transmutation, ClassesLM.ToArray()); //Assert actual.Should().BeEquivalentTo(expected); } }