public void Can_run_activity_validatelineitems()
		{
			var orderGroup = CreateCart();

			orderGroup.OrderForms[0].LineItems[0].Catalog = "default";
			orderGroup.OrderForms[0].LineItems[0].CatalogItemId = "v-9948444183";
			orderGroup.OrderForms[0].LineItems[0].FulfillmentCenterId = "default";
			orderGroup.OrderForms[0].LineItems[0].Quantity = 4;
			orderGroup.OrderForms[0].LineItems[1].Catalog = "default";
			orderGroup.OrderForms[0].LineItems[1].CatalogItemId = "v-b000068ilf";
			orderGroup.OrderForms[0].LineItems[1].FulfillmentCenterId = "default";
			orderGroup.OrderForms[0].LineItems[1].Quantity = 10;


			var invAvailable = new Inventory
				{
					AllowBackorder = true,
					AllowPreorder = true,
					FulfillmentCenterId = "default",
					InStockQuantity = 10,
					Sku = "v-9948444183",
					ReservedQuantity = 1,
					Status = InventoryStatus.Enabled.GetHashCode(),
					BackorderQuantity = 5,
					PreorderQuantity = 3
				};

			var invNotAvailable = new Inventory
				{
					AllowBackorder = true,
					AllowPreorder = true,
					FulfillmentCenterId = "default",
					InStockQuantity = 14,
					Sku = "v-b000068ilf",
					ReservedQuantity = 10,
					BackorderQuantity = 10,
					Status = InventoryStatus.Enabled.GetHashCode(),
					PreorderQuantity = 4
				};

			var mockUnitOfWork = new Mock<IUnitOfWork>();
			var repository = new Mock<IInventoryRepository>();
			repository.Setup(x => x.Inventories).Returns(() => new[] { invAvailable, invNotAvailable }.AsQueryable());
			repository.Setup(x => x.UnitOfWork).Returns(mockUnitOfWork.Object);
			repository.SetupAllProperties();

			var item1 = new Product
				{
					ItemId = "v-9948444183",
					TrackInventory = true,
					IsActive = true,
					IsBuyable = true,
					StartDate = DateTime.UtcNow.AddDays(-1),
					EndDate = DateTime.UtcNow.AddDays(1)
				};

			var item2 = new Product
				{
					ItemId = "v-b000068ilf",
					IsActive = true,
					IsBuyable = true,
					TrackInventory = true,
					StartDate = DateTime.UtcNow.AddDays(-1),
					EndDate = DateTime.UtcNow.AddDays(1)
				};

			var catrepository = new Mock<ICatalogRepository>();
			catrepository.Setup(x => x.Items).Returns(() => new Item[] { item1, item2 }.AsQueryable());
			catrepository.Setup(x => x.UnitOfWork).Returns(mockUnitOfWork.Object);
			catrepository.SetupAllProperties();

			var store = new Store { StoreId = orderGroup.StoreId, Catalog = orderGroup.OrderForms[0].LineItems[0].Catalog };
			var storeRepository = new Mock<IStoreRepository>();
			storeRepository.Setup(x => x.Stores).Returns(() => new[] { store }.AsQueryable());

			var priceList = new Pricelist { PricelistId = "default", Currency = "USD" };
			var priceList2 = new Pricelist { PricelistId = "sale", Currency = "USD" };
			var prices = new[] 
            {
                new Price { List = 100, Sale = 90, MinQuantity = 1, ItemId = "v-9948444183" , PricelistId = "default"},
                new Price { List = 95, Sale = 85, MinQuantity = 5, ItemId = "v-9948444183", PricelistId = "default"},
                new Price { List = 98, Sale = 88, MinQuantity = 1, ItemId = "v-9948444183" , PricelistId = "sale"},
                new Price { List = 93, Sale = 83, MinQuantity = 5, ItemId = "v-9948444183", PricelistId = "sale"},
                new Price { List = 60, Sale = 50, MinQuantity = 1, ItemId = "v-b000068ilf" , PricelistId = "default"},
                new Price { List = 55, Sale = 45, MinQuantity = 5, ItemId = "v-b000068ilf", PricelistId = "default"},
                new Price { List = 58, Sale = 48, MinQuantity = 1, ItemId = "v-b000068ilf" , PricelistId = "sale"},
                new Price { List = 53, Sale = 43, MinQuantity = 5, ItemId = "v-b000068ilf", PricelistId = "sale"}

            };

			var priceRepository = new Mock<IPricelistRepository>();
			priceRepository.Setup(x => x.Pricelists).Returns(() => new[] { priceList2, priceList }.AsQueryable());
			priceRepository.Setup(x => x.Prices).Returns(prices.AsQueryable);

			var customerService = new CustomerSessionService();
			var session = customerService.CustomerSession;
			session.Currency = "USD";
			session.Pricelists = new[] { "Sale", "Default" };

			var currencyService = new CurrencyService();

			var cacheRepository = new Mock<ICacheRepository>();
			cacheRepository.SetupAllProperties();

			var activity = new ValidateLineItemsActivity(repository.Object, catrepository.Object, storeRepository.Object, customerService, priceRepository.Object, currencyService, null, null, cacheRepository.Object);

			var result = InvokeActivity(activity, orderGroup);

			var order = result.OrderGroup;
			// now check totals            

			// Order totals
			// Order form totals
			var form = order.OrderForms[0];

			Assert.True(form.LineItems.Count == 2);
			Assert.True(form.LineItems[0].InStockQuantity == 9);
			Assert.True(form.LineItems[0].PreorderQuantity == 3);
			Assert.True(form.LineItems[0].ListPrice == 88);
			Assert.True(form.LineItems[1].ListPrice == 43);
		}
		private static Product CreateProduct(string catalogId, string categoryId, string name, string propertySetId)
		{
			Product product = new Product();
			//product.CatalogId = catalogId;
			product.Name = name;
			product.Code = product.ItemId;
			product.StartDate = DateTime.Now.AddYears(-1);
			product.EndDate = DateTime.Now.AddYears(1);
			product.IsActive = true;
			product.CatalogId = catalogId;
			product.MinQuantity = 1;
			product.MaxQuantity = 10;

			product.Weight = 2.3m;
			product.TrackInventory = false;
			//product.SetPropertyValue<string>("Brand", brand);

			string description = @"The Nokia 2610 is an easy to use device that combines multiple messaging options including email, instant messaging, and more. You can even download MP3 ringtones, graphics, and games straight to the phone, or surf the Internet with Cingular's MEdia Net service. It's the perfect complement to Cingular service for those even remotely interested in mobile Web capabilities in an affordable handset.";

			product.ItemPropertyValues.Add(new ItemPropertyValue() { ItemId = product.ItemId, LongTextValue = description, Name = "Description" });

			string design = "Compact and stylish, the 2610 features a candybar design sporting a bright 128 x 128 pixel display capable of displaying over 65,000 colors. Most of the phone's features and on-screen menus are controlled by a center toggle on the control pad. A standard hands-free headphone jack is provided, as are volume control keys, and there's even a \"Go-To\" button that can be assigned by the user for quick access to favorite applications. Lastly, the included speakerphone allows you to talk handsfree, and because the phone sports an internal antenna, there's nothing to snag or break off.";
			product.ItemPropertyValues.Add(new ItemPropertyValue() { ItemId = product.ItemId, LongTextValue = design, Name = "Design" });
			product.ItemPropertyValues.Add(new ItemPropertyValue() { ItemId = product.ItemId, LongTextValue = "2610", Name = "Model" });

			//var propertySet = catalog.PropertySets[0];

			//product.PropertySet = propertySet;
			product.PropertySetId = propertySetId;

			////Add associations
			//AssociationGroup group = new AssociationGroup();

			//group.Description = "Related products";
			//group.Name = "RelatedProducts";
			//group.ItemId = product.ItemId;

			//Association association = new Association();
			//association.AssociationType = AssociationTypes.Optional;
			//association.ItemId = product.ItemId;
			////association.CatalogItem = product;
			//association.AssociationGroupId = group.AssociationGroupId;
			//group.Associations.Add(association);

			//product.AssociationGroups.Add(group);

			//AssociationGroup group2 = new AssociationGroup();
			//group2.Description = "Accessory products";
			//group2.Name = "ProductAccessories";
			//group2.ItemId = product.ItemId;

			//Association association2 = new Association();
			//association2.AssociationType = AssociationTypes.Optional;
			//association2.ItemId = product.ItemId;
			////association2.CatalogItem = product;
			//association2.AssociationGroupId = group2.AssociationGroupId;
			//group2.Associations.Add(association2);

			//product.AssociationGroups.Add(group2);


			ItemAsset asset = new ItemAsset();
			asset.AssetId = String.Format("catalog/{0}", "image");
			asset.AssetType = "file";
			asset.GroupName = "primaryimage";
			asset.ItemId = product.ItemId;
			asset.SortOrder = 1;

			product.ItemAssets.Add(asset);

			var relation = new CategoryItemRelation() { CatalogId = catalogId, CategoryId = categoryId, ItemId = product.ItemId };
			product.CategoryItemRelations.Add(relation);

			return product;
		}
		public void Can_run_activity_adjustinventory()
		{
			var invAvailable = new Inventory
				{
					AllowBackorder = true,
					AllowPreorder = true,
					BackorderAvailabilityDate = DateTime.Now,
					PreorderAvailabilityDate = DateTime.Now,
					FulfillmentCenterId = "default",
					InStockQuantity = 10,
					Sku = "v-9948444183",
					ReservedQuantity = 1,
					Status = InventoryStatus.Enabled.GetHashCode()
				};

			var invNotAvailable = new Inventory
				{
					AllowBackorder = true,
					AllowPreorder = true,
					BackorderAvailabilityDate = DateTime.Now,
					PreorderAvailabilityDate = DateTime.Now,
					FulfillmentCenterId = "default",
					InStockQuantity = 14,
					Sku = "v-b000068ilf",
					ReservedQuantity = 10,
					BackorderQuantity = 10,
					Status = InventoryStatus.Enabled.GetHashCode()
				};

			var mockUnitOfWork = new Mock<IUnitOfWork>();
			var repository = new Mock<IInventoryRepository>();
			repository.Setup(x => x.Inventories).Returns(() => new[] { invAvailable, invNotAvailable }.AsQueryable());
			repository.Setup(x => x.UnitOfWork).Returns(mockUnitOfWork.Object);
			repository.SetupAllProperties();

			var item1 = new Product
				{
					ItemId = "v-9948444183",
					TrackInventory = true
				};

			var item2 = new Product
				{
					ItemId = "v-b000068ilf",
					TrackInventory = true
				};
			var catrepository = new Mock<ICatalogRepository>();
			catrepository.Setup(x => x.Items).Returns(() => new Item[] { item1, item2 }.AsQueryable());
			catrepository.Setup(x => x.UnitOfWork).Returns(mockUnitOfWork.Object);
			catrepository.SetupAllProperties();

			var customerSession = new Mock<ICustomerSessionService>();

			var cacheRepository = new Mock<ICacheRepository>();
			cacheRepository.SetupAllProperties();

			var orderGroup = CreateCart();
			var activity = new AdjustInventoryActivity(catrepository.Object, repository.Object, customerSession.Object, cacheRepository.Object);
			//activity.InventoryRepository = _repository.Object;
			//activity.CatalogRepository = _catrepository.Object;

			orderGroup.OrderForms[0].LineItems[0].CatalogItemId = "v-9948444183";
			orderGroup.OrderForms[0].LineItems[0].FulfillmentCenterId = "default";
			orderGroup.OrderForms[0].LineItems[0].Quantity = 6;
			orderGroup.OrderForms[0].LineItems[1].CatalogItemId = "v-b000068ilf";
			orderGroup.OrderForms[0].LineItems[1].FulfillmentCenterId = "default";
			orderGroup.OrderForms[0].LineItems[1].Quantity = 10;

			InvokeActivity(activity, orderGroup);

			// validate adjusted inventory
			var inventory = repository.Object.Inventories.SingleOrDefault(i => i.FulfillmentCenterId.Equals("default", StringComparison.OrdinalIgnoreCase)
																			   && i.Sku.Equals("v-9948444183", StringComparison.OrdinalIgnoreCase));

			Assert.True(inventory != null && inventory.InStockQuantity == 4);

			inventory = repository.Object.Inventories.SingleOrDefault(i => i.FulfillmentCenterId.Equals("default", StringComparison.OrdinalIgnoreCase)
																		   && i.Sku.Equals("v-b000068ilf", StringComparison.OrdinalIgnoreCase));

			Assert.True(inventory != null && inventory.InStockQuantity == 10);
			Assert.True(inventory != null && inventory.BackorderQuantity == 4);
		}