Beispiel #1
0
        public async Task Handle_ReturnsMatchesThatDontIncludeDrafts_WhenManyTitlesMatch_ButSomeAreDrafts(
            int expectedAmount, int drafts)
        {
            //arrange
            for (var i = 0; i < expectedAmount; i++)
            {
                DbContext.Prompts.Add(new Prompt {
                    Title = "TestTitle", PromptContent = "TestContent"
                });
            }

            for (var i = 0; i < drafts; i++)
            {
                DbContext.Prompts.Add(new Prompt {
                    Title = "TestTitle", PromptContent = "TestContent", IsDraft = true
                });
            }

            await DbContext.SaveChangesAsync();

            var query = new SimilarPromptQuery("TestTitle");

            //act
            SimilarPromptViewModel?actual = await _handler.Handle(query);

            //assert
            Assert.True(actual.Matched);
            Assert.Equal(expectedAmount, actual.SimilarPrompts.Count);
        }
Beispiel #2
0
        public async Task Handle_ReturnsExpectedMatches_WhenThereAreTitleMatches_AndOnePromptMatchesId(
            int expectedMatches)
        {
            //arrange
            var prompt = new Prompt {
                Title = "TestTitle", PromptContent = "TestContent"
            };

            DbContext.Prompts.Add(prompt);
            for (var i = 0; i < expectedMatches; i++)
            {
                DbContext.Prompts.Add(new Prompt {
                    Title = "TestTitle", PromptContent = "TestContent"
                });
            }

            await DbContext.SaveChangesAsync();

            var query = new SimilarPromptQuery("TestTitle", prompt.Id);

            //act
            SimilarPromptViewModel?actual = await _handler.Handle(query);

            //assert
            Assert.True(actual.Matched);
            Assert.Equal(expectedMatches, actual.SimilarPrompts.Count);
        }
        public async Task ValidateAsync_ReturnsValid_WhenTitleHasValue_AndIdIsHasValue(int id)
        {
            //arrange
            var query = new SimilarPromptQuery("Value", id);

            //act
            ValidationResult?actual = await _validator.ValidateAsync(query);

            //assert
            Assert.True(actual.IsValid);
        }
        public async Task ValidateAsync_ReturnsNotValid_WhenTitleIsEmpty_AndIdIsDefault(string title)
        {
            //arrange
            var query = new SimilarPromptQuery(title);

            //act
            ValidationResult?actual = await _validator.ValidateAsync(query);

            //assert
            Assert.False(actual.IsValid);
        }
Beispiel #5
0
        public async Task Handle_ReturnsNoMatches_WhenDatabaseIsEmpty()
        {
            //arrange
            var query = new SimilarPromptQuery("TestTitle");

            //act
            SimilarPromptViewModel?actual = await _handler.Handle(query);

            //assert
            Assert.False(actual.Matched);
            Assert.Empty(actual.SimilarPrompts);
        }
Beispiel #6
0
        public async Task Handle_ReturnsOneMatch_WhenOneTitleMatches()
        {
            //arrange
            DbContext.Prompts.Add(new Prompt {
                Title = "TestTitle", PromptContent = "TestContent"
            });
            await DbContext.SaveChangesAsync();

            var query = new SimilarPromptQuery("TestTitle");

            //act
            SimilarPromptViewModel?actual = await _handler.Handle(query);

            //assert
            Assert.True(actual.Matched);
            Assert.Single(actual.SimilarPrompts);
        }
Beispiel #7
0
        public async Task Handle_ReturnsNoMatches_WhenThereAreNoSimilarPrompts()
        {
            //arrange
            DbContext.Prompts.Add(new Prompt {
                Title = "TestTitle", PromptContent = "TestContent"
            });
            await DbContext.SaveChangesAsync();

            var query = new SimilarPromptQuery("NewTitle");

            //act
            SimilarPromptViewModel?actual = await _handler.Handle(query);

            //assert
            Assert.False(actual.Matched);
            Assert.Empty(actual.SimilarPrompts);
        }