Пример #1
0
func ConvertProductToViewModel(product models.Product) viewmodels.Product {
	result := viewmodels.Product{
		Name:             product.Name(),
		DescriptionShort: product.DescriptionShort(),
		DescriptionLong:  product.DescriptionLong(),
		PricePerLitre:    product.PricePerLitre(),
		PricePer10Litre:  product.PricePer10Litre(),
		Origin:           product.Origin(),
		IsOrganic:        product.IsOrganic(),
		ImageUrl:         product.ImageUrl(),
		Id:               product.Id(),
	}

	return result
}
Пример #2
0
func Test_ConvertsProductToViewModel(t *testing.T) {
	product := models.Product{}
	product.SetName("the name")
	product.SetDescriptionShort("the short description")
	product.SetDescriptionLong("the long description")
	product.SetPricePerLitre(42.127)
	product.SetPricePer10Litre(27.314)
	product.SetOrigin("the origin")
	product.SetIsOrganic(true)
	product.SetImageUrl("the image URL")
	product.SetId(42)

	result := ConvertProductToViewModel(product)

	if product.Name() != result.Name {
		t.Fail()
	}
	if product.DescriptionShort() != result.DescriptionShort {
		t.Fail()
	}
	if product.DescriptionLong() != result.DescriptionLong {
		t.Fail()
	}
	if product.PricePerLitre() != result.PricePerLitre {
		t.Fail()
	}
	if product.PricePer10Litre() != result.PricePer10Litre {
		t.Fail()
	}
	if product.Origin() != result.Origin {
		t.Fail()
	}
	if product.IsOrganic() != result.IsOrganic {
		t.Fail()
	}
	if product.ImageUrl() != result.ImageUrl {
		t.Fail()
	}
	if product.Id() != result.Id {
		t.Fail()
	}
}