示例#1
0
        public void UpdatePhotoDisplayPropertiesDoesntUpdatePhotoDataTest()
        {
            // TODO: clean this up
            var entity = new Photo
            {
                DisplayProperties = new PhotoDisplayProperties
                {
                    PhotoGroupId = 4,
                    Title        = Guid.NewGuid().ToString(),
                    SortOrder    = 5
                },
                Data = new PhotoData
                {
                    MimeType = Guid.NewGuid().ToString(),
                    Data     = Guid.NewGuid().ToByteArray(),
                }
            };

            var updatedProperties = new PhotoDisplayProperties
            {
                PhotoGroupId = 2,
                Title        = Guid.NewGuid().ToString(),
                SortOrder    = 3
            };

            var dbContext   = InMemoryDbContextProvider.GetContext();
            var respository = new PhotoRepository(dbContext);

            dbContext.Add(entity);
            dbContext.SaveChanges();
            DetachAllEntities(dbContext);

            respository.UpdateDisplayProperties(entity.Id, updatedProperties);

            var photos = dbContext.Set <Photo>().AsNoTracking().ToList();

            Assert.Single(photos);
            Assert.Equal(entity.Data.Data, photos[0].Data.Data);
            Assert.Equal(entity.Data.MimeType, photos[0].Data.MimeType);
            Assert.Equal(
                updatedProperties.PhotoGroupId,
                photos[0].DisplayProperties.PhotoGroupId);
            Assert.Equal(
                updatedProperties.SortOrder,
                photos[0].DisplayProperties.SortOrder);
            Assert.Equal(
                updatedProperties.Title,
                photos[0].DisplayProperties.Title);
        }
        public void PhotoDisplayPropertiesModelMapTest()
        {
            var entity = new PhotoDisplayProperties
            {
                Title        = Guid.NewGuid().ToString(),
                PhotoGroupId = 2,
                SortOrder    = 3
            };

            var model = Mapper.Map <PhotoDisplayPropertiesModel>(entity);

            Assert.Equal(entity.Title, model.Title);
            Assert.Equal(entity.PhotoGroupId, model.PhotoGroupId);
            Assert.Equal(entity.SortOrder, model.SortOrder);
        }
        public void UpdateDisplayProperties(int id, PhotoDisplayProperties properties)
        {
            Guard.NotNull(properties, nameof(properties));

            // TODO: throw on not exist?
            // TODO: better way to unit test this
            if (Exists(id))
            {
                var photo = new Photo {
                    Id = id, DisplayProperties = properties
                };
                DbContext.Attach(photo);
                DbContext.Update(photo.DisplayProperties);
                DbContext.Entry(photo).Reference(x => x.Data).IsModified = false;
                DbContext.SaveChanges();
            }
        }