public ResultDTO Create(ErrorCreateDTO logErroDTO, ClaimsPrincipal user) { if (logErroDTO == null) { throw new ArgumentNullException(); } if (!_context.Sources.Where(x => x.Deleted == false).Any(x => x.Id == logErroDTO.SourceId)) { return(new ResultDTO(false, "Invalid Source Id.", null)); } var userId = user.Claims.FirstOrDefault().Value; logErroDTO.AddUserId(userId); var logErro = _mapper.Map <Error>(logErroDTO); _context.Add(logErro); if (SaveChanges() == true) { return(new ResultDTO(true, "Succesfully registred the error.", logErro)); } return(new ResultDTO(false, "Fail", null)); }
public void Null_Token_Throws_ArgumentNullException(string title, string details, int sourceId, Level level, string token) { ErrorCreateDTO errorCreateDTO = new ErrorCreateDTO { Title = title, Details = details, SourceId = sourceId, Level = level }; errorCreateDTO.AddUserId(token); }
public void Check_Token_Equals_Token(string title, string details, int sourceId, Level level, string userId) { ErrorCreateDTO errorCreateDTO = new ErrorCreateDTO { Title = title, Details = details, SourceId = sourceId, Level = level }; errorCreateDTO.AddUserId(userId); Assert.AreEqual("UserId", errorCreateDTO.UserId); }
public void Novo_Erro_Deve_Ser_Valido(string title, string details, int sourceId, Level level, string userId) { ErrorCreateDTO errorCreateDTO = new ErrorCreateDTO { Title = title, Details = details, SourceId = sourceId, Level = level }; Assert.IsNotNull(errorCreateDTO); errorCreateDTO.Validate(); Assert.IsTrue(errorCreateDTO.Valid); errorCreateDTO.AddUserId(userId); errorCreateDTO.Validate(); Assert.IsTrue(errorCreateDTO.Valid); Assert.AreEqual(userId, errorCreateDTO.UserId); }