예제 #1
0
 public Concept(ConceptMapper mapper, DataAccess.DataAccess dac, int id_concept, int id_transaction, int id_product, int quantity) : this(mapper, dac)
 {
     this.id_concept     = id_concept;
     this.id_transaction = id_transaction;
     this.id_product     = id_product;
     this.quantity       = quantity;
 }
        public void Verify_MapToEntity_WithExistingEntity_AssignsConceptProperties()
        {
            // Arrange
            var mapper = new ConceptMapper();
            var model  = ConceptsMockingSetup.DoMockingSetupForConceptModel();
            // Act
            IConcept existingEntity = new Concept {
                Id = 1
            };

            mapper.MapToEntity(model.Object, ref existingEntity);
            // Assert
            Assert.Equal(model.Object.StartYear, existingEntity.StartYear);
            // Related Objects
            Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId);
            Assert.Equal(model.Object.FirstIssueAppearanceId, existingEntity.FirstIssueAppearanceId);
            // Associated Objects
            model.VerifyGet(x => x.ConceptAliases, Times.Once);
            //Assert.Equal(model.Object.ConceptAliases?.Count, existingEntity.ConceptAliases?.Count);
            model.VerifyGet(x => x.ConceptIssuesAppearedIn, Times.Once);
            //Assert.Equal(model.Object.ConceptIssuesAppearedIn?.Count, existingEntity.ConceptIssuesAppearedIn?.Count);
            model.VerifyGet(x => x.ConceptIssues, Times.Once);
            //Assert.Equal(model.Object.ConceptIssues?.Count, existingEntity.ConceptIssues?.Count);
            model.VerifyGet(x => x.ConceptMovies, Times.Once);
            //Assert.Equal(model.Object.ConceptMovies?.Count, existingEntity.ConceptMovies?.Count);
            model.VerifyGet(x => x.ConceptVolumes, Times.Once);
            //Assert.Equal(model.Object.ConceptVolumes?.Count, existingEntity.ConceptVolumes?.Count);
        }
예제 #3
0
        public IConceptModel Update(IConceptModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = ConceptsRepository.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 (ConceptMapper.AreEqual(model, existingEntity))
            {
                return(ConceptMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            ConceptMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            ConceptsRepository.Update(ConceptMapper.MapToEntity(model));
            // Try to Save Changes
            ConceptsRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
예제 #4
0
        public IConceptModel Create(IConceptModel 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(ConceptMapper.MapToSearchModel(model));

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            ConceptsRepository.Add(newEntity);
            // Try to Save Changes
            ConceptsRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
예제 #5
0
        public ConceptController()
        {
            string constr = GlobalData.connectionString;


            _dataAccess    = new DataAccess.DataAccess(constr);
            _conceptMapper = new ConceptMapper(_dataAccess);
        }
        public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse()
        {
            // Arrange
            var mapper = new ConceptMapper();
            var model  = ConceptsMockingSetup.DoMockingSetupForConceptModel(1);
            var entity = ConceptsMockingSetup.DoMockingSetupForConcept(2);
            // Act
            var result = mapper.AreEqual(model.Object, entity.Object);

            // Assert
            Assert.False(result);
        }
        public void Verify_MapToModelLite_AssignsLiteOnlyConceptProperties()
        {
            // Arrange
            var mapper = new ConceptMapper();
            var entity = ConceptsMockingSetup.DoMockingSetupForConcept();
            // Act
            var model = mapper.MapToModelLite(entity.Object);

            // Assert
            Assert.Equal(entity.Object.StartYear, model.StartYear);
            // Related Objects
            Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId);
            Assert.Equal(entity.Object.FirstIssueAppearanceId, model.FirstIssueAppearanceId);
        }
        public void Verify_MapToModel_AssignsConceptProperties()
        {
            // Arrange
            var mapper = new ConceptMapper();
            var entity = ConceptsMockingSetup.DoMockingSetupForConcept();
            // Act
            var model = mapper.MapToModel(entity.Object);

            // Assert
            Assert.Equal(entity.Object.StartYear, model.StartYear);
            // Related Objects
            Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId);
            Assert.Equal(entity.Object.FirstIssueAppearanceId, model.FirstIssueAppearanceId);
            // Associated Objects
            Assert.Equal(entity.Object.ConceptAliases?.Count, model.ConceptAliases?.Count);
            Assert.Equal(entity.Object.ConceptIssuesAppearedIn?.Count, model.ConceptIssuesAppearedIn?.Count);
            Assert.Equal(entity.Object.ConceptIssues?.Count, model.ConceptIssues?.Count);
            Assert.Equal(entity.Object.ConceptMovies?.Count, model.ConceptMovies?.Count);
            Assert.Equal(entity.Object.ConceptVolumes?.Count, model.ConceptVolumes?.Count);
        }
        public void Verify_MapToSearchModel_AssignsConceptSearchProperties()
        {
            // Arrange
            var mapper = new ConceptMapper();
            var model  = ConceptsMockingSetup.DoMockingSetupForConceptModel();
            // 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);
        }
 public void Verify_MapToSearchModel_AssignsConceptSearchProperties()
 {
     // Arrange
     var mapper = new ConceptMapper();
     var model = ConceptsMockingSetup.DoMockingSetupForConceptModel();
     // 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);
 }
 public void Verify_MapToModel_AssignsConceptProperties()
 {
     // Arrange
     var mapper = new ConceptMapper();
     var entity = ConceptsMockingSetup.DoMockingSetupForConcept();
     // Act
     var model = mapper.MapToModel(entity.Object);
     // Assert
     Assert.Equal(entity.Object.StartYear, model.StartYear);
     // Related Objects
     Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId);
     Assert.Equal(entity.Object.FirstIssueAppearanceId, model.FirstIssueAppearanceId);
     // Associated Objects
     Assert.Equal(entity.Object.ConceptAliases?.Count, model.ConceptAliases?.Count);
     Assert.Equal(entity.Object.ConceptIssuesAppearedIn?.Count, model.ConceptIssuesAppearedIn?.Count);
     Assert.Equal(entity.Object.ConceptIssues?.Count, model.ConceptIssues?.Count);
     Assert.Equal(entity.Object.ConceptMovies?.Count, model.ConceptMovies?.Count);
     Assert.Equal(entity.Object.ConceptVolumes?.Count, model.ConceptVolumes?.Count);
 }
 public void Verify_MapToModelLite_AssignsLiteOnlyConceptProperties()
 {
     // Arrange
     var mapper = new ConceptMapper();
     var entity = ConceptsMockingSetup.DoMockingSetupForConcept();
     // Act
     var model = mapper.MapToModelLite(entity.Object);
     // Assert
     Assert.Equal(entity.Object.StartYear, model.StartYear);
     // Related Objects
     Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId);
     Assert.Equal(entity.Object.FirstIssueAppearanceId, model.FirstIssueAppearanceId);
 }
예제 #13
0
 public IConceptModel Get(string key)
 {
     BusinessWorkflowBase.ValidateRequiredKey(key);
     return(ConceptMapper.MapToModel(ConceptsRepository.Get(key)));
 }
 public void Verify_AreEqual_WithEqualObjects_ReturnsTrue()
 {
     // Arrange
     var mapper = new ConceptMapper();
     var model = ConceptsMockingSetup.DoMockingSetupForConceptModel(1);
     var entity = ConceptsMockingSetup.DoMockingSetupForConcept(1);
     // Act
     var result = mapper.AreEqual(model.Object, entity.Object);
     // Assert
     Assert.True(result);
 }
예제 #15
0
 public Concept(ConceptMapper mapper, DataAccess.DataAccess dac)
 {
     _mapper     = mapper;
     _dataAccess = dac;
 }
 public void Verify_MapToEntity_WithExistingEntity_AssignsConceptProperties()
 {
     // Arrange
     var mapper = new ConceptMapper();
     var model = ConceptsMockingSetup.DoMockingSetupForConceptModel();
     // Act
     IConcept existingEntity = new Concept { Id = 1 };
     mapper.MapToEntity(model.Object, ref existingEntity);
     // Assert
     Assert.Equal(model.Object.StartYear, existingEntity.StartYear);
     // Related Objects
     Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId);
     Assert.Equal(model.Object.FirstIssueAppearanceId, existingEntity.FirstIssueAppearanceId);
     // Associated Objects
     model.VerifyGet(x => x.ConceptAliases, Times.Once);
     //Assert.Equal(model.Object.ConceptAliases?.Count, existingEntity.ConceptAliases?.Count);
     model.VerifyGet(x => x.ConceptIssuesAppearedIn, Times.Once);
     //Assert.Equal(model.Object.ConceptIssuesAppearedIn?.Count, existingEntity.ConceptIssuesAppearedIn?.Count);
     model.VerifyGet(x => x.ConceptIssues, Times.Once);
     //Assert.Equal(model.Object.ConceptIssues?.Count, existingEntity.ConceptIssues?.Count);
     model.VerifyGet(x => x.ConceptMovies, Times.Once);
     //Assert.Equal(model.Object.ConceptMovies?.Count, existingEntity.ConceptMovies?.Count);
     model.VerifyGet(x => x.ConceptVolumes, Times.Once);
     //Assert.Equal(model.Object.ConceptVolumes?.Count, existingEntity.ConceptVolumes?.Count);
 }
예제 #17
0
 public IConceptModel Get(int id)
 {
     BusinessWorkflowBase.ValidateRequiredID(id);
     return(ConceptMapper.MapToModel(ConceptsRepository.Get(id)));
 }