public void Execute_Should_ThrowException()
        {
            // arrange
            var categoryId = "fakeId";
            var entries    = new List <ListEntry> {
                new ListEntry {
                    Id = categoryId
                }
            };
            var context = new CategoryChangeBulkActionContext {
                CategoryId = categoryId
            };
            var serviceProvider = new Mock <ILazyServiceProvider>();
            var bulkAction      = new CategoryChangeBulkAction(serviceProvider.Object, context);

            // act
            var action = new Action(
                () =>
            {
                bulkAction.Execute(entries);
            });

            // assert
            action.Should().Throw <Exception>();
        }
        public void Execute_Should_InvokeMethods(Mock <ILazyServiceProvider> serviceProvider, Action assertAction)
        {
            // arrange
            var context    = new CategoryChangeBulkActionContext();
            var bulkAction = new CategoryChangeBulkAction(serviceProvider.Object, context);

            // act
            bulkAction.Execute(Enumerable.Empty <IEntity>());

            // assert
            serviceProvider.VerifyAll();
            assertAction();
        }
        public IBulkAction Create(BulkActionContext context)
        {
            IBulkAction result = null;

            switch (context)
            {
            case CategoryChangeBulkActionContext changeCategoryActionContext:
                result = new CategoryChangeBulkAction(_lazyLazyServiceProvider, changeCategoryActionContext);
                break;

            case PropertiesUpdateBulkActionContext updatePropertiesActionContext:
                result = new PropertiesUpdateBulkAction(_lazyLazyServiceProvider, updatePropertiesActionContext);
                break;
            }

            return(result ?? throw new ArgumentException($"Unsupported action type: {context.GetType().Name}"));
        }
        public IBulkAction Create(BulkActionContext context)
        {
            IBulkAction result = null;

            switch (context)
            {
            case CategoryChangeBulkActionContext changeCategoryActionContext:
                result = new CategoryChangeBulkAction(changeCategoryActionContext, _catalogService, _categoryListEntryMover, _productListEntryMover);
                break;

            case PropertiesUpdateBulkActionContext updatePropertiesActionContext:
                result = new PropertiesUpdateBulkAction(updatePropertiesActionContext, _itemService, _bulkPropertyUpdateManager);
                break;
            }

            return(result ?? throw new ArgumentException($"Unsupported action type: {context.GetType().Name}"));
        }
        public void Validate_Result_True()
        {
            // arrange
            var context = new CategoryChangeBulkActionContext {
                CatalogId = "catalog"
            };
            var catalogService  = new Mock <ICatalogService>();
            var serviceProvider = new Mock <ILazyServiceProvider>();

            catalogService.Setup(t => t.GetById("catalog"))
            .Returns(Mock.Of <Catalog>(catalog => catalog.IsVirtual == false));
            serviceProvider.Setup(t => t.Resolve <ICatalogService>()).Returns(catalogService.Object);

            var bulkAction = new CategoryChangeBulkAction(serviceProvider.Object, context);

            // act
            var result = bulkAction.Validate();

            // assert
            result.Succeeded.Should().Be(true);
        }
        public void Validate_Result_HaveErrorCount(int errorCount)
        {
            // arrange
            var context = new CategoryChangeBulkActionContext {
                CatalogId = "catalog"
            };
            var catalogService  = new Mock <ICatalogService>();
            var serviceProvider = new Mock <ILazyServiceProvider>();

            catalogService.Setup(t => t.GetById("catalog"))
            .Returns(Mock.Of <Catalog>(catalog => catalog.IsVirtual == true));
            serviceProvider.Setup(t => t.Resolve <ICatalogService>()).Returns(catalogService.Object);

            var bulkAction = new CategoryChangeBulkAction(serviceProvider.Object, context);

            // act
            var result = bulkAction.Validate();

            // assert
            result.Errors.Should().HaveCount(errorCount, "Because we can't move in virtual catalog'");
        }