Esempio n. 1
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));
        }
Esempio n. 2
0
 public void Add_And_Presist_Changes_Should_Succeed()
 {
     using (BeginTransaction())
     {
         var tag = (Tag)_domainFactory.CreateTag("Dummy Tag");
         _tagRepository.Add(tag);
         Assert.Equal(EntityState.Added, tag.EntityState);
         _database.SubmitChanges();
         Assert.Equal(EntityState.Unchanged, tag.EntityState);
     }
 }
Esempio n. 3
0
        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));
        }
Esempio n. 4
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());
        }
Esempio n. 5
0
        public void Add_Get_Activity_Tags_From_Repository()
        {
            using (var context = new AcManContext(OptionsRandom)) {
                string randomTagName = "Tag " + Guid.NewGuid();
                var    tag           = new Tag {
                    Name = randomTagName
                };
                var activityTags = new Collection <Tag> {
                    tag
                };
                var activity = new Activity {
                    Caption = "Test activity",
                    Tags    = activityTags
                };

                var activityRepository = new ActivityRepository(context);
                var tagRepository      = new TagRepository(context);
                var tagId      = tagRepository.Add(tag);
                var activityId = activityRepository.Add(activity);

                var resultActivity = activityRepository.GetWithTags(activityId);
                Assert.IsNotNull(resultActivity.Tags);
                Assert.IsTrue(((Tag[])resultActivity.Tags)[0].Name.Equals(randomTagName));
            }
        }
Esempio n. 6
0
        public async Task <IActionResult> CreateTag(int contactId, DetailInfoForUpdateDto details)
        {
            Tag tag           = new Tag();
            int tagIdFromRepo = await _contactTagRepo.getTagId(details.tagName);

            if (tagIdFromRepo == -1)
            {
                tag.TagName = details.tagName;
                _tagsRepo.Add(tag);
                _contactTagRepo.Add(new ContactTag {
                    TagId = tag.Id, ContactId = contactId
                });
                await _tagsRepo.SaveAll();

                await _contactTagRepo.SaveAll();
            }
            else
            {
                var tagsFromRepo = await _contactTagRepo.GetTags(contactId);

                if (tagsFromRepo.Any(t => t.TagName == details.tagName))
                {
                    return(BadRequest());
                }
                else
                {
                    _contactTagRepo.Add(new ContactTag {
                        TagId = tagIdFromRepo, ContactId = contactId
                    });
                    await _contactTagRepo.SaveAll();
                }
            }
            return(Ok());
        }
Esempio n. 7
0
        public void CanFailWithNullDescriptionAndNullTagType()
        {
            TagRepository repo = new TagRepository();

            Assert.Throws(typeof(SQLiteException), () =>
                          repo.Add(new Tag())
                          );
        }
        public ActionResult <Tag> Create([FromBody] TagDTO dto)
        {
            var tag = new Tag(dto.Name);

            _repository.Add(tag);

            return(StatusCode(201, tag));
        }
Esempio n. 9
0
        public void CanAddTag()
        {
            TagRepository repo = new TagRepository();

            repo.Add(new Tag
            {
                Description = "tag"
            });
        }
Esempio n. 10
0
        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));
        }
Esempio n. 11
0
        public static void CreateTag(string name, string friendlyName)
        {
            var result = TagRepository.Get(friendlyName);

            if (result != null)
            {
                throw new HttpException(409, "Tag is already in use.");
            }
            TagRepository.Add(name, friendlyName);
        }
Esempio n. 12
0
    private static void CreateTag(string name, string friendlyName)
    {
        var result = TagRepository.Get(friendlyName);

        if (result != null)
        {
            throw new HttpException(404, "Post does not exist");
        }

        TagRepository.Add(name, friendlyName);
    }
Esempio n. 13
0
        private SVP.CIL.Domain.Tag TagCreate(AppDbContext dbc, SVP.CIL.Domain.Tag target)
        {
            var tag  = Mapper.Map <Tag>(target);
            var repo = new TagRepository(dbc);

            repo.Add(tag);
            dbc.SaveChanges();
            var domainTag = Mapper.Map <SVP.CIL.Domain.Tag>(tag);

            return(domainTag);
        }
Esempio n. 14
0
        public void CanGetTag()
        {
            TagRepository repo = new TagRepository();
            Tag           tag  = new Tag
            {
                Description = "tag"
            };

            repo.Add(tag);

            Assert.AreEqual(tag, repo.GetById(tag.Id));
        }
Esempio n. 15
0
        public void CreateTagFromActivity(Activity activity, string newTagName)
        {
            var activityAdditionalInfo = new ActivityAdditionalInfo(activity);

            _activityAdditionalInfoRepository.Add(activityAdditionalInfo);
            var tag = new Tag {
                Name = newTagName,
                ActivityAdditionalInfo = activityAdditionalInfo
            };

            _tagRepository.Add(tag);
        }
 public ActionResult Create(Tag tag)
 {
     try
     {
         _tagRepo.Add(tag);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View(tag));
     }
 }
Esempio n. 17
0
    private static void CreateTag(string name, string friendlyName)
    {
        // trying if post with specific slug exists
        var result = TagRepository.Get(friendlyName);

        if (result != null)
        {
            throw new HttpException(409, "Tag allready in use");
        }


        TagRepository.Add(name, friendlyName);
    }
Esempio n. 18
0
        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));
        }
Esempio n. 19
0
        private static void CreateTag(string name, string friendlyName)
        {
            var result = TagRepository.Get(friendlyName);

            if (result != null)
            {
                throw new HttpException(409, "Tag is already in use");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new HttpException(409, "Tag must not be empty!");
            }
            TagRepository.Add(name, friendlyName);
        }
Esempio n. 20
0
        public ActionResult AddEditTag(Tag model)
        {
            // Validate the model being submitted
            if (model.Id > 0)
            {
                _tagRepository.Update(model);
            }
            else
            {
                _tagRepository.Add(model);
            }

            return(RedirectToAction("Tag"));
        }
Esempio n. 21
0
        public IActionResult Create(Tag tag)
        {
            try
            {
                _tagRepository.Add(tag);

                return(RedirectToAction("Index"));
            }

            catch (Exception ex)
            {
                return(View(tag));
            }
        }
Esempio n. 22
0
        public int Agregar(TagViewModel pTagViewModel)
        {
            tags otags = new tags
            {
                tag_id          = 0,
                name            = pTagViewModel.name,
                date_created    = DateTime.Now,
                user_id_created = pTagViewModel.user_id_created
            };

            otags = oRepositorio.Add(otags);
            oUnitOfWork.SaveChanges();
            return(otags.tag_id);
        }
Esempio n. 23
0
        private TagViewModel CreateOrGetTag(string tagName)
        {
            Tag tagExist = tagRepository.GetAll().FirstOrDefault(t => t.Name == tagName);

            if (tagExist != null)
            {
                return(Mapper.Map <TagViewModel>(tagExist));
            }
            Tag newTag = new Tag {
                Name = tagName
            };

            tagRepository.Add(Mapper.Map <Tag>(newTag));
            tagRepository.Save();
            return(Mapper.Map <TagViewModel>(newTag));
        }
Esempio n. 24
0
        public IActionResult Post([FromBody] TagInfo tag)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                tag = tagRepository.Add(tag);
                return(CreatedAtRoute("GetTag", new { id = tag.TagId }, tag));
                //return Ok(tag);
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }
Esempio n. 25
0
        private void addTags(string[] Tags, int postId)
        {
            List <PostTag> postTags = new List <PostTag>();

            foreach (var tag in Tags)
            {
                var assignTag = _tagRepository.GetByName(tag);
                if (assignTag is null)
                {
                    assignTag = new Tag {
                        name = tag
                    };
                    _tagRepository.Add(assignTag);
                }

                postTags.Add(new PostTag {
                    TagId = assignTag.id, PostId = postId
                });
            }

            _postTagRepository.BulkInsert(postTags);
        }
Esempio n. 26
0
 public IActionResult Post(Tag tag)
 {
     _tagRepository.Add(tag);
     return(CreatedAtAction("Get", new { id = tag.Id }, tag));
 }
Esempio n. 27
0
        public void Add_Should_Use_Database()
        {
            database.Expect(d => d.Insert(It.IsAny <Tag>())).Verifiable();

            _tagRepository.Add(_factory.CreateTag("Dummy"));
        }
Esempio n. 28
0
 public void Add_Should_Use_Database()
 {
     _tagRepository.Add(_factory.CreateTag("Dummy"));
     database.Verify(d => d.InsertOnSubmit(It.IsAny <Tag>()), Times.AtMostOnce());
 }
        public IActionResult Post([FromBody] Tag tag)
        {
            var tagResult = tagRepository.Add(tag);

            return(Created("api/Tag/" + tagResult.Id, tagResult));
        }