コード例 #1
0
        public IVolumeModel Create(IVolumeModel 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(VolumeMapper.MapToSearchModel(model));

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            VolumesRepository.Add(newEntity);
            // Try to Save Changes
            VolumesRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
コード例 #2
0
        public IVolumeModel Update(IVolumeModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = VolumesRepository.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 (VolumeMapper.AreEqual(model, existingEntity))
            {
                return(VolumeMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            VolumeMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            VolumesRepository.Update(VolumeMapper.MapToEntity(model));
            // Try to Save Changes
            VolumesRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
コード例 #3
0
        public void Verify_MapToEntity_AssignsVolumeProperties()
        {
            // Arrange
            var mapper = new VolumeMapper();
            var model  = VolumesMockingSetup.DoMockingSetupForVolumeModel();
            // Act
            var entity = mapper.MapToEntity(model.Object);

            // Assert
            Assert.Equal(model.Object.Startyear, entity.Startyear);
            // Related Objects
            Assert.Equal(model.Object.PrimaryImageFileId, entity.PrimaryImageFileId);
            Assert.Equal(model.Object.FirstIssueId, entity.FirstIssueId);
            Assert.Equal(model.Object.LastIssueId, entity.LastIssueId);
            Assert.Equal(model.Object.PublisherId, entity.PublisherId);
            // Associated Objects
            //Assert.Equal(model.Object.Issues?.Count, entity.Issues?.Count);
            model.VerifyGet(x => x.Issues, Times.Once);
            //Assert.Equal(model.Object.VolumeAliases?.Count, entity.VolumeAliases?.Count);
            model.VerifyGet(x => x.VolumeAliases, Times.Once);
            //Assert.Equal(model.Object.VolumeCharacters?.Count, entity.VolumeCharacters?.Count);
            model.VerifyGet(x => x.VolumeCharacters, Times.Once);
            //Assert.Equal(model.Object.VolumeConcepts?.Count, entity.VolumeConcepts?.Count);
            model.VerifyGet(x => x.VolumeConcepts, Times.Once);
            //Assert.Equal(model.Object.VolumeLocations?.Count, entity.VolumeLocations?.Count);
            model.VerifyGet(x => x.VolumeLocations, Times.Once);
            //Assert.Equal(model.Object.VolumeObjects?.Count, entity.VolumeObjects?.Count);
            model.VerifyGet(x => x.VolumeObjects, Times.Once);
            //Assert.Equal(model.Object.VolumeTeams?.Count, entity.VolumeTeams?.Count);
            model.VerifyGet(x => x.VolumeTeams, Times.Once);
            //Assert.Equal(model.Object.VolumeWriters?.Count, entity.VolumeWriters?.Count);
            model.VerifyGet(x => x.VolumeWriters, Times.Once);
        }
コード例 #4
0
 public void Verify_MapToEntity_WithExistingEntity_AssignsVolumeProperties()
 {
     // Arrange
     var mapper = new VolumeMapper();
     var model = VolumesMockingSetup.DoMockingSetupForVolumeModel();
     // Act
     IVolume existingEntity = new Volume { 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.FirstIssueId, existingEntity.FirstIssueId);
     Assert.Equal(model.Object.LastIssueId, existingEntity.LastIssueId);
     Assert.Equal(model.Object.PublisherId, existingEntity.PublisherId);
     // Associated Objects
     model.VerifyGet(x => x.Issues, Times.Once);
     //Assert.Equal(model.Object.Issues?.Count, existingEntity.Issues?.Count);
     model.VerifyGet(x => x.VolumeAliases, Times.Once);
     //Assert.Equal(model.Object.VolumeAliases?.Count, existingEntity.VolumeAliases?.Count);
     model.VerifyGet(x => x.VolumeCharacters, Times.Once);
     //Assert.Equal(model.Object.VolumeCharacters?.Count, existingEntity.VolumeCharacters?.Count);
     model.VerifyGet(x => x.VolumeConcepts, Times.Once);
     //Assert.Equal(model.Object.VolumeConcepts?.Count, existingEntity.VolumeConcepts?.Count);
     model.VerifyGet(x => x.VolumeLocations, Times.Once);
     //Assert.Equal(model.Object.VolumeLocations?.Count, existingEntity.VolumeLocations?.Count);
     model.VerifyGet(x => x.VolumeObjects, Times.Once);
     //Assert.Equal(model.Object.VolumeObjects?.Count, existingEntity.VolumeObjects?.Count);
     model.VerifyGet(x => x.VolumeTeams, Times.Once);
     //Assert.Equal(model.Object.VolumeTeams?.Count, existingEntity.VolumeTeams?.Count);
     model.VerifyGet(x => x.VolumeWriters, Times.Once);
     //Assert.Equal(model.Object.VolumeWriters?.Count, existingEntity.VolumeWriters?.Count);
 }