Esempio n. 1
0
        public void CanSaveAttachment()
        {
            // Act.
            Assert.That(Attachment.All().Count(), Is.EqualTo(0));
            Attachment file = CreateAttachment();

            // Assert.
            Assert.That(file.ID, Is.Not.EqualTo(ObjectId.Empty));
            Assert.That(Attachment.All().Count(), Is.EqualTo(1));
        }
Esempio n. 2
0
        public void CanSaveAttachmentsWithDuplicateFileNames()
        {
            // Act.
            Assert.That(Attachment.All().Count(), Is.EqualTo(0));
            Attachment file1 = CreateAttachment();
            Attachment file2 = CreateAttachment();

            // Assert.
            Assert.That(Attachment.All().Count(), Is.EqualTo(2));
            Assert.That(Attachment.Find(file1.ID), Is.Not.Null);
            Assert.That(Attachment.Find(file2.ID), Is.Not.Null);
        }
Esempio n. 3
0
        public void CanDeleteAttachment()
        {
            // Arrange.
            Attachment file = CreateAttachment();

            Assert.That(Attachment.All().Count(), Is.EqualTo(1));

            // Act.
            Attachment.Delete(file.ID);

            // Assert.
            Assert.That(Attachment.All().Count(), Is.EqualTo(0));
        }
Esempio n. 4
0
        public void CanCreateAttachmentFromStream()
        {
            Assert.That(Attachment.All().Count(), Is.EqualTo(0));

            // Act.
            Attachment file;

            using (var fs = File.OpenRead("Files/Koala.jpg"))
                file = Attachment.Create(new Attachment
                {
                    Content     = fs,
                    ContentType = "image/jpg"
                });

            // Assert.
            Assert.That(file.ID, Is.Not.EqualTo(ObjectId.Empty));
            Assert.That(Attachment.All().Count(), Is.EqualTo(1));
        }
Esempio n. 5
0
        public void CanSaveExistingAttachment()
        {
            // Arrange.
            using (FileStream stream = File.OpenRead("Files/Koala.jpg"))
            {
                Attachment file = Attachment.Create(new Attachment
                {
                    Content     = stream,
                    FileName    = "Files/Koala.jpg",
                    ContentType = "image/jpg"
                });
                ObjectId id = file.ID;

                // Act.
                file.FileName = "newfilename.jpg";
                file.Save();

                // Assert.
                Assert.That(file.ID, Is.EqualTo(id));
                Assert.That(Attachment.All().Count(), Is.EqualTo(1));
            }
        }