Esempio 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()));
        }
Esempio 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();
 }
Esempio 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);
            }
        }
Esempio 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);
            }
        }
Esempio n. 5
0
 public bool Equals(Media other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.Id == Id;
 }
Esempio n. 6
0
 public void GivenTwoImageObjects_WhenOneIsNull_AndItIsCastToObject_ThenTheyAreNotEqual()
 {
     var img = new Media();
     bool actual = img.Equals((object) null);
     Assert.That(actual, Is.False);
 }
Esempio 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));
 }
Esempio 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));
 }
Esempio n. 9
0
 public void GivenAnInvalidAlignmenmt_ThenAnAlignmentOfNoneIsReturned()
 {
     var m = new Media();
     m.Alignment = 43;
     m.Alignment.Should().Be((int)Media.ValidAllignments.None);
 }
Esempio n. 10
0
        public void WhenAnInvalidAlignmentIsSet_ThenTheAlignmentIsSetToNone()
        {
            var media = new Media();
            media.Alignment = 23;

            Assert.That(media.Alignment, Is.EqualTo(0));
        }
Esempio n. 11
0
 public void GivenAnImageObject_WhenItIsComparedToAnotherType_ThenTheyAreNotEqual()
 {
     var img = new Media();
     bool actual = img.Equals("string");
     Assert.That(actual, Is.False);
 }
Esempio n. 12
0
 public void WhenGettingATitle_ThenTheTitleIsReturned()
 {
     var m = new Media();
     m.Title = "title";
     m.Title.Should().Be("title");
 }
Esempio 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();
 }
Esempio 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"));
        }
Esempio n. 15
0
 public void GivenAnImageObject_WhenItIsComparedToItself_ThenTheyAreEqual()
 {
     var img = new Media();
     bool actual = img.Equals(img);
     Assert.That(actual, Is.True);
 }
Esempio n. 16
0
 public void AddImage(Media media)
 {
     throw new NotImplementedException();
 }
Esempio n. 17
0
 public string GeneratedFileName(Media e)
 {
     return GenerateFileName(e);
 }