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); }
public void CanAddFile() { Mock<IFileRepository> mock = new Mock<IFileRepository>(); File fileToAdd = new File { FilePath = "" }; FileController controller = new FileController(mock.Object); controller.Post(fileToAdd); }
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("")); }
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); }
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)); }
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()); }
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)); }
public void Add(File file) { SqliteHelper.Insert(AddWithReferencesQuery(file), AddWithReferencesCommandBinder, file); }
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(); }
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++; } }
private static string AddWithReferencesQuery(File entity) { return AddQuery + InsertTagMap(entity, "(SELECT Id FROM File ORDER BY Id DESC LIMIT 1)"); }
public void Update(File file) { SqliteHelper.Update(UpdateWithReferencesQuery(file), UpdateWithReferencesCommandBinder, file); }