public void CanGetTag() { TagRepository repo = new TagRepository(); Tag tag = new Tag { Description = "tag" }; repo.Add(tag); Assert.AreEqual(tag, repo.GetById(tag.Id)); }
public void CanGetTagType() { Tag expected = new Tag { Id = 1, Description = "abc" }; Mock<ITagRepository> mock = new Mock<ITagRepository>(); mock.Setup(f => f.GetById(1)) .Returns(expected); TagController controller = new TagController(mock.Object); Tag tag = controller.Get(1); Assert.AreEqual(expected, tag); }
public void CanDeleteTag() { TagRepository repo = new TagRepository(); Tag tag = new Tag { Description = "tag" }; repo.Add(tag); repo.Delete(tag.Id); Assert.Null(repo.GetById(tag.Id)); }
public void CanGetAllTags() { TagRepository repo = new TagRepository(); Tag tag1 = new Tag { Description = "tag1" }; Tag tag2 = new Tag { Description = "tag2" }; repo.Add(tag1); repo.Add(tag2); Tag[] tags = repo.GetAll().ToArray(); Assert.True(tags.Contains(tag1)); Assert.True(tags.Contains(tag2)); }
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 CanUpdateTag() { TagTypeRepository repoTagtypes = new TagTypeRepository(); TagType tagTypeOriginal = new TagType { Description = "tag type original" }; TagType tagTypeUpdated = new TagType { Description = "tag type updated" }; repoTagtypes.Add(tagTypeOriginal); repoTagtypes.Add(tagTypeUpdated); TagRepository repoTags = new TagRepository(); Tag tag = new Tag { Description = "tag", TagType = tagTypeOriginal }; repoTags.Add(tag); tag.Description = "tag updated"; tag.TagType = tagTypeUpdated; repoTags.Update(tag); Assert.AreEqual(tag, repoTags.GetById(tag.Id)); }
public void Add(Tag tagType) { SqliteHelper.Insert(AddQuery, AddCommandBinder, tagType); }
private static Tag Parse(SQLiteDataReader dr) { Tag tag = new Tag { Id = dr.GetInt32(0), Description = dr.GetString(1) }; object idTagTypeObj = dr.GetValue(2); if (idTagTypeObj != DBNull.Value) { tag.TagType = new TagType { Id = dr.GetInt32(2), Description = dr.GetString(3) }; } return tag; }
//protected override string GetByIdWithReferencesQuery => // GetByIdQuery + // @"SELECT f.Id, f.FilePath // FROM File AS f // INNER JOIN TagMap AS tm // ON tm.File_Id = f.Id // WHERE tm.Tag_Id = @Id;"; //protected override Tag ParseWithReferences(SQLiteDataReader dr) //{ // if (!dr.Read()) return null; // Tag tag = Parse(dr); // LinkedList<File> files = new LinkedList<File>(); // dr.NextResult(); // while (dr.Read()) // { // files.AddLast(new File // { // Id = dr.GetInt32(0), // FilePath = dr.GetString(1) // }); // } // tag.Files = files; // return tag; //} private static object GetTagTypeId(Tag tag) { if (tag.TagType != null) { return tag.TagType.Id; } return DBNull.Value; }
public void Update(Tag tagType) { SqliteHelper.Update(UpdateQuery, UpdateCommandBinder, tagType); }
private static File ParseWithReferences(SQLiteDataReader dr) { if (!dr.Read()) return null; File file = Parse(dr); List<Tag> tags = new List<Tag>(); dr.NextResult(); while (dr.Read()) { Tag tag; tags.Add(tag = new Tag { Id = dr.GetInt32(0), Description = dr.GetString(1) }); object idTagTypeObj = dr.GetValue(2); if (idTagTypeObj != DBNull.Value) { tag.TagType = new TagType { Id = dr.GetInt32(2), Description = dr.GetString(3) }; } } file.Tags = tags; return file; }