public async Task Get_ReturnsOk() { // Arrange var expectedUserId = "EPECTED USER ID"; var expectedTerms = new Models.Dto.Term[] { new Models.Dto.Term(), new Models.Dto.Term(), new Models.Dto.Term() }; The <ITermsRepository>() .Setup(m => m.ReadTerms(expectedUserId)) .ReturnsAsync(expectedTerms); The <IMapper>() .Setup(m => m.Map <Models.Term>(It.IsAny <Models.Dto.Term>())) .Returns(new Models.Term()); Target.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext { User = GenerateUser(expectedUserId) } }; // Act var response = await Target.Get(); // Assert Assert.Equal(3, response.ToArray().Length); VerifyAll(); }
/// <inheritdoc cref="ITermsRepository.UpdateTerm"/> public async Task UpdateTerm(Models.Dto.Term term) { var termOld = await GetTerm(term.TermId); _context.Terms.Attach(termOld); termOld.Color = term.Color; termOld.Name = term.Name; termOld.Enabled = term.Enabled; await _context.SaveChangesAsync(); }
/// <inheritdoc cref="ITermsRepository.AddTerm"/> public async Task <int> AddTerm(string userId, Models.Dto.Term term) { var user = await GetUserAndTerms(userId); _context.Users.Attach(user); user.Terms = user.Terms ?? new List <Models.Dto.Term>(); user.Terms.Add(term); await _context.SaveChangesAsync(); return(term.TermId); }