Пример #1
0
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
}
Пример #2
0
func ConvertCategoryToViewModel(category models.Category) viewmodels.Category {

	result := viewmodels.Category{
		ImageUrl:       category.ImageUrl(),
		Id:             category.Id(),
		SampleProducts: category.SampleProducts(),
		Title:          category.Title(),
	}

	return result
}
Пример #3
0
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()
	}
}
Пример #4
0
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
}
Пример #5
0
func Test_ConvertsCategoryToViewModel(t *testing.T) {
	category := models.Category{}
	category.SetImageUrl("image url")
	category.SetTitle("title")
	category.SetDescription("description")
	category.SetIsOrientRight(true)
	category.SetId(42)

	result := ConvertCategoryToViewModel(category)

	if result.ImageUrl != category.ImageUrl() {
		t.Log("Image url not converted properly")
		t.Fail()
	}

	//ToDo - Add tests for the remaining attributes
}
Пример #6
0
func Test_ConvertsCategoryToViewModel(t *testing.T) {
	category := models.Category{}
	category.SetImageUrl("the image URL")
	category.SetTitle("the title")
	category.SetDescription("the description")
	category.SetId(42)
	isOrientRight := true

	result := ConvertCategoryToViewModel(category, isOrientRight)

	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 != isOrientRight {
		t.Log("IsOrientRight not converted properly")
		t.Fail()
	}

	if result.Id != category.Id() {
		t.Log("Id not converted properly")
		t.Fail()
	}

}