public ICharacterAppearedInIssueModel Create(ICharacterAppearedInIssueModel 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(CharacterAppearedInIssueMapper.MapToSearchModel(model));

            if (results.Any())
            {
                return(results.First());
            }                                              // Return the first that matches
            // Map model to a new entity
            var newEntity = CharacterAppearedInIssueMapper.MapToEntity(model);

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            CharacterAppearedInIssuesRepository.Add(newEntity);
            // Try to Save Changes
            CharacterAppearedInIssuesRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
Ejemplo n.º 2
0
        public void Verify_MapToSearchModel_AssignsCharacterAppearedInIssueSearchProperties()
        {
            // Arrange
            var mapper = new CharacterAppearedInIssueMapper();
            var model  = CharacterAppearedInIssuesMockingSetup.DoMockingSetupForCharacterAppearedInIssueModel();
            // Act
            var searchModel = mapper.MapToSearchModel(model.Object);

            // Assert
            Assert.Equal(model.Object.CharacterId, searchModel.CharacterId);
            Assert.Equal(model.Object.Character?.CustomKey, searchModel.CharacterCustomKey);
            Assert.Equal(model.Object.Character?.ApiDetailUrl, searchModel.CharacterApiDetailUrl);
            Assert.Equal(model.Object.Character?.SiteDetailUrl, searchModel.CharacterSiteDetailUrl);
            Assert.Equal(model.Object.Character?.Name, searchModel.CharacterName);
            Assert.Equal(model.Object.Character?.ShortDescription, searchModel.CharacterShortDescription);
            Assert.Equal(model.Object.Character?.Description, searchModel.CharacterDescription);
            Assert.Equal(model.Object.AppearedInIssueId, searchModel.AppearedInIssueId);
            Assert.Equal(model.Object.AppearedInIssue?.CustomKey, searchModel.AppearedInIssueCustomKey);
            Assert.Equal(model.Object.AppearedInIssue?.ApiDetailUrl, searchModel.AppearedInIssueApiDetailUrl);
            Assert.Equal(model.Object.AppearedInIssue?.SiteDetailUrl, searchModel.AppearedInIssueSiteDetailUrl);
            Assert.Equal(model.Object.AppearedInIssue?.Name, searchModel.AppearedInIssueName);
            Assert.Equal(model.Object.AppearedInIssue?.ShortDescription, searchModel.AppearedInIssueShortDescription);
            Assert.Equal(model.Object.AppearedInIssue?.Description, searchModel.AppearedInIssueDescription);
        }