public void Verify_MapToModel_AssignsCharacterProperties() { // Arrange var mapper = new CharacterMapper(); var entity = CharactersMockingSetup.DoMockingSetupForCharacter(); // Act var model = mapper.MapToModel(entity.Object); // Assert Assert.Equal(entity.Object.RealName, model.RealName); Assert.Equal(entity.Object.DateOfBirth, model.DateOfBirth); // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); Assert.Equal(entity.Object.FirstIssueAppearanceId, model.FirstIssueAppearanceId); Assert.Equal(entity.Object.GenderId, model.GenderId); Assert.Equal(entity.Object.OriginId, model.OriginId); Assert.Equal(entity.Object.PublisherId, model.PublisherId); // Associated Objects Assert.Equal(entity.Object.CharacterAliases?.Count, model.CharacterAliases?.Count); Assert.Equal(entity.Object.CharacterCreators?.Count, model.CharacterCreators?.Count); Assert.Equal(entity.Object.CharacterEnemies?.Count, model.CharacterEnemies?.Count); Assert.Equal(entity.Object.CharacterEnemyTeams?.Count, model.CharacterEnemyTeams?.Count); Assert.Equal(entity.Object.CharacterFriends?.Count, model.CharacterFriends?.Count); Assert.Equal(entity.Object.CharacterFriendlyTeams?.Count, model.CharacterFriendlyTeams?.Count); Assert.Equal(entity.Object.CharacterIssuesAppearedIn?.Count, model.CharacterIssuesAppearedIn?.Count); Assert.Equal(entity.Object.CharacterIssuesDiedIn?.Count, model.CharacterIssuesDiedIn?.Count); Assert.Equal(entity.Object.CharacterIssues?.Count, model.CharacterIssues?.Count); Assert.Equal(entity.Object.CharacterMovies?.Count, model.CharacterMovies?.Count); Assert.Equal(entity.Object.CharacterPowers?.Count, model.CharacterPowers?.Count); Assert.Equal(entity.Object.CharacterStoryArcs?.Count, model.CharacterStoryArcs?.Count); Assert.Equal(entity.Object.CharacterTeams?.Count, model.CharacterTeams?.Count); Assert.Equal(entity.Object.CharacterVolumes?.Count, model.CharacterVolumes?.Count); }
public ICharacterModel Update(ICharacterModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = CharactersRepository.Get(model.Id.Value); // Check if we would be applying identical information, if we are, just return the original // ReSharper disable once SuspiciousTypeConversion.Global if (CharacterMapper.AreEqual(model, existingEntity)) { return(CharacterMapper.MapToModel(existingEntity)); } // Map model to an existing entity CharacterMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it CharactersRepository.Update(CharacterMapper.MapToEntity(model)); // Try to Save Changes CharactersRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public void CharacterServices_buildKnownSpellRowCM_ValidCall() { //Arrange List <Spell> spells = CreateTestData.GetListOfSpells(); var mockSet = new Mock <DbSet <Spell> >() .SetupData(spells, o => { return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0)); }); var record = CreateTestData.GetSampleSpell(); KnownSpellRowCM expected = CharacterMapper.mapSpellToKnownSpellRowCM(record); expected.Index = 1; using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <SpellsContext>() .Setup(x => x.Set <Spell>()).Returns(mockSet.Object); mockContext.Mock <SpellsContext>() .Setup(x => x.Spells).Returns(mockSet.Object); IUnitOfWork uow = UoW_Factory.getUnitofWork(mockContext); IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow); var creator = ProcessorFactory.getCreateCharacterProcessor(access); var updater = ProcessorFactory.getUpdateCharacterProcessor(access); var builder = ProcessorFactory.GetCharacterCMBuilder(access); //Act var toTest = ServicesFactory.GetCharacterService(creator, updater, builder); var actual = toTest.buildKnownSpellRowCM(1, record.Spell_id); } }
public FullCharacterDTO Get(string playerName, string characterId) { var resp = new HttpResponseMessage(); try { var character = _characterRepository.Get(characterId); if (character == null) { resp.StatusCode = HttpStatusCode.NotFound; resp.Content = new StringContent(string.Format("Character not found with Id = {0}", characterId)); resp.ReasonPhrase = "Character Not Found"; throw new HttpResponseException(resp); } if (character.PlayerAccountName != playerName) { resp.StatusCode = HttpStatusCode.Conflict; resp.Content = new StringContent(string.Format("Character found but is not associated with the given player Id")); resp.ReasonPhrase = "Mismatch character Id and player Id"; throw new HttpResponseException(resp); } var characterDTO = CharacterMapper.FullDTOFromCharacter(character); return(characterDTO); } catch (Exception ex) { throw ex; } }
public void CharacterSerivces_buildHeldItemRowCM_ValidCall() { List <Item> items = CreateTestData.GetListOfItems(); var itemsMockSet = new Mock <DbSet <Item> >() .SetupData(items, o => { return(items.Single(x => x.Item_id.CompareTo(o.First()) == 0)); }); HeldItemRowCM expected = CharacterMapper.mapItemToHeldItemRowCM(CreateTestData.GetSampleItem()); Item record = CreateTestData.GetSampleItem(); expected.Count = 1; expected.isAttuned = false; expected.isEquipped = false; expected.Index = 1; using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <ItemsContext>() .Setup(x => x.Set <Item>()).Returns(itemsMockSet.Object); mockContext.Mock <ItemsContext>() .Setup(x => x.Items).Returns(itemsMockSet.Object); IUnitOfWork uow = UoW_Factory.getUnitofWork(mockContext); IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow); var creator = ProcessorFactory.getCreateCharacterProcessor(access); var updater = ProcessorFactory.getUpdateCharacterProcessor(access); var builder = ProcessorFactory.GetCharacterCMBuilder(access); //Act var toTest = ServicesFactory.GetCharacterService(creator, updater, builder); var actual = toTest.buildHeldItemRowCM(1, record.Item_id); actual.Should().BeEquivalentTo(expected); } }
public void GivenThatCharacterIsNull_WhenTryingToMapIt_ThenArgumentNullExceptionIsThrown() { var urlHelper = CreateUrlHelper("http://localhost/api/characters/1"); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(null, urlHelper); }
public ICharacterModel Create(ICharacterModel model) { // Validate model BusinessWorkflowBase.ValidateIDIsNull(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Search for an Existing Record (Don't allow Duplicates var results = Search(CharacterMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = CharacterMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it CharactersRepository.Add(newEntity); // Try to Save Changes CharactersRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public async Task <IActionResult> Edit(int Id) { Character character = await _characterServices.GetCharacterAsync(Id); CharacterViewModel mapCharacter = CharacterMapper.MapCharacter(character); return(View("Edit", mapCharacter)); }
public KnownSpellRowCM buildKnownSpellRowCM(Guid Spell_id) { Spell foundSpell = _userAccess.GetSpell(Spell_id); KnownSpellRowCM cm = CharacterMapper.mapSpellToKnownSpellRowCM(foundSpell); cm.School = _userAccess.GetSchool(foundSpell.School_id).Name; return(cm); }
// Busines logic goes here protected void EnsureStatsListExists() { // protection from null references exceptions if (null == stats) { stats = (IsNew || 0 == id) ? new List <Stat>() : CharacterMapper.LoadStats(this).ToList(); } }
public HeldItemRowCM buildExistingHeldItemRowCM(Guid Character_id, Guid Item_id) { Item foundItem = _userAccess.GetItem(Item_id); HeldItemRowCM cm = CharacterMapper.mapItemToHeldItemRowCM(foundItem); Character_Item foundHeldItem = _userAccess.GetHeldItemRecord(Character_id, Item_id); CharacterMapper.mapHeldItemRecordToHeldItemRowCM(foundHeldItem, cm); return(cm); }
public void GivenThatUrlHelperIsNull_WhenTryingToMapCharacter_ThenArgumentNullExceptionIsThrown() { var character = MockRepository.GenerateMock <ICharacter>(); character.Stub(x => x.Identifier).Return(1); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(character, null); }
public void CharacterMapper_MapNoteCMToNewEntity() { NoteCM cm = new NoteCM(); cm.Name = "Backstory"; Note actual = CharacterMapper.mapNoteCMToNewEntity(cm); actual.Name.Should().Be(cm.Name); }
public void CharacterMapper_MapMoneyCMToNewEntity() { MoneyCM cm = new MoneyCM(); cm.GoldPieces = 50; Currency actual = CharacterMapper.mapCurrencyCMToNewEntity(cm); actual.GoldPieces.Should().Be(cm.GoldPieces); }
public void CharacterMapper_MapStatsCMToNewEntity() { StatsCM cm = new StatsCM(); cm.Strength = 14; Stats actual = CharacterMapper.mapStatsCMToNewEntity(cm); actual.Strength.Should().Be(cm.Strength); }
public void CharacterMapper_MapCombatCMToHealthRecord() { CombatCM cm = new CombatCM(); cm.MaxHP = 50; Health actual = CharacterMapper.mapCombatCMToNewHealthEntity(cm); actual.MaxHP.Should().Be(cm.MaxHP); }
public CharacterHandler(ICharacterRepository characterRepository, ICharacterQueryRepository characterQueryRepository) { _characterRepository = characterRepository; _characterQueryRepository = characterQueryRepository; _mapper = new CharacterMapper(); _createCharacterCommandValidator = new CreateCharacterCommandValidator(); _updateCharacterCommandValidator = new UpdateCharacterCommandValidator(); _deleteByIdCommandValidator = new DeleteByIdCommandValidator(); _getListQueryValidator = new GetListQueryValidator(); }
private void SetNotes(IEnumerable <NoteCM> notes, Guid Character_id) { foreach (NoteCM note in notes) { Note noteRecord = CharacterMapper.mapNoteCMToNewEntity(note); noteRecord.Character_id = Character_id; noteRecord.Note_id = Guid.NewGuid(); _userAccess.AddNote(noteRecord); } }
public void GivenThatCharacterHasCulture_WhenTryingToMapCharacter_ThenMappedCharacterHasSameCulture() { var character = MockRepository.GenerateMock<ICharacter>(); character.Stub(x => x.Identifier).Return(1); character.Stub(x => x.Culture).Return("testCulture"); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1")); Assert.AreEqual(character.Culture, mappedCharacter.Culture); }
public HeldItemRowCM buildNewHeldItemRowCM(Guid item_id) { Item foundItem = _userAccess.GetItem(item_id); HeldItemRowCM cm = CharacterMapper.mapItemToHeldItemRowCM(foundItem); cm.isAttuned = false; cm.isEquipped = false; cm.Count = 1; return(cm); }
public void GivenThatCharacterHasIdentifierOfOne_WhenTryingToMapCharacter_ThenMappedCharacterUrlIsCorrectWithIdentifierInIt() { var character = MockRepository.GenerateMock <ICharacter>(); character.Stub(x => x.Identifier).Return(1); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1")); Assert.AreEqual("http://localhost/api/characters/1", mappedCharacter.URL); }
public void GivenThatCharacterHasAliases_WhenTryingToMapCharacter_ThenMappedCharacterHasSameAliases() { var character = MockRepository.GenerateMock<ICharacter>(); character.Stub(x => x.Identifier).Return(1); character.Stub(x => x.Aliases).Return(new List<string> { "firstAlias", }); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1")); Assert.AreEqual(character.Aliases.Count, mappedCharacter.Aliases.Count()); Assert.AreEqual(character.Aliases.ElementAt(0), mappedCharacter.Aliases.ElementAt(0)); }
public void CharacterMapper_MapNoteToNoteCM_ValidCall() { //Arrange var record = CreateTestData.GetSampleNote(); var actual = new NoteCM(); //Act actual = CharacterMapper.mapNoteToNoteCM(record); actual.Should().BeEquivalentTo(record, options => options.Excluding(o => o.Character_id)); }
public void GivenThatCharacterHasCulture_WhenTryingToMapCharacter_ThenMappedCharacterHasSameCulture() { var character = MockRepository.GenerateMock <ICharacter>(); character.Stub(x => x.Identifier).Return(1); character.Stub(x => x.Culture).Return("testCulture"); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1")); Assert.AreEqual(character.Culture, mappedCharacter.Culture); }
public void GivenThatCharacterIsDead_WhenTryingToMapCharacter_ThenMappedCharacterHasSameDiedData() { var character = MockRepository.GenerateMock <ICharacter>(); character.Stub(x => x.Identifier).Return(1); character.Stub(x => x.Died).Return("someYear"); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1")); Assert.AreEqual(character.Died, mappedCharacter.Died); }
public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse() { // Arrange var mapper = new CharacterMapper(); var model = CharactersMockingSetup.DoMockingSetupForCharacterModel(1); var entity = CharactersMockingSetup.DoMockingSetupForCharacter(2); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.False(result); }
public SpellDetailsCM buildSpellDetailsCM(Guid Spell_id) { Spell foundSpell = _userAccess.GetSpell(Spell_id); SpellDetailsCM cm = CharacterMapper.mapSpellToSpellDetailsCM(foundSpell); cm.School = _userAccess.GetSchool(foundSpell.School_id).Name; if (foundSpell.RequiresMaterial == true) { cm.Material = _userAccess.GetSpellMaterials(Spell_id).materials; } return(cm); }
public void CharacterMapper_MapIsProficientToIsProficientCM_ValidCall() { //Arrange var record = CreateTestData.GetSampleIsProficient(); var actual = new IsProficientCM(); //Act actual = CharacterMapper.mapIsProficientToIsProficientCM(record); //Assert actual.Should().BeEquivalentTo(record, options => options.Excluding(o => o.Character_id)); }
public Mapper() { _accountMapper = new AccountMapper(); _bazaarItemMapper = new BazaarItemMapper(); _bCardMapper = new BCardMapper(); _boxItemMapper = new ItemInstanceMapper(); _cardMapper = new CardMapper(); _cellonOptionMapper = new CellonOptionMapper(); _characterMapper = new CharacterMapper(); _characterRelationMapper = new CharacterRelationMapper(); _characterSkillMapper = new CharacterSkillMapper(); _comboMapper = new ComboMapper(); _dropMapper = new DropMapper(); _familyCharacterMapper = new FamilyCharacterMapper(); _familyLogMapper = new FamilyLogMapper(); _familyMapper = new FamilyMapper(); _generalLogMapper = new GeneralLogMapper(); _itemInstanceMapper = new ItemInstanceMapper(); _itemMapper = new ItemMapper(); _mailMapper = new MailMapper(); _maintenanceLogMapper = new MaintenanceLogMapper(); _mapMapper = new MapMapper(); _mapMonsterMapper = new MapMonsterMapper(); _mapNPCMapper = new MapNPCMapper(); _mapTypeMapMapper = new MapTypeMapMapper(); _mapTypeMapper = new MapTypeMapper(); _mateMapper = new MateMapper(); _minilandObjectMapper = new MinilandObjectMapper(); _npcMonsterMapper = new NpcMonsterMapper(); _npcMonsterSkillMapper = new NpcMonsterSkillMapper(); _penaltyLogMapper = new PenaltyLogMapper(); _portalMapper = new PortalMapper(); _questMapper = new QuestMapper(); _questProgressMapper = new QuestProgressMapper(); _quicklistEntryMapper = new QuicklistEntryMapper(); _recipeItemMapper = new RecipeItemMapper(); _recipeListMapper = new RecipeListMapper(); _recipeMapper = new RecipeMapper(); _respawnMapper = new RespawnMapper(); _respawnMapTypeMapper = new RespawnMapTypeMapper(); _rollGeneratedItemMapper = new RollGeneratedItemMapper(); _scriptedInstanceMapper = new ScriptedInstanceMapper(); _shellEffectMapper = new ShellEffectMapper(); _shopItemMapper = new ShopItemMapper(); _shopMapper = new ShopMapper(); _shopSkillMapper = new ShopSkillMapper(); _skillMapper = new SkillMapper(); _staticBonusMapper = new StaticBonusMapper(); _staticBuffMapper = new StaticBuffMapper(); _teleporterMapper = new TeleporterMapper(); }
public async Task <IActionResult> Index(int?currentPage, string search = null) { try { string userId = FindCurrentUserId(); int currPage = currentPage ?? 1; int totalPages = await _characterServices.GetPageCount(); IEnumerable <Character> characterAllResults = null; if (!string.IsNullOrEmpty(search)) { //For character search characterAllResults = await _characterServices.SearchCharacter(search, currPage, userId); } else { characterAllResults = await _characterServices.GetAllUserCharactersAsync(currPage, userId); } IEnumerable <CharacterViewModel> characterListing = characterAllResults .Select(m => CharacterMapper.MapCharacter(m)); CharacterIndexViewModel characterIVM = CharacterMapper.MapFromCharacterIndex(characterListing, currPage, totalPages); #region For pagination buttons and distribution characterIVM.CurrentPage = currPage; characterIVM.TotalPages = totalPages; if (totalPages > currPage) { characterIVM.NextPage = currPage + 1; } if (currPage > 1) { characterIVM.PreviousPage = currPage - 1; } #endregion return(View(characterIVM)); } catch (GlobalException e) { //TODO return(BadRequest(e.Message)); //ModelState.AddModelError(string.Empty, ExceptionMessage.GlobalErrorMessage); //return RedirectToAction("Index", "Home"); } }
public void GivenThatCharacterHasAllegiance_WhenTryingToMapCharacter_ThenMappedCharacterAllegiancesContainsCorrectUrls() { var house = MockRepository.GenerateMock<IHouse>(); house.Stub(x => x.Identifier).Return(1); var character = MockRepository.GenerateMock<ICharacter>(); character.Stub(x => x.Allegiances).Return(new List<IHouse> { house }); character.Stub(x => x.Identifier).Return(1); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1")); Assert.AreEqual(1, mappedCharacter.Allegiances.Count()); Assert.AreEqual("http://localhost/api/houses/1", mappedCharacter.Allegiances.ElementAt(0)); }
public void Verify_MapToEntity_WithExistingEntity_AssignsCharacterProperties() { // Arrange var mapper = new CharacterMapper(); var model = CharactersMockingSetup.DoMockingSetupForCharacterModel(); // Act ICharacter existingEntity = new Character { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert Assert.Equal(model.Object.RealName, existingEntity.RealName); Assert.Equal(model.Object.DateOfBirth, existingEntity.DateOfBirth); // Related Objects Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId); Assert.Equal(model.Object.FirstIssueAppearanceId, existingEntity.FirstIssueAppearanceId); Assert.Equal(model.Object.GenderId, existingEntity.GenderId); Assert.Equal(model.Object.OriginId, existingEntity.OriginId); Assert.Equal(model.Object.PublisherId, existingEntity.PublisherId); // Associated Objects model.VerifyGet(x => x.CharacterAliases, Times.Once); //Assert.Equal(model.Object.CharacterAliases?.Count, existingEntity.CharacterAliases?.Count); model.VerifyGet(x => x.CharacterCreators, Times.Once); //Assert.Equal(model.Object.CharacterCreators?.Count, existingEntity.CharacterCreators?.Count); model.VerifyGet(x => x.CharacterEnemies, Times.Once); //Assert.Equal(model.Object.CharacterEnemies?.Count, existingEntity.CharacterEnemies?.Count); model.VerifyGet(x => x.CharacterEnemyTeams, Times.Once); //Assert.Equal(model.Object.CharacterEnemyTeams?.Count, existingEntity.CharacterEnemyTeams?.Count); model.VerifyGet(x => x.CharacterFriends, Times.Once); //Assert.Equal(model.Object.CharacterFriends?.Count, existingEntity.CharacterFriends?.Count); model.VerifyGet(x => x.CharacterFriendlyTeams, Times.Once); //Assert.Equal(model.Object.CharacterFriendlyTeams?.Count, existingEntity.CharacterFriendlyTeams?.Count); model.VerifyGet(x => x.CharacterIssuesAppearedIn, Times.Once); //Assert.Equal(model.Object.CharacterIssuesAppearedIn?.Count, existingEntity.CharacterIssuesAppearedIn?.Count); model.VerifyGet(x => x.CharacterIssuesDiedIn, Times.Once); //Assert.Equal(model.Object.CharacterIssuesDiedIn?.Count, existingEntity.CharacterIssuesDiedIn?.Count); model.VerifyGet(x => x.CharacterIssues, Times.Once); //Assert.Equal(model.Object.CharacterIssues?.Count, existingEntity.CharacterIssues?.Count); model.VerifyGet(x => x.CharacterMovies, Times.Once); //Assert.Equal(model.Object.CharacterMovies?.Count, existingEntity.CharacterMovies?.Count); model.VerifyGet(x => x.CharacterPowers, Times.Once); //Assert.Equal(model.Object.CharacterPowers?.Count, existingEntity.CharacterPowers?.Count); model.VerifyGet(x => x.CharacterStoryArcs, Times.Once); //Assert.Equal(model.Object.CharacterStoryArcs?.Count, existingEntity.CharacterStoryArcs?.Count); model.VerifyGet(x => x.CharacterTeams, Times.Once); //Assert.Equal(model.Object.CharacterTeams?.Count, existingEntity.CharacterTeams?.Count); model.VerifyGet(x => x.CharacterVolumes, Times.Once); //Assert.Equal(model.Object.CharacterVolumes?.Count, existingEntity.CharacterVolumes?.Count); }
public void GivenThatCharacterHasBooks_WhenTryingToMapCharacter_ThenMappedCharacterBooksContainsCorrectUrls() { var book = MockRepository.GenerateMock<IBook>(); book.Stub(x => x.Identifier).Return(10); var characer = MockRepository.GenerateMock<ICharacter>(); characer.Stub(x => x.Identifier).Return(1); characer.Stub(x => x.Books).Return(new List<IBook> { book }); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(characer, CreateUrlHelper("http://localhost/api/characters/1")); Assert.AreEqual(1, mappedCharacter.Books.Count()); Assert.AreEqual("http://localhost/api/books/10", mappedCharacter.Books.ElementAt(0)); }
public CharacterCreationViewController( ICharacterCreationView view, ICharacterDataRepository characterDataRepository, IBackgroundRepository backgroundRepository, ICharacterRepository characterRepository, CharacterMapper characterMapper, CharacterManager characterManager) : base(view) { this.characterDataRepository = characterDataRepository; this.backgroundRepository = backgroundRepository; this.characterRepository = characterRepository; this.characterMapper = characterMapper; this.characterManager = characterManager; }
public void Verify_MapToSearchModel_AssignsCharacterSearchProperties() { // Arrange var mapper = new CharacterMapper(); var model = CharactersMockingSetup.DoMockingSetupForCharacterModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert Assert.Equal(model.Object.PrimaryImageFileId, searchModel.PrimaryImageFileId); Assert.Equal(model.Object.PrimaryImageFile?.CustomKey, searchModel.PrimaryImageFileCustomKey); Assert.Equal(model.Object.PrimaryImageFile?.ApiDetailUrl, searchModel.PrimaryImageFileApiDetailUrl); Assert.Equal(model.Object.PrimaryImageFile?.SiteDetailUrl, searchModel.PrimaryImageFileSiteDetailUrl); Assert.Equal(model.Object.PrimaryImageFile?.Name, searchModel.PrimaryImageFileName); Assert.Equal(model.Object.PrimaryImageFile?.ShortDescription, searchModel.PrimaryImageFileShortDescription); Assert.Equal(model.Object.PrimaryImageFile?.Description, searchModel.PrimaryImageFileDescription); Assert.Equal(model.Object.FirstIssueAppearanceId, searchModel.FirstIssueAppearanceId); Assert.Equal(model.Object.FirstIssueAppearance?.CustomKey, searchModel.FirstIssueAppearanceCustomKey); Assert.Equal(model.Object.FirstIssueAppearance?.ApiDetailUrl, searchModel.FirstIssueAppearanceApiDetailUrl); Assert.Equal(model.Object.FirstIssueAppearance?.SiteDetailUrl, searchModel.FirstIssueAppearanceSiteDetailUrl); Assert.Equal(model.Object.FirstIssueAppearance?.Name, searchModel.FirstIssueAppearanceName); Assert.Equal(model.Object.FirstIssueAppearance?.ShortDescription, searchModel.FirstIssueAppearanceShortDescription); Assert.Equal(model.Object.FirstIssueAppearance?.Description, searchModel.FirstIssueAppearanceDescription); Assert.Equal(model.Object.GenderId, searchModel.GenderId); Assert.Equal(model.Object.Gender?.CustomKey, searchModel.GenderCustomKey); Assert.Equal(model.Object.Gender?.ApiDetailUrl, searchModel.GenderApiDetailUrl); Assert.Equal(model.Object.Gender?.SiteDetailUrl, searchModel.GenderSiteDetailUrl); Assert.Equal(model.Object.Gender?.Name, searchModel.GenderName); Assert.Equal(model.Object.Gender?.ShortDescription, searchModel.GenderShortDescription); Assert.Equal(model.Object.Gender?.Description, searchModel.GenderDescription); Assert.Equal(model.Object.OriginId, searchModel.OriginId); Assert.Equal(model.Object.Origin?.CustomKey, searchModel.OriginCustomKey); Assert.Equal(model.Object.Origin?.ApiDetailUrl, searchModel.OriginApiDetailUrl); Assert.Equal(model.Object.Origin?.SiteDetailUrl, searchModel.OriginSiteDetailUrl); Assert.Equal(model.Object.Origin?.Name, searchModel.OriginName); Assert.Equal(model.Object.Origin?.ShortDescription, searchModel.OriginShortDescription); Assert.Equal(model.Object.Origin?.Description, searchModel.OriginDescription); Assert.Equal(model.Object.PublisherId, searchModel.PublisherId); Assert.Equal(model.Object.Publisher?.CustomKey, searchModel.PublisherCustomKey); Assert.Equal(model.Object.Publisher?.ApiDetailUrl, searchModel.PublisherApiDetailUrl); Assert.Equal(model.Object.Publisher?.SiteDetailUrl, searchModel.PublisherSiteDetailUrl); Assert.Equal(model.Object.Publisher?.Name, searchModel.PublisherName); Assert.Equal(model.Object.Publisher?.ShortDescription, searchModel.PublisherShortDescription); Assert.Equal(model.Object.Publisher?.Description, searchModel.PublisherDescription); Assert.Equal(model.Object.RealName, searchModel.RealName); }
public void Verify_MapToModelLite_AssignsLiteOnlyCharacterProperties() { // Arrange var mapper = new CharacterMapper(); var entity = CharactersMockingSetup.DoMockingSetupForCharacter(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert Assert.Equal(entity.Object.RealName, model.RealName); Assert.Equal(entity.Object.DateOfBirth, model.DateOfBirth); // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); Assert.Equal(entity.Object.FirstIssueAppearanceId, model.FirstIssueAppearanceId); Assert.Equal(entity.Object.GenderId, model.GenderId); Assert.Equal(entity.Object.OriginId, model.OriginId); Assert.Equal(entity.Object.PublisherId, model.PublisherId); }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new CharacterMapper(); var model = CharactersMockingSetup.DoMockingSetupForCharacterModel(1); var entity = CharactersMockingSetup.DoMockingSetupForCharacter(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }
public void GivenThatCharacterHasIdentifierOfOne_WhenTryingToMapCharacter_ThenMappedCharacterUrlIsCorrectWithIdentifierInIt() { var character = MockRepository.GenerateMock<ICharacter>(); character.Stub(x => x.Identifier).Return(1); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1")); Assert.AreEqual("http://localhost/api/characters/1", mappedCharacter.URL); }
public void GivenThatCharacterWasBorn_WhenTryingToMapCharacter_ThenMappedCharacterHasSameBornData() { var character = MockRepository.GenerateMock<ICharacter>(); character.Stub(x => x.Identifier).Return(1); character.Stub(x => x.Born).Return("someYear"); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1")); Assert.AreEqual(character.Born, mappedCharacter.Born); }
public void GivenThatUrlHelperIsNull_WhenTryingToMapCharacter_ThenArgumentNullExceptionIsThrown() { var character = MockRepository.GenerateMock<ICharacter>(); character.Stub(x => x.Identifier).Return(1); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(character, null); }
public void GivenThatCharacterHasFather_WhenTryingToMapCharacter_ThenMappedCharacterFatherContainsCorrectUrl() { var father = MockRepository.GenerateMock<ICharacter>(); father.Stub(x => x.Identifier).Return(2); var character = MockRepository.GenerateMock<ICharacter>(); character.Stub(x => x.Identifier).Return(1); character.Stub(x => x.Father).Return(father); var mapper = new CharacterMapper(); var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1")); Assert.AreEqual($"http://localhost/api/characters/{character.Father.Identifier}", mappedCharacter.Father); }