Created
March 10, 2010 20:44
-
-
Save joeygreen/328363 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Data.Linq; | |
using System.Text; | |
using NUnit.Framework; | |
using Sandow.LuxeSource.Models; | |
namespace Sandow.LuxeSource.Tests | |
{ | |
[TestFixture] | |
public class PhotoTests | |
{ | |
SourcePhotoRepository repo = new SourcePhotoRepository(); | |
SourceDataContext db = new SourceDataContext(); | |
//[Test] | |
//public void WeightedQueryTest() | |
//{ | |
// foreach (Photo photo in repo.GetPhotosByPropertyWeight(2, "IL", 36, 6, null)) | |
// { | |
// Console.Write("Id: {0}\rName: {1}\r", photo.Id, photo.Title); | |
// } | |
// //SET @CategoryId = 2 -- 2=Kitchens | |
// //SET @UserState = 'AZ' | |
// //SET @BusinessCategoryId = 36 -- 35=Interior Designers&36=Kitchen & Bath Designers | |
// //SET @AttributeValueId1 = 6 -- white & cream | |
//} | |
[Test] | |
public void GetTopTwoCategoryAttributesTest() | |
{ | |
Photo currentEditorialPhoto = repo.ReadPhoto(2396); | |
Category mainCategory = currentEditorialPhoto.CategoryHierarchies.First().Category1 != null | |
? currentEditorialPhoto.CategoryHierarchies.First().Category1 | |
: currentEditorialPhoto.CategoryHierarchies.First().Category; | |
var av1 = (from attributeValue in db.AttributeValues | |
join photoAttribute in db.PhotoAttributes | |
on attributeValue.Id equals photoAttribute.AttributeValueId | |
where attributeValue.AttributeNameId == mainCategory.CategoryAttributes.OrderBy(a => a.Sort).ToList()[0].AttributeName.Id | |
&& photoAttribute.PhotoId == currentEditorialPhoto.Id | |
&& photoAttribute.CategoryId == mainCategory.Id | |
select attributeValue); | |
var av2 = (from attributeValue in db.AttributeValues | |
join photoAttribute in db.PhotoAttributes | |
on attributeValue.Id equals photoAttribute.AttributeValueId | |
where attributeValue.AttributeNameId == mainCategory.CategoryAttributes.OrderBy(a => a.Sort).ToList()[1].AttributeName.Id | |
&& photoAttribute.PhotoId == currentEditorialPhoto.Id | |
&& photoAttribute.CategoryId == mainCategory.Id | |
select attributeValue); | |
foreach (Photo photo in repo.GetPhotosByPropertyWeight(mainCategory.Id, "IL", 36, ((AttributeValue)av1.First()).Id, ((AttributeValue)av2.First()).Id)) | |
{ | |
Console.Write("Category: {2}\rAttribute One: {3}\rAttribute Two: {4}\rPhoto Id: {0}\rPhoto Name: {1}\r", photo.Id, photo.Title, mainCategory.Name, ((AttributeValue)av1.First()).Name, ((AttributeValue)av2.First()).Name); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment