Пример #1
0
        public void GetAllCategoriesOfAGroup_idIsNull_ReturnEmptyList()
        {
            // Given
            CategoryServices service = new CategoryServices(null, null);

            // When
            IList<CategoryItemModel> result = service.GetAllCategoriesOfAGroup(null);

            // Then
            Assert.AreEqual(0, result.Count);
        }
Пример #2
0
        public void GetAllCategoriesOfAGroup_aCategoryItem_ReturnAllSubCategoriesAndParentCategory()
        {
            // Given
            Category group = new Category
            {
                Id = 7,
                Label = "huhu"
            };
            Category subC1 = new Category
            {
                Id = 8,
                ParentCategory = group,
                Label = "toto"
            };
            group.SubCategories.Add(subC1);
            Category subC2 = new Category
            {
                Id = 9,
                ParentCategory = group,
                Label = "titi"
            };
            group.SubCategories.Add(subC2);
            Category subC3 = new Category
            {
                Id = 13,
                ParentCategory = group,
                Label = "tutu"
            };
            group.SubCategories.Add(subC3);

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(9)).Returns(subC2);

            CategoryServices service = new CategoryServices(repoMock.Object, null);

            // When
            IList<CategoryItemModel> result = service.GetAllCategoriesOfAGroup(9);

            // Then
            Assert.AreEqual(4, result.Count);
            Assert.AreEqual(7, result[0].Id);
            Assert.AreEqual(8, result[1].Id);
            Assert.AreEqual(9, result[2].Id);
            Assert.AreEqual(13, result[3].Id);
            Assert.AreEqual("HUHU", result[0].Label);
            Assert.AreEqual("toto", result[1].Label);
            Assert.AreEqual("titi", result[2].Label);
            Assert.AreEqual("tutu", result[3].Label);
        }
Пример #3
0
        public void GetAllCategoriesOfAGroup_groupDoesNotExists_ReturnEmptyList()
        {
            // Given

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(7)).Returns(null as Category);

            CategoryServices service = new CategoryServices(repoMock.Object, null);

            // When
            IList<CategoryItemModel> result = service.GetAllCategoriesOfAGroup(7);

            // Then
            Assert.AreEqual(0, result.Count);
        }