func ConvertCategoryToViewModel(category models.Category) viewmodels.Category { result := viewmodels.Category{ ImageUrl: category.ImageUrl(), Title: category.Title(), Description: category.Description(), IsOrientRight: category.IsOrientRight(), Id: category.Id(), } return result }
func ConvertCategoryToViewModel(category models.Category) viewmodels.Category { result := viewmodels.Category{ ImageUrl: category.ImageUrl(), Title: category.Title(), Description: category.Description(), IsOrientRight: category.IsOrientRight(), Id: category.Id(), } for _, p := range category.Products() { result.Products = append(result.Products, ConvertProductToViewModel(p)) } return result }
func Test_ConvertsCategoryToViewModel(t *testing.T) { category := models.Category{} category.SetImageUrl("the image URL") category.SetTitle("the title") category.SetDescription("the description") category.SetIsOrientRight(true) category.SetId(42) category.SetProducts([]models.Product{ models.Product{}, models.Product{}, }) result := ConvertCategoyToViewModel(category) if result.ImageUrl != category.ImageUrl() { t.Log("Image URL not converted properly") t.Fail() } if result.Title != category.Title() { t.Log("Title not converted properly") t.Fail() } if result.Description != category.Description() { t.Log("Description not converted properly") t.Fail() } if result.IsOrientRight != category.IsOrientRight() { t.Log("IsOrientRight not converted properly") t.Fail() } if result.Id != category.Id() { t.Log("Id not converted properly") t.Fail() } if len(result.Products) != len(category.Products()) { t.Log("Products not converted properly") t.Fail() } }