Ejemplo n.º 1
0
        public void GivenAnImageObject_ThenItIsHashCodeIsEqualToItsId()
        {
            var id = new Guid();
            var img = new Media {Id= id};

            Assert.That(img.GetHashCode(), Is.EqualTo(id.GetHashCode()));
        }
Ejemplo n.º 2
0
 public void GivenAnImageObject_WhenItIsComparedToAnotherMedia_AndTheIdsAreEqual_ThenTheyAreEqual()
 {
     var id = Guid.NewGuid();
     var img1 = new Media { Id = id };
     var img2 = new Media { Id = id };
     img1.Equals(img2).Should().BeTrue();
 }
Ejemplo n.º 3
0
        public Media CreateMedia(string fileName, string contentType, Stream inputStream, int contentLength)
        {
            var mediaToCreate = new Media(fileName, contentType, inputStream, contentLength);

            try
            {
                Media media = (from e in _mediaRepository.Entities
                               where e.FileName == mediaToCreate.FileName
                               select e).FirstOrDefault();

                if (media == null)
                {
                    mediaToCreate = _mediaRepository.Create(mediaToCreate);
                    return mediaToCreate;
                }
                throw new ItsaException("Unable to add media. The media already exists in the database");
            }
            catch (ItsaException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ItsaException("Could not create media", e);
            }
        }
Ejemplo n.º 4
0
        public void UpdateMedia(string fileName, string title, string caption, string description, string alternate,
                               string contentType, int alignment, int size, Stream inputStream,
                               int contentLength)
        {
            byte[] bytes = ReadBytes(inputStream, contentLength);

            // todo: url?
            var media = new Media(fileName, title, caption, description, alternate, contentType, alignment, size,
                                  bytes);
            try
            {
                _mediaRepository.Update(media);
            }
            catch (Exception e)
            {
                throw new ItsaException("Could not create media", e);
            }
        }
Ejemplo n.º 5
0
 public bool Equals(Media other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.Id == Id;
 }
Ejemplo n.º 6
0
 public void GivenTwoImageObjects_WhenOneIsNull_AndItIsCastToObject_ThenTheyAreNotEqual()
 {
     var img = new Media();
     bool actual = img.Equals((object) null);
     Assert.That(actual, Is.False);
 }
Ejemplo n.º 7
0
 public void GivenImageData_WhenICreateAnImage_ThenIGetValidDates()
 {
     DateTime today = DateTime.Now;
     var media = new Media("filename", "title", "caption", "description", "alternate", "mime",
                           (int) Media.ValidAllignments.None, (int) Media.ValidSizes.Fullsize, new byte[] {});
     Assert.That(media.Year, Is.EqualTo(today.Year));
     Assert.That(media.Month, Is.EqualTo(today.Month));
     Assert.That(media.Day, Is.EqualTo(today.Day));
 }
Ejemplo n.º 8
0
 public void GivenAnInvalidSize_WhenICreateAnImage_ThenTheSizeIsSetToFullsize()
 {
     var media = new Media("filename", "title", "caption", "description", "alternate", "mime",
                           (int) Media.ValidAllignments.None, 43, new byte[] {});
     Assert.That(media.Size, Is.EqualTo((int) Media.ValidSizes.Fullsize));
 }
Ejemplo n.º 9
0
 public void GivenAnInvalidAlignmenmt_ThenAnAlignmentOfNoneIsReturned()
 {
     var m = new Media();
     m.Alignment = 43;
     m.Alignment.Should().Be((int)Media.ValidAllignments.None);
 }
Ejemplo n.º 10
0
        public void WhenAnInvalidAlignmentIsSet_ThenTheAlignmentIsSetToNone()
        {
            var media = new Media();
            media.Alignment = 23;

            Assert.That(media.Alignment, Is.EqualTo(0));
        }
Ejemplo n.º 11
0
 public void GivenAnImageObject_WhenItIsComparedToAnotherType_ThenTheyAreNotEqual()
 {
     var img = new Media();
     bool actual = img.Equals("string");
     Assert.That(actual, Is.False);
 }
Ejemplo n.º 12
0
 public void WhenGettingATitle_ThenTheTitleIsReturned()
 {
     var m = new Media();
     m.Title = "title";
     m.Title.Should().Be("title");
 }
Ejemplo n.º 13
0
 public void WhenCreatingAMediaWithAShortConstructor_ThenTheDefaulsValuesAreSet()
 {
     var m = new Media("", "", new MemoryStream(), 0);
     m.Alignment.Should().Be(0);
     m.Title.Should().Be("");
     m.Caption.Should().Be("");
     m.Description.Should().Be("");
     m.Alternate.Should().Be("");
     m.Size.Should().Be(0);
     m.Data.Should().NotBeNull();
 }
Ejemplo n.º 14
0
        public void WhenAUrlIsRequested_TheCorrectlyFormattedUrlIsReturned()
        {
            var media = new Media {Year = 2010, Month = 1, Day = 2, LinkKey = "link"};

            Assert.That(media.Url, Is.EqualTo("2010/1/2/link"));
        }
Ejemplo n.º 15
0
 public void GivenAnImageObject_WhenItIsComparedToItself_ThenTheyAreEqual()
 {
     var img = new Media();
     bool actual = img.Equals(img);
     Assert.That(actual, Is.True);
 }
Ejemplo n.º 16
0
 public void AddImage(Media media)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 17
0
 public string GeneratedFileName(Media e)
 {
     return GenerateFileName(e);
 }