Esempio n. 1
0
        public void Verify_MapToEntity_WithExistingEntity_AssignsSeriesProperties()
        {
            // Arrange
            var mapper = new SeriesMapper();
            var model  = SeriesMockingSetup.DoMockingSetupForSeriesModel();
            // Act
            ISeries existingEntity = new Series {
                Id = 1
            };

            mapper.MapToEntity(model.Object, ref existingEntity);
            // Assert
            Assert.Equal(model.Object.Startyear, existingEntity.Startyear);
            // Related Objects
            Assert.Equal(model.Object.PublisherId, existingEntity.PublisherId);
            Assert.Equal(model.Object.FirstEpisodeId, existingEntity.FirstEpisodeId);
            Assert.Equal(model.Object.LastEpisodeId, existingEntity.LastEpisodeId);
            // Associated Objects
            model.VerifyGet(x => x.Episodes, Times.Once);
            //Assert.Equal(model.Object.Episodes?.Count, existingEntity.Episodes?.Count);
            model.VerifyGet(x => x.SeriesAliases, Times.Once);
            //Assert.Equal(model.Object.SeriesAliases?.Count, existingEntity.SeriesAliases?.Count);
            model.VerifyGet(x => x.SeriesCharacters, Times.Once);
            //Assert.Equal(model.Object.SeriesCharacters?.Count, existingEntity.SeriesCharacters?.Count);
            model.VerifyGet(x => x.SeriesLocations, Times.Once);
            //Assert.Equal(model.Object.SeriesLocations?.Count, existingEntity.SeriesLocations?.Count);
        }
Esempio n. 2
0
        public ISeriesModel Update(ISeriesModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = SeriesRepository.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 (SeriesMapper.AreEqual(model, existingEntity))
            {
                return(SeriesMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            SeriesMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            SeriesRepository.Update(SeriesMapper.MapToEntity(model));
            // Try to Save Changes
            SeriesRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
Esempio n. 3
0
        public ISeriesModel Create(ISeriesModel 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(SeriesMapper.MapToSearchModel(model));

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            SeriesRepository.Add(newEntity);
            // Try to Save Changes
            SeriesRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
 public void Verify_MapToEntity_WithExistingEntity_AssignsSeriesProperties()
 {
     // Arrange
     var mapper = new SeriesMapper();
     var model = SeriesMockingSetup.DoMockingSetupForSeriesModel();
     // Act
     ISeries existingEntity = new Series { Id = 1 };
     mapper.MapToEntity(model.Object, ref existingEntity);
     // Assert
     Assert.Equal(model.Object.Startyear, existingEntity.Startyear);
     // Related Objects
     Assert.Equal(model.Object.PublisherId, existingEntity.PublisherId);
     Assert.Equal(model.Object.FirstEpisodeId, existingEntity.FirstEpisodeId);
     Assert.Equal(model.Object.LastEpisodeId, existingEntity.LastEpisodeId);
     // Associated Objects
     model.VerifyGet(x => x.Episodes, Times.Once);
     //Assert.Equal(model.Object.Episodes?.Count, existingEntity.Episodes?.Count);
     model.VerifyGet(x => x.SeriesAliases, Times.Once);
     //Assert.Equal(model.Object.SeriesAliases?.Count, existingEntity.SeriesAliases?.Count);
     model.VerifyGet(x => x.SeriesCharacters, Times.Once);
     //Assert.Equal(model.Object.SeriesCharacters?.Count, existingEntity.SeriesCharacters?.Count);
     model.VerifyGet(x => x.SeriesLocations, Times.Once);
     //Assert.Equal(model.Object.SeriesLocations?.Count, existingEntity.SeriesLocations?.Count);
 }