コード例 #1
0
        public async Task AddCategoryChild_Should_Throw_ArgumentException_If_ChildId_Is_Empty()
        {
            Repository.IRepository        repository = new Mock <Repository.IRepository>().Object;
            Core.Infrastructure.IEventBus eventBus   = new Mock <Core.Infrastructure.IEventBus>().Object;

            Guid categoryId = Guid.NewGuid();
            Guid childId    = Guid.Empty;

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

            Assert.Equal(nameof(childId), ex.ParamName);
        }
コード例 #2
0
        public async Task AddCategoryChild_Should_Add_The_Specified_Child_To_Category()
        {
            var category = Category.Create("mycode", "Category name", "category-url");
            var child    = Category.Create("childcode", "Child", "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.AddCategoryChild(categoryId, childId);

            Assert.True(category.Children.Contains(child));
        }