コード例 #1
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);
        }
コード例 #2
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);
        }