public void WehnVehiclePhotoIdSet_ThenValueUpdated()
        {
            VehiclePhoto target = new VehiclePhoto();

            target.VehiclePhotoId = 4;

            int actual = target.VehiclePhotoId;
            Assert.Equal(4, actual);
        }
        public void WhenConstructed_ThenPopulated()
        {
            VehiclePhoto actual = new VehiclePhoto();

            Assert.NotNull(actual);
            Assert.Equal(0, actual.VehiclePhotoId);
            Assert.Null(actual.Image);
            Assert.Null(actual.ImageMimeType);
        }
        public void WhenImageSetToNull_ThenValueUpdated()
        {
            VehiclePhoto target = new VehiclePhoto();
            target.Image = new byte[] {1, 2, 3};

            target.Image = null;

            byte[] actual = target.Image;
            Assert.Null(actual);
        }
        public void WhenCreateCalled_ThenPhotoPersists()
        {
            var repository = new VehiclePhotoRepository();
            var photo = new VehiclePhoto
                            {
                                ImageMimeType = "image/jpeg",
                                Image = new byte[1]
                            };
            repository.Create(1, photo);

            var repository2 = new VehiclePhotoRepository();
            Assert.NotNull(repository2.Get(1));
        }
        public void WhenImageSetToValidValue_ThenValidationPasses()
        {
            VehiclePhoto target = new VehiclePhoto();
            target.ImageMimeType = "ImageMimeType";

            target.Image = new byte[1];

            var validationContext = new ValidationContext(target, null, null);
            var validationResults = new List<ValidationResult>();
            bool actual = Validator.TryValidateObject(target, validationContext, validationResults, true);

            Assert.True(actual);
            Assert.Equal(0, validationResults.Count);
        }
        public void WhenImageSet_ThenValueUpdated()
        {
            VehiclePhoto target = new VehiclePhoto();
            byte[] expected = new byte[] {1, 2, 3};

            target.Image = expected;

            byte[] actual = target.Image;
            Assert.Equal(expected.Length, actual.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.Equal(expected[i], actual[i]);
            }
        }
        public void WhenImageMimeTypeSetToEmpty_ThenValidationFails()
        {
            VehiclePhoto target = new VehiclePhoto();
            target.Image = new byte[1];
            target.ImageMimeType = string.Empty;

            var validationContext = new ValidationContext(target, null, null);
            var validationResults = new List<ValidationResult>();
            bool actual = Validator.TryValidateObject(target, validationContext, validationResults, true);

            Assert.False(actual);
            Assert.Equal(1, validationResults.Count);
            Assert.Equal(1, validationResults[0].MemberNames.Count());
            Assert.Equal("ImageMimeType", validationResults[0].MemberNames.First());
        }
        public void WhenDeleteCalled_ThenPhotoNuked()
        {
            const int vehicleId = 1;
            var repository = new VehiclePhotoRepository();
            var photo = new VehiclePhoto
                            {
                                ImageMimeType = "image/jpeg",
                                Image = new byte[1]
                            };
            repository.Create(vehicleId, photo);
            repository.Delete(photo.Id);

            var repository2 = new VehiclePhotoRepository();
            Assert.Null(repository2.Get(photo.Id));
        }
        public void WhenImageMimeTypeSetToNull_ThenUpdatesValue()
        {
            VehiclePhoto target = new VehiclePhoto();
            target.ImageMimeType = "ImageMimeType";

            target.ImageMimeType = null;

            string actual = target.ImageMimeType;
            Assert.Null(actual);
        }
        public void WhenImageMimeTypeSet_ThenValueUpdated()
        {
            VehiclePhoto target = new VehiclePhoto();

            target.ImageMimeType = "ImageMimeType";

            string actual = target.ImageMimeType;
            Assert.Equal("ImageMimeType", actual);
        }
 private VehiclePhoto CreateVehiclePhoto(Image image, int vehicleId)
 {
     byte[] buffer;
     using (var memoryStream = new MemoryStream())
     {
         image.Save(memoryStream, new ImageFormat(image.RawFormat.Guid));
         buffer = memoryStream.ToArray();
     }
     var vehiclePhoto = new VehiclePhoto {ImageMimeType = "image/jpeg", Image = buffer, VehicleId = vehicleId};
     _photos.Create(vehicleId, vehiclePhoto);
     return vehiclePhoto;
 }