예제 #1
0
        public void CanUpdateFile()
        {
            Mock<IFileRepository> mock = new Mock<IFileRepository>();
            File fileToUpdate = new File { Id = 1, FilePath = "" };
            FileController controller = new FileController(mock.Object);

            controller.Put(fileToUpdate);
        }
예제 #2
0
        public void CanAddFile()
        {
            Mock<IFileRepository> mock = new Mock<IFileRepository>();
            File fileToAdd = new File { FilePath = "" };
            FileController controller = new FileController(mock.Object);

            controller.Post(fileToAdd);
        }
예제 #3
0
        public void CanGetFileByFileName()
        {
            File expected = new File { Id = 1 };

            Mock<IFileRepository> mock = new Mock<IFileRepository>();
            mock.Setup(f => f.GetByFilename(It.IsAny<string>()))
                .Returns(expected);

            FileNameController controller = new FileNameController(mock.Object);
            Assert.AreEqual(expected, controller.GetByFilename(""));
        }
예제 #4
0
        public void CanAddFile()
        {
            FileRepository repo = new FileRepository();
            File file = new File
            {
                FilePath = Guid.NewGuid().ToString(),
                Tags = new List<Tag>()
            };

            repo.Add(file);

            Assert.AreNotEqual(0, file.Id);
        }
예제 #5
0
        public void CanAddFileWithTags()
        {
            TagRepository tagRepository = new TagRepository();
            Tag tag1 = new Tag { Description = Guid.NewGuid().ToString() };
            tagRepository.Add(tag1);
            Tag tag2 = new Tag { Description = Guid.NewGuid().ToString() };
            tagRepository.Add(tag2);

            FileRepository fileRepository = new FileRepository();
            File file = new File
            {
                FilePath = Guid.NewGuid().ToString(),
                Tags = new [] { tag1, tag2 }.ToList()
            };
            fileRepository.Add(file);

            Assert.AreEqual(file, fileRepository.GetByFilename(file.FilePath));
        }
예제 #6
0
        public void CanGetFilesByTag()
        {
            TagRepository tagRepository = new TagRepository();
            Tag tag = new Tag
            {
                Description = "CanGetFilesByTag tag"
            };
            tagRepository.Add(tag);

            FileRepository fileRepository = new FileRepository();
            File fileWithTag = new File
            {
                FilePath = Guid.NewGuid().ToString(),
                Tags = new []{ tag }.ToList()
            };

            File fileWithoutTag = new File
            {
                FilePath = Guid.NewGuid().ToString(),
                Tags = new Tag[0].ToList()
            };

            fileRepository.Add(fileWithTag);
            fileRepository.Add(fileWithoutTag);

            IEnumerable<File> files = fileRepository.GetByTag(tag.Id);
            Assert.Contains(fileWithTag, files.ToArray());
        }
예제 #7
0
        public void CanGetFile()
        {
            FileRepository repo = new FileRepository();
            File file = new File
            {
                FilePath = Guid.NewGuid().ToString(),
                Tags = new List<Tag>()
            };
            repo.Add(file);

            Assert.AreEqual(file, repo.GetByFilename(file.FilePath));
        }
예제 #8
0
 public void Add(File file)
 {
     SqliteHelper.Insert(AddWithReferencesQuery(file), AddWithReferencesCommandBinder, file);
 }
예제 #9
0
        private static string InsertTagMap(File entity, string fileId)
        {
            StringBuilder sb = new StringBuilder();
            int i = 0;
            IEnumerator<Tag> tagsEnumerator = entity.Tags.GetEnumerator();
            while (tagsEnumerator.MoveNext())
            {
                sb.Append("INSERT INTO TagMap(File_Id, Tag_Id) VALUES(");
                sb.Append(fileId);
                sb.Append(", @Tag_Id");
                sb.Append(i);
                sb.Append(");");
                i++;
            }

            return sb.ToString();
        }
예제 #10
0
 private static void BindTagIds(SQLiteCommand cmd, File file)
 {
     int i = 0;
     foreach (Tag tag in file.Tags)
     {
         cmd.Parameters.Add("@Tag_Id" + i, DbType.String).Value = tag.Id;
         i++;
     }
 }
예제 #11
0
 private static string AddWithReferencesQuery(File entity)
 {
     return AddQuery + InsertTagMap(entity, "(SELECT Id FROM File ORDER BY Id DESC LIMIT 1)");
 }
예제 #12
0
 public void Update(File file)
 {
     SqliteHelper.Update(UpdateWithReferencesQuery(file), UpdateWithReferencesCommandBinder, file);
 }