コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }