From 8c1ef192b18d5ca41a26f9ce0d8abe98705a84ec Mon Sep 17 00:00:00 2001 From: haraldnilsen Date: Thu, 12 Oct 2023 12:20:09 +0200 Subject: [PATCH] :white_check_mark: tests for all validators complete Co-authored-by: Sindre Kjelsrud --- .../QueryParameterValidatorsTests.cs | 70 ++++++++++++++++--- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/backend/cinemateketTests/ValidatorTests/QueryParameterValidatorsTests.cs b/backend/cinemateketTests/ValidatorTests/QueryParameterValidatorsTests.cs index 4a11fca..17e291a 100644 --- a/backend/cinemateketTests/ValidatorTests/QueryParameterValidatorsTests.cs +++ b/backend/cinemateketTests/ValidatorTests/QueryParameterValidatorsTests.cs @@ -5,14 +5,66 @@ using backend; public class QueryParameterValidatorsTests { [Theory] - [InlineData("Star Wars", true)] - [InlineData("", false)] - [InlineData(null, false)] - public void IsValidS_ShouldReturnExpectedResult(string input, bool expectedResult) - { - bool result = QueryParameterValidators.IsValidS(input); - Assert.Equal(expectedResult, result); - } + [InlineData("Star Wars", true)] + [InlineData("", false)] + [InlineData(null, false)] + public void IsValidS_ShouldReturnExpectedResult(string input, bool expectedResult) + { + bool result = QueryParameterValidators.IsValidS(input); + Assert.Equal(expectedResult, result); + } - // Add more tests for other validators + [Theory] + [InlineData("movie", true)] + [InlineData("series", true)] + [InlineData("episode", true)] + [InlineData("unknown", false)] + [InlineData(null, true)] + public void IsValidType_ShouldReturnExpectedResult(string input, bool expectedResult) + { + bool result = QueryParameterValidators.IsValidType(input); + Assert.Equal(expectedResult, result); + } + + [Theory] + [InlineData("2021", true)] + [InlineData("1899", false)] + [InlineData(null, true)] + public void IsValidYear_ShouldReturnExpectedResult(string input, bool expectedResult) + { + bool result = QueryParameterValidators.IsValidYear(input); + Assert.Equal(expectedResult, result); + } + + [Theory] + [InlineData("titleasc", true)] + [InlineData("titledesc", true)] + [InlineData("unknown", false)] + [InlineData(null, true)] + public void IsValidSort_ShouldReturnExpectedResult(string input, bool expectedResult) + { + bool result = QueryParameterValidators.IsValidSort(input); + Assert.Equal(expectedResult, result); + } + + [Theory] + [InlineData(1, true)] + [InlineData(0, false)] + [InlineData(-1, false)] + public void IsValidPageNumber_ShouldReturnExpectedResult(int input, bool expectedResult) + { + bool result = QueryParameterValidators.IsValidPageNumber(input); + Assert.Equal(expectedResult, result); + } + + [Theory] + [InlineData(1, true)] + [InlineData(100, true)] + [InlineData(0, false)] + [InlineData(101, false)] + public void IsValidPageSize_ShouldReturnExpectedResult(int input, bool expectedResult) + { + bool result = QueryParameterValidators.IsValidPageSize(input); + Assert.Equal(expectedResult, result); + } } \ No newline at end of file