async public void AddAsync_TagDontExist_ReturnsID() { //Arrange int expected = 1; var model = new TagModel() { }; _mapper.Setup(m => m.Map(It.IsAny <TagModel>())).Returns(new Tag() { Id = 1 }); _repo.Setup(r => r.Add(It.IsAny <Tag>())).Verifiable(); _uow.Setup(u => u.SaveAsync()).ReturnsAsync(expected); //Act var actual = await _service.AddAsync(model); //Assert _factory.Verify(f => f.GetUnitOfWork(), Times.Exactly(2)); _uow.Verify(u => u.TagRepository, Times.Exactly(2)); _repo.VerifyAll(); _mapper.Verify(m => m.Map(It.IsAny <TagModel>()), Times.Once); _uow.Verify(u => u.SaveAsync(), Times.Once); Assert.AreEqual(expected, actual); }
public async Task UpdateTagAsyncShouldRemoveAllTags() { string tags = "javascript c# web"; string deleteTags = string.Empty; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "DeleteTagDb").Options; var dbContext = new ApplicationDbContext(options); dbContext.JobPosts.Add(new JobPost()); await dbContext.SaveChangesAsync(); var jobTagRepository = new EfRepository <JobTag>(dbContext); var tagRepository = new EfDeletableEntityRepository <Tag>(dbContext); var service = new TagService(jobTagRepository, tagRepository); await service.AddAsync(1, tags); var result = service.GetTagToString(1); Assert.Equal(tags, result); await service.UpdateTagAsync(1, deleteTags); result = service.GetTagToString(1); Assert.Equal(deleteTags, result); }
public async Task <IActionResult> Create([Bind("Id,Name,ShortDescription,Details")] Tag tag) { if (ModelState.IsValid) { await _tagService.AddAsync(tag); return(RedirectToAction(nameof(index))); } ModelState.AddModelError("", "I just don't like this model"); return(View()); }
public async void Tags_AddAsync_Positive_Test() { var options = new DbContextOptionsBuilder <DreamFoodDeliveryContext>() .UseInMemoryDatabase(databaseName: "Tags_AddAsync_Positive_Test") .Options; using (var context = new DreamFoodDeliveryContext(options)) { var service = new TagService(_mapper, context); string newTag = "NewTag"; TagToAdd tag = new TagToAdd() { TagName = newTag, }; var resultPositive = await service.AddAsync(tag); resultPositive.IsSuccess.Should().BeTrue(); resultPositive.Data.TagName.Should().BeEquivalentTo(tag.TagName); } }