예제 #1
0
        public void Should_Add_Question_With_Authorized_User()
        {
            AbpSession.UserId = UsingDbContext(context => context.Users.Single(u => u.UserName == "admin" && u.TenantId == AbpSession.TenantId.Value).Id);

            const string questionTitle = "Test question title 1";

            //Question does not exists now
            UsingDbContext(context => context.Questions.FirstOrDefault(q => q.Title == questionTitle).ShouldBe(null));

            //Create the question
            _questionAppService.CreateQuestion(
                new CreateQuestionInput
            {
                Title = questionTitle,
                Text  = "A dummy question text..."
            });

            //Question is added now
            var question = UsingDbContext(context => context.Questions.FirstOrDefault(q => q.Title == questionTitle));

            question.ShouldNotBe(null);

            //Vote up the question
            var voteUpOutput = _questionAppService.VoteUp(new EntityDto(question.Id));

            voteUpOutput.VoteCount.ShouldBe(1);

            //Vote down the question
            var voteDownOutput = _questionAppService.VoteDown(new EntityDto(question.Id));

            voteDownOutput.VoteCount.ShouldBe(0);
        }