Skip to content

Commit

Permalink
✅ correcting and updating unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
larismourullo committed Nov 17, 2020
1 parent 2450843 commit 4d7c561
Showing 1 changed file with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ public void Should_ReturnEnumerableWithTenItems_When_SearchingTranslationsWithou
var controller = new TranslationsController(context);

var searchResult = controller.SearchTranslations(null) as OkObjectResult;
var response = searchResult.Value as SearchTranslationResponse;

Assert.IsAssignableFrom<IEnumerable<SearchTranslationResult>>(searchResult.Value);
Assert.True((searchResult.Value as IEnumerable<SearchTranslationResult>).Count() == 10);
Assert.IsAssignableFrom<SearchTranslationResponse>(searchResult.Value);
Assert.True(response.Translations.Count() == 10);
}

[Fact]
Expand All @@ -73,12 +74,12 @@ public void Should_ReturnPageTwo_When_SearchingPageTwo()
var controller = new TranslationsController(context);

var searchResult = controller.SearchTranslations(null, 2) as OkObjectResult;
var response = searchResult.Value as SearchTranslationResponse;

Assert.IsAssignableFrom<IEnumerable<SearchTranslationResult>>(searchResult.Value);

var result = searchResult.Value as IEnumerable<SearchTranslationResult>;
Assert.True(result.Count() == 10);
Assert.True(result.First().Id == 11);
Assert.IsAssignableFrom<SearchTranslationResponse>(searchResult.Value);
Assert.True(response.Translations.Count() == 10);
Assert.True(response.Translations.First().Id == 11);
Assert.True(response.Pagination.Page == 2);
}

[Fact]
Expand All @@ -87,12 +88,12 @@ public void Should_ReturnPageThree_When_SearchingPageThree()
var controller = new TranslationsController(context);

var searchResult = controller.SearchTranslations(null, 3) as OkObjectResult;
var response = searchResult.Value as SearchTranslationResponse;

Assert.IsAssignableFrom<IEnumerable<SearchTranslationResult>>(searchResult.Value);

var result = searchResult.Value as IEnumerable<SearchTranslationResult>;
Assert.True(result.Count() == 5);
Assert.True(result.First().Id == 21);
Assert.IsAssignableFrom<SearchTranslationResponse>(searchResult.Value);
Assert.True(response.Translations.Count() == 5);
Assert.True(response.Translations.First().Id == 21);
Assert.True(response.Pagination.Page == 3);
}

[Theory]
Expand All @@ -103,12 +104,12 @@ public void Should_ReturnFirstPage_When_SearchingInvalidPage(int pageNumber)
var controller = new TranslationsController(context);

var searchResult = controller.SearchTranslations(null, pageNumber) as OkObjectResult;
var response = searchResult.Value as SearchTranslationResponse;

Assert.IsAssignableFrom<IEnumerable<SearchTranslationResult>>(searchResult.Value);

var result = searchResult.Value as IEnumerable<SearchTranslationResult>;
Assert.True(result.Count() == 10);
Assert.True(result.First().Id == 1);
Assert.IsAssignableFrom<SearchTranslationResponse>(searchResult.Value);
Assert.True(response.Translations.Count() == 10);
Assert.True(response.Translations.First().Id == 1);
Assert.True(response.Pagination.Page == 1);
}

[Theory]
Expand All @@ -119,10 +120,12 @@ public void Should_ReturnDefaultNumberOfRecords_When_SearchingInvalidNumberOfRec
{
var controller = new TranslationsController(context);

var searchResult = controller.SearchTranslations(null, recordsPerPage: recordsPerPage) as OkObjectResult;
var searchResult = controller.SearchTranslations(null, pageSize: recordsPerPage) as OkObjectResult;
var response = searchResult.Value as SearchTranslationResponse;

Assert.IsAssignableFrom<IEnumerable<SearchTranslationResult>>(searchResult.Value);
Assert.True((searchResult.Value as IEnumerable<SearchTranslationResult>).Count() == 10);
Assert.IsAssignableFrom<SearchTranslationResponse>(searchResult.Value);
Assert.True(response.Translations.Count() == 10);
Assert.True(response.Pagination.PageSize == 10);
}

[Theory]
Expand All @@ -134,10 +137,11 @@ public void Should_FilterByTitle_When_UserSentAQuery(string query)
var controller = new TranslationsController(context);

var searchResult = controller.SearchTranslations(query: query) as OkObjectResult;
var response = searchResult.Value as SearchTranslationResponse;

var result = searchResult.Value as IEnumerable<SearchTranslationResult>;
Assert.True(result.All(t => t.Title.Contains(query)));
Assert.True(result.Any());
Assert.IsAssignableFrom<SearchTranslationResponse>(searchResult.Value);
Assert.True(response.Translations.All(t => t.Title.Contains(query)));
Assert.True(response.Translations.Any());
}

[Theory]
Expand All @@ -149,10 +153,11 @@ public void Should_FilterByAuthor_When_UserSentAQuery(string query)
var controller = new TranslationsController(context);

var searchResult = controller.SearchTranslations(query: query) as OkObjectResult;
var response = searchResult.Value as SearchTranslationResponse;

var result = searchResult.Value as IEnumerable<SearchTranslationResult>;
Assert.True(result.All(t => t.Author.Contains(query)));
Assert.True(result.Any());
Assert.IsAssignableFrom<SearchTranslationResponse>(searchResult.Value);
Assert.True(response.Translations.All(t => t.Author.Contains(query)));
Assert.True(response.Translations.Any());
}

[Theory]
Expand All @@ -164,10 +169,11 @@ public void Should_FilterByTranslator_When_UserSentAQuery(string query)
var controller = new TranslationsController(context);

var searchResult = controller.SearchTranslations(query: query) as OkObjectResult;
var response = searchResult.Value as SearchTranslationResponse;

var result = searchResult.Value as IEnumerable<SearchTranslationResult>;
Assert.True(result.All(t => t.Translator.Contains(query)));
Assert.True(result.Any());
Assert.IsAssignableFrom<SearchTranslationResponse>(searchResult.Value);
Assert.True(response.Translations.All(t => t.Translator.Contains(query)));
Assert.True(response.Translations.Any());
}
}
}

0 comments on commit 4d7c561

Please sign in to comment.