public void FindAll_Returns_All_Categories() { var fixture = new Fixture(); var contextMock = new Mock <ISupportAppContext>(); var sut = new CategoryFinder(contextMock.Object); var expectedTicket1 = new Category("test1"); var expectedTicket2 = new Category("test2"); var expectedTicket3 = new Category("test3"); var categories = new[] { expectedTicket1, expectedTicket2, expectedTicket3, }; contextMock.Setup(c => c.Queryable <Category>()) .Returns(categories.AsQueryable()); //act var result = sut.FindAll(); //assert result.Should().BeEquivalentTo(expectedTicket1, expectedTicket2, expectedTicket3); }
/// <summary> /// Creates a category hierarchy based on a DOS style path (folder delimiter is "\") /// </summary> /// <param name="parentCategoryId">The id of the parent category, 0 belongs to root</param> /// <param name="brandId">The brand ID</param> /// <param name="path">DOS style path statement (excluding drive letter:)</param> /// <param name="user">The user creating the category</param> /// <returns>The ID of the lowest level category</returns> public static int CreateCategoryTreeFromPath(int?parentCategoryId, int brandId, string path, User user) { var folders = from f in path.Split('\\', '/') where !f.Contains(':') && f != string.Empty select f; int?currentParentId = parentCategoryId; int?newId = parentCategoryId; // Create a finder and pre-load the BrandId as this won't be changing CategoryFinder finder = new CategoryFinder { BrandId = brandId }; foreach (string folder in folders) { // Check to see if the category already exists finder.ParentCategoryId = currentParentId; finder.Name = folder; Category existingCategory = Category.FindOne(finder); if (existingCategory.IsNull) { newId = CreateCategory(currentParentId, brandId, folder, string.Empty, string.Empty, string.Empty, user); } else { newId = existingCategory.CategoryId; } currentParentId = newId; } return(newId.GetValueOrDefault()); }
private static IList <Category> GetParentCategories(int brandId) { CategoryFinder finder = new CategoryFinder { BrandId = brandId, ParentCategoryId = Int32.MinValue }; return(Category.FindMany(finder)); }
public void TestCategoryFinder() { int categoryId = 6; CategoryFinder categoryFinder = new CategoryFinder(); CategoryGateway categoryGateway = categoryFinder.FindCategoryGatewayById(categoryId); Assert.AreEqual(categoryId, categoryGateway.CategoryID); Assert.AreEqual("Meat/Poultry", categoryGateway.CategoryName); Assert.AreEqual("Prepared meats", categoryGateway.Description); }
public void TestIdentityMapOfCategoryFinder() { int categoryId = 6; int anotherCategoryId = 8; CategoryFinder categoryFinder = new CategoryFinder(); CategoryGateway categoryGateway1 = categoryFinder.FindCategoryGatewayById(categoryId); CategoryGateway categoryGateway2 = categoryFinder.FindCategoryGatewayById(categoryId); Assert.AreEqual(categoryGateway1, categoryGateway2); CategoryGateway categoryGateway3 = categoryFinder.FindCategoryGatewayById(anotherCategoryId); Assert.AreNotEqual(categoryGateway1, categoryGateway3); Assert.AreNotEqual(categoryGateway2, categoryGateway3); }
public void Find_Returns_Category_With_Given_Id() { var fixture = new Fixture(); var contextMock = new Mock <ISupportAppContext>(); var sut = new CategoryFinder(contextMock.Object); var expectedTicket = fixture.Create <Category>(); contextMock.Setup(c => c.FindById <Category>(22)) .Returns(expectedTicket); //act var result = sut.Find(22); //assert result.Should().Be(expectedTicket); }
private static void UpdateCategories() { DataContext.ConnectionString = ConfigurationManager.AppSettings.Get("ConnectionString"); var finder = new CategoryFinder(); var list = Category.FindMany(finder); foreach (var category in list) { var categoryId = category.CategoryId.GetValueOrDefault(); var publishedCount = CategoryManager.GetPublishedAssetCount(categoryId); var fullCount = CategoryManager.GetFullAssetCount(categoryId); category.AvailableAssetCount = publishedCount; category.FullAssetCount = fullCount; Category.Update(category); m_Logger.DebugFormat("Updated category: {0} - Published count: {1}, Full Count: {2}", category.Name, publishedCount, fullCount); } CacheManager.InvalidateCache("Category", CacheType.All); }