예제 #1
0
        public void GetQuestion_WithInvalidId_ShouldReturnErrorResult()
        {
            //---------------Arrange----------------------

            var command = new AskQuestionCommandBuilder().Build();

            //---------------Act--------------------------
            var notFound = Assert.Throws <Exception>(() => command.GetQuestion(null));

            //---------------Assert-----------------------
            Assert.That(notFound.Message, Is.EqualTo("Id not found"));
        }
예제 #2
0
        public void UpdateQuestion_WithInvalidUserId_ShouldReturnErrorResult()
        {
            //---------------Arrange----------------------

            var question = new QuestionBuilder().Build();
            var command  = new AskQuestionCommandBuilder()
                           .WithInvalidUserId("")
                           .Build();

            //---------------Act--------------------------
            var notFound = Assert.ThrowsAsync <Exception>(() => command.UpdateQuestion(question, new CancellationToken()));

            //---------------Assert-----------------------
            Assert.That(notFound.Message, Is.EqualTo("User not found"));
        }
예제 #3
0
        public void AskQuestion_WithExistingTitle_ShouldReturnErrorResult()
        {
            //---------------Arrange----------------------
            const string title  = "where to buy a strong";
            const string userId = "22";

            var question  = new QuestionBuilder().WithTitle(title).Build();
            var questions = new List <Question>
            {
                new QuestionBuilder().WithTitle(title).Build(),
                new QuestionBuilder().WithTitle(title).Build()
            };

            var command = new AskQuestionCommandBuilder()
                          .WithExistingQuestionTitle(questions).WithInvalidUserId(userId)
                          .Build();

            //---------------Act--------------------------
            var notFound = Assert.ThrowsAsync <Exception>(() => command.AskQuestion(question, new CancellationToken()));

            //---------------Assert-----------------------
            Assert.That(notFound.Message, Is.EqualTo("Title already exist!"));
        }
예제 #4
0
        public void UpdateQuestion_WithNewUpdatedQuestion_ShouldReturnQuestion()
        {
            //---------------Arrange----------------------

            var newQuestionTitle = "New Title Testing";

            var oldQuestion = new Question
            {
                Id          = 5,
                Title       = "Old Title testing",
                DateCreated = DateTime.Parse("2020-01-20"),
                Description = "Old Test description"
            };

            var question = new QuestionBuilder().WithId(5)
                           .WithDateCreated(oldQuestion.DateCreated)
                           .WithTitle(newQuestionTitle)
                           .Build();

            var command = new AskQuestionCommandBuilder()
                          .WithNewUpdatedQuestionId(question)
                          .WithQuestionToUpdate(5, oldQuestion)
                          .WithValidUserId("12")
                          .Build();

            //---------------Act--------------------------

            var result = command.UpdateQuestion(question, new CancellationToken());

            //---------------Assert-----------------------

            Assert.That(result, Is.Not.Null);
            var resultTitle = result.Result.Title;

            Assert.That(oldQuestion.Title, Is.EqualTo("Old Title testing"));
            Assert.That(resultTitle, Is.EqualTo("New Title Testing"));
        }
예제 #5
0
        public async Task AskQuestion_WithNewCreatedQuestion_ShouldReturnOkStatusCodeResult()
        {
            //---------------Arrange----------------------
            var questionGarGateway  = Substitute.For <IQuestionGateway>();
            var requestUserProvider = Substitute.For <IRequestUserProvider>();
            var answerGateway       = Substitute.For <IAnswerGateway>();

            var question = new Question
            {
                AuthorId     = CreateUserId(),
                Id           = 0,
                Title        = "Test Question",
                Description  = "Test Question Description. From Acceptance tests",
                DateCreated  = DateTime.Now,
                LastModified = DateTime.Now
            };

            var existingQuestions = new List <Question>
            {
                new QuestionBuilder().WithTitle("tittle 1").Build(),
                new QuestionBuilder().WithTitle("tittle 2").Build(),
                new QuestionBuilder().WithTitle("tittle 3").Build(),
                new QuestionBuilder().WithTitle("tittle 4").Build(),
                new QuestionBuilder().WithTitle("title 5").Build()
            };

            var command = new AskQuestionCommandBuilder()
                          .WithExistingQuestionTitle(existingQuestions)
                          .WithValidUserId(question.AuthorId)
                          .Build();

            var sut = CreateQuestionCommand(questionGarGateway, answerGateway, requestUserProvider).AskQuestion(question, CancellationToken.None);

            //---------------Assert-----------------------
            requestUserProvider.Received(1).GetUserId();
        }