Exemplo n.º 1
0
        /// <summary>
        /// Add answer description.
        /// </summary>
        /// <param name="answerDescription"></param>
        /// <returns></returns>
        public DataOperationResult AddAnswerDescription(AnswerDescriptionDto answerDescription)
        {
            var answerDescriptionObject = new AnswerDescription();

            answerDescriptionObject.FromDto(answerDescription);

            // Save to database
            _repository.Insert(answerDescriptionObject);
            _repository.SaveChangesAsync().Wait();

            // Add to cache.
            var cachedData = GetCachedData();

            cachedData.Insert(answerDescriptionObject);

            // Add to user cache if there is a user
            if (answerDescriptionObject.UserId != null)
            {
                var userCachedData = GetUserCachedData();
                userCachedData.Insert(new AnswerDescriptionUserMask(answerDescriptionObject));
            }

            return(new DataOperationResult()
            {
                IsNew = true, IntId = answerDescriptionObject.AnswerId
            });
        }
 public AnswerDescriptionTests()
 {
     _answerDescription = new AnswerDescription()
     {
         Id              = 1,
         DateAdded       = new DateTime(2016, 1, 1),
         NumberOfEntries = 3,
         ObjectState     = ObjectState.Unchanged,
         UserId          = "B",
         AnswerId        = 2,
         Description     = "A"
     };
 }
        public void AnswerDescriptionVoteTests_OtherProperties_Work()
        {
            var answerDescription = new AnswerDescription()
            {
                Description = "leftword"
            };

            _answerDescriptionVote.AnswerDescription = answerDescription;

            Assert.Equal(_answerDescriptionVote.AnswerDescription.Description, "leftword");

            var user = new ApplicationUser()
            {
                DisplayName = "A1"
            };

            _answerDescriptionVote.ApplicationUser = user;
            Assert.Equal(_answerDescriptionVote.ApplicationUser.DisplayName, "A1");
        }
        public void AnswerDescriptionTests_IDtoConvertable_Converts()
        {
            var dto = _answerDescription.ToDto();

            Assert.Equal(dto.Id, _answerDescription.Id);
            Assert.Equal(dto.AnswerId, _answerDescription.AnswerId);
            Assert.Equal(dto.Description, _answerDescription.Description);
            Assert.Equal(dto.UserId, _answerDescription.UserId);
            Assert.Equal(dto.DateAdded, _answerDescription.DateAdded);

            var newAnswerDescription = new AnswerDescription();

            newAnswerDescription.FromDto(dto);

            Assert.Equal(newAnswerDescription.Id, _answerDescription.Id);
            Assert.Equal(newAnswerDescription.Description, _answerDescription.Description);
            Assert.Equal(newAnswerDescription.AnswerId, _answerDescription.AnswerId);
            Assert.Equal(newAnswerDescription.UserId, _answerDescription.UserId);
            Assert.NotEqual(newAnswerDescription.DateAdded, _answerDescription.DateAdded);
        }
 /// <summary>
 /// Copy data from answer description
 /// </summary>
 /// <param name="answer"></param>
 public AnswerDescriptionUserMask(AnswerDescription answerDescription)
 {
     Id          = answerDescription.Id;
     Description = answerDescription.Description;
     UserId      = answerDescription.UserId;
 }