-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
198 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/dwCheckApi.Tests/ViewModelMappers/CharacterViewModelMapperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using dwCheckApi.DTO.Helpers; | ||
using Xunit; | ||
|
||
namespace dwCheckApi.Tests.ViewModelMappers | ||
{ | ||
public class CharacterViewModelMapperTests | ||
{ | ||
[Fact] | ||
public void Given_CharacterDbModel_Returns_ViewModel() | ||
{ | ||
// Arrange | ||
var characterName = Guid.NewGuid().ToString(); | ||
var books = new Dictionary<int, string> | ||
{ | ||
// intentionally added out of order ot test the ordering of the final Dictionary | ||
{ 2, Guid.NewGuid().ToString() }, | ||
{ 1, Guid.NewGuid().ToString() } | ||
}; | ||
|
||
// Act | ||
var response = CharacterViewModelHelpers.ConvertToViewModel(characterName, books); | ||
|
||
// Assert | ||
Assert.Equal(response.CharacterName, characterName); | ||
Assert.Equal(response.Books.Count, books.Count); | ||
|
||
var first = response.Books.First(); | ||
Assert.Equal(1, first.Key); | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
tests/dwCheckApi.Tests/ViewModelMappers/SeriesViewModelMapperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using dwCheckApi.DTO.Helpers; | ||
using dwCheckApi.Entities; | ||
using Xunit; | ||
|
||
namespace dwCheckApi.Tests.ViewModelMappers | ||
{ | ||
public class SeriesViewModelMapperTests | ||
{ | ||
[Fact] | ||
public void Given_SeriesDbModel_Returns_ViewModel() | ||
{ | ||
// Arrange | ||
var dbBook = new Book | ||
{ | ||
BookName = Guid.NewGuid().ToString() | ||
}; | ||
var dbSeries = new Series | ||
{ | ||
SeriesId = 1, | ||
SeriesName = Guid.NewGuid().ToString(), | ||
BookSeries = new List<BookSeries> | ||
{ | ||
new() | ||
{ | ||
Book = dbBook | ||
} | ||
} | ||
}; | ||
|
||
// Act | ||
var viewModel = SeriesViewModelHelpers.ConvertToViewModel(dbSeries); | ||
|
||
// Assert | ||
Assert.Equal(dbSeries.SeriesId, viewModel.SeriesId); | ||
Assert.Equal(dbSeries.SeriesName, viewModel.SeriesName); | ||
Assert.Equal(dbSeries.BookSeries.First().Book.BookName, viewModel.BookNames.First()); | ||
} | ||
|
||
[Fact] | ||
public void Given_ListOfSeriesDbModel_Returns_ListOfViewModel() | ||
{ | ||
// Arrange | ||
var dbSeries = new List<Series> | ||
{ | ||
new() | ||
{ | ||
SeriesId = 1, | ||
SeriesName = Guid.NewGuid().ToString(), | ||
BookSeries = new List<BookSeries>() | ||
} | ||
}; | ||
|
||
// Act | ||
var viewModels = SeriesViewModelHelpers.ConvertToViewModels(dbSeries); | ||
|
||
// Assert | ||
Assert.NotNull(viewModels); | ||
Assert.NotEmpty(viewModels); | ||
Assert.Equal(dbSeries.Count, viewModels.Count); | ||
|
||
for (var i = 0; i < viewModels.Count; i++) | ||
{ | ||
Assert.Equal(dbSeries[i].SeriesId, viewModels[i].SeriesId); | ||
Assert.Equal(dbSeries[i].SeriesName, viewModels[i].SeriesName); | ||
} | ||
} | ||
} | ||
} |