예제 #1
0
        public async Task RemoveParentForCategory_Should_Remove_The_Category_Parent()
        {
            var category = Category.Create("code", "name", "url");
            var parent   = Category.Create("parent", "parent", "parent");

            category.SetParentCategory(parent);

            var repositoryMock = new Mock <Repository.IRepository>();

            repositoryMock.Setup(r => r.GetByKeyAsync <Category>(category.Id))
            .Returns(Task.FromResult(category));

            repositoryMock.Setup(r => r.GetByKeyAsync <Category>(parent.Id))
            .Returns(Task.FromResult(parent));

            Repository.IRepository        repository = repositoryMock.Object;
            Core.Infrastructure.IEventBus eventBus   = new Mock <Core.Infrastructure.IEventBus>().Object;

            Guid categoryId = category.Id;
            Guid parentId   = parent.Id;

            var commands = new CategoryCommands(repository, eventBus);
            await commands.RemoveParentForCategory(categoryId, parentId);

            Assert.Null(category.Parent);
        }
예제 #2
0
        public async Task UpdateCategoryInfo_Should_Update_Category_With_Specified_Values()
        {
            var category = Category.Create("mycode", "Category name", "category-url");

            var repositoryMock = new Mock <Repository.IRepository>();

            repositoryMock.Setup(r => r.GetByKeyAsync <Category>(It.IsAny <Guid>()))
            .Returns(Task.FromResult(category));

            Repository.IRepository        repository = repositoryMock.Object;
            Core.Infrastructure.IEventBus eventBus   = new Mock <Core.Infrastructure.IEventBus>().Object;

            Guid     categoryId  = category.Id;
            string   code        = "code";
            string   name        = "name";
            string   url         = "url";
            string   description = "description";
            bool     isVisible   = true;
            DateTime?visibleFrom = DateTime.Today;
            DateTime?visibleTo   = DateTime.Today.AddYears(1);

            var commands = new CategoryCommands(repository, eventBus);
            await commands.UpdateCategoryInfo(categoryId, code, name, url, description, isVisible, visibleFrom, visibleTo);

            Assert.Equal(code, category.Code);
            Assert.Equal(name, category.Name);
            Assert.Equal(url, category.Url);
            Assert.Equal(description, category.Description);
            Assert.Equal(isVisible, category.IsVisible);
            Assert.Equal(visibleFrom, category.VisibleFrom);
            Assert.Equal(visibleTo, category.VisibleTo);
        }
예제 #3
0
        public async Task CreateNewCategory_Should_Create_A_New_Category_And_Return_The_Created_Category_Id()
        {
            var fakeCategoryList = new List <Category>();
            var repositoryMock   = new Mock <Repository.IRepository>();

            repositoryMock.Setup(r => r.Add(It.IsAny <Category>()))
            .Callback <Category>((category) => fakeCategoryList.Add(category));

            Repository.IRepository        repository = repositoryMock.Object;
            Core.Infrastructure.IEventBus eventBus   = new Mock <Core.Infrastructure.IEventBus>().Object;

            string   code        = "code";
            string   name        = "name";
            string   url         = "url";
            string   description = "description";
            bool     isVisible   = true;
            DateTime?visibleFrom = DateTime.Today;
            DateTime?visibleTo   = DateTime.Today.AddYears(1);

            var commands   = new CategoryCommands(repository, eventBus);
            var categoryId = await commands.CreateNewCategory(code, name, url, description, isVisible, visibleFrom, visibleTo);

            var createdCategory = fakeCategoryList.FirstOrDefault(c => c.Id == categoryId);

            Assert.NotNull(createdCategory);
            Assert.Equal(code, createdCategory.Code);
            Assert.Equal(name, createdCategory.Name);
            Assert.Equal(url, createdCategory.Url);
            Assert.Equal(description, createdCategory.Description);
            Assert.Equal(isVisible, createdCategory.IsVisible);
            Assert.Equal(visibleFrom, createdCategory.VisibleFrom);
            Assert.Equal(visibleTo, createdCategory.VisibleTo);
        }
예제 #4
0
        public async Task RemoveChildForCategory_Should_Remove_Child_From_The_Category_Children()
        {
            var category = Category.Create("mycode", "Category name", "category-url");
            var child    = Category.Create("childcode", "Child", "child");

            category.AddChild(child);

            var repositoryMock = new Mock <Repository.IRepository>();

            repositoryMock.Setup(r => r.GetByKeyAsync <Category>(category.Id))
            .Returns(Task.FromResult(category));

            repositoryMock.Setup(r => r.GetByKeyAsync <Category>(child.Id))
            .Returns(Task.FromResult(child));

            Repository.IRepository        repository = repositoryMock.Object;
            Core.Infrastructure.IEventBus eventBus   = new Mock <Core.Infrastructure.IEventBus>().Object;

            Guid categoryId = category.Id;
            Guid childId    = child.Id;

            var commands = new CategoryCommands(repository, eventBus);
            await commands.RemoveChildForCategory(categoryId, childId);

            Assert.False(category.Children.Contains(child));
        }
예제 #5
0
        public async Task RestoreCategory_Should_Return_ArgumentException_If_CategoryId_Is_Empty()
        {
            Repository.IRepository        repository = new Mock <Repository.IRepository>().Object;
            Core.Infrastructure.IEventBus eventBus   = new Mock <Core.Infrastructure.IEventBus>().Object;

            Guid categoryId = Guid.Empty;

            var commands = new CategoryCommands(repository, eventBus);
            var ex       = await Assert.ThrowsAsync <ArgumentException>(() => commands.RestoreCategory(categoryId));

            Assert.Equal(nameof(categoryId), ex.ParamName);
        }
예제 #6
0
        public async Task SetCategorySeoData_Should_Throw_ArgumentException_If_CategoryId_Is_Empty()
        {
            Repository.IRepository        repository = new Mock <Repository.IRepository>().Object;
            Core.Infrastructure.IEventBus eventBus   = new Mock <Core.Infrastructure.IEventBus>().Object;

            Guid    categoryId = Guid.Empty;
            SeoData seo        = new SeoData {
                Title = "title", Description = "description"
            };

            var commands = new CategoryCommands(repository, eventBus);
            var ex       = await Assert.ThrowsAsync <ArgumentException>(() => commands.SetCategorySeoData(categoryId, seo));

            Assert.Equal(nameof(categoryId), ex.ParamName);
        }
예제 #7
0
        protected void fillCatCommColl()
        {
            PropertyDescriptorCollection baseProps = TypeDescriptor.GetProperties(this, true);

            foreach (PropertyDescriptor oProp in baseProps)
            {
                if (!oProp.DesignTimeOnly && oProp.IsBrowsable && oProp.Category != PROPERTY_CONTROL)
                {
                    CategoryCommand cc = new CategoryCommand(oProp.Category, true);
                    if (CategoryCommands.BinarySearch(cc) < 0)
                    {
                        CategoryCommands.Add(cc);
                    }
                }
            }
            CategoryCommands.Sort();
        }
예제 #8
0
        public async Task UpdateCategoryInfo_Should_Throw_ArgumentException_If_CategoryId_Is_Empty()
        {
            Repository.IRepository        repository = new Mock <Repository.IRepository>().Object;
            Core.Infrastructure.IEventBus eventBus   = new Mock <Core.Infrastructure.IEventBus>().Object;

            Guid     categoryId  = Guid.Empty;
            string   code        = "code";
            string   name        = "name";
            string   url         = "url";
            string   description = "description";
            bool     isVisible   = true;
            DateTime?visibleFrom = DateTime.Today;
            DateTime?visibleTo   = DateTime.Today.AddYears(1);

            var commands = new CategoryCommands(repository, eventBus);
            var ex       = await Assert.ThrowsAsync <ArgumentException>(() => commands.UpdateCategoryInfo(categoryId, code, name, url, description, isVisible, visibleFrom, visibleTo));

            Assert.Equal(nameof(categoryId), ex.ParamName);
        }
예제 #9
0
        public async Task DeleteCategory_Should_Mark_Category_As_Deleted()
        {
            var category = Category.Create("code", "name", "url");

            var repositoryMock = new Mock <Repository.IRepository>();

            repositoryMock.Setup(r => r.GetByKeyAsync <Category>(It.IsAny <Guid>()))
            .Returns(Task.FromResult(category));

            Repository.IRepository        repository = repositoryMock.Object;
            Core.Infrastructure.IEventBus eventBus   = new Mock <Core.Infrastructure.IEventBus>().Object;

            Guid categoryId = category.Id;

            var commands = new CategoryCommands(repository, eventBus);
            await commands.DeleteCategory(categoryId);

            Assert.True(category.Deleted);
        }
예제 #10
0
        public async Task SetCategorySeoData_Should_Set_The_Seo_Data_With_The_Specified_Values()
        {
            var category = Category.Create("code", "name", "url");

            var repositoryMock = new Mock <Repository.IRepository>();

            repositoryMock.Setup(r => r.GetByKeyAsync <Category>(It.IsAny <Guid>()))
            .Returns(Task.FromResult(category));

            Repository.IRepository        repository = repositoryMock.Object;
            Core.Infrastructure.IEventBus eventBus   = new Mock <Core.Infrastructure.IEventBus>().Object;

            Guid    categoryId = category.Id;
            SeoData seo        = new SeoData {
                Title = "title", Description = "description"
            };

            var commands = new CategoryCommands(repository, eventBus);
            await commands.SetCategorySeoData(categoryId, seo);

            Assert.Equal(seo.Title, category.Seo.Title);
            Assert.Equal(seo.Description, category.Seo.Description);
        }
예제 #11
0
 private void CategoriesChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     CategoryCommands.Clear();
     CategoryCommands.AddRange(Categories.Select(c => new CategorizeExpenseCommand(this, c)).Concat(new[] { _newExpenseCategoryCommand }));
 }