public void GivenAnImageObject_ThenItIsHashCodeIsEqualToItsId() { var id = new Guid(); var img = new Media {Id= id}; Assert.That(img.GetHashCode(), Is.EqualTo(id.GetHashCode())); }
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(); }
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); } }
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); } }
public bool Equals(Media other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other.Id == Id; }
public void GivenTwoImageObjects_WhenOneIsNull_AndItIsCastToObject_ThenTheyAreNotEqual() { var img = new Media(); bool actual = img.Equals((object) null); Assert.That(actual, Is.False); }
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)); }
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)); }
public void GivenAnInvalidAlignmenmt_ThenAnAlignmentOfNoneIsReturned() { var m = new Media(); m.Alignment = 43; m.Alignment.Should().Be((int)Media.ValidAllignments.None); }
public void WhenAnInvalidAlignmentIsSet_ThenTheAlignmentIsSetToNone() { var media = new Media(); media.Alignment = 23; Assert.That(media.Alignment, Is.EqualTo(0)); }
public void GivenAnImageObject_WhenItIsComparedToAnotherType_ThenTheyAreNotEqual() { var img = new Media(); bool actual = img.Equals("string"); Assert.That(actual, Is.False); }
public void WhenGettingATitle_ThenTheTitleIsReturned() { var m = new Media(); m.Title = "title"; m.Title.Should().Be("title"); }
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(); }
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")); }
public void GivenAnImageObject_WhenItIsComparedToItself_ThenTheyAreEqual() { var img = new Media(); bool actual = img.Equals(img); Assert.That(actual, Is.True); }
public void AddImage(Media media) { throw new NotImplementedException(); }
public string GeneratedFileName(Media e) { return GenerateFileName(e); }