private IBulkAction BuildBulkAction( PropertiesUpdateBulkActionContext context, IMock <IItemService> itemServiceMock, IMock <IBulkPropertyUpdateManager> manager) { return(new PropertiesUpdateBulkAction(context, itemServiceMock.Object, manager.Object)); }
public async Task GetProperties_ItemService_InvokeGetByIds() { // arrange var context = new PropertiesUpdateBulkActionContext(); var dataSourceFactory = new Mock <IDataSourceFactory>(); var itemService = new Mock <IItemService>(); var manager = BuildManager(dataSourceFactory, itemService); var dataSource = new Mock <IDataSource>(); var productId = "fakeProductId"; var group = ItemResponseGroup.ItemInfo | ItemResponseGroup.ItemProperties; var productIds = new[] { productId }; var properties = new List <Property>(); var product = Mock.Of <CatalogProduct>( t => t.Id == productId && t.Properties == properties, MockBehavior.Loose); var products = new List <CatalogProduct> { product }; dataSourceFactory.Setup(t => t.Create(context)).Returns(dataSource.Object); dataSource.SetupSequence(t => t.FetchAsync()).ReturnsAsync(true).ReturnsAsync(false); dataSource.Setup(t => t.Items).Returns(products); itemService.Setup(t => t.GetByIdsAsync(productIds, group.ToString(), null)).ReturnsAsync(products.ToArray()); // act await manager.GetPropertiesAsync(context); // assert itemService.Verify(t => t.GetByIdsAsync(productIds, group.ToString(), null)); }
private static IBulkAction BuildBulkAction( PropertiesUpdateBulkActionContext context, IMock <IBulkPropertyUpdateManager> manager, Mock <ILazyServiceProvider> serviceProvider) { serviceProvider.Setup(t => t.Resolve <IBulkPropertyUpdateManager>()).Returns(manager.Object); return(new PropertiesUpdateBulkAction(serviceProvider.Object, context)); }
private IBulkAction BuildBulkAction(PropertiesUpdateBulkActionContext context) { var manager = new Mock <IBulkPropertyUpdateManager>(); manager.Setup(t => t.GetPropertiesAsync(It.IsAny <PropertiesUpdateBulkActionContext>())) .ReturnsAsync(new List <Property>().ToArray()); var bulkAction = BuildBulkAction(context, manager); return(bulkAction); }
private IBulkAction BuildBulkAction( PropertiesUpdateBulkActionContext context, IMock <IItemService> itemServiceMock) { var manager = new Mock <IBulkPropertyUpdateManager>(); manager.Setup(t => t.GetPropertiesAsync(It.IsAny <PropertiesUpdateBulkActionContext>())) .ReturnsAsync(new List <Property>().ToArray()); return(BuildBulkAction(context, itemServiceMock, manager)); }
public void Create_Result_PropertiesUpdateBulkAction() { // arrange var factory = BuildFactory(); var context = new PropertiesUpdateBulkActionContext(); // act var result = factory.Create(context); // assert result.Should().BeOfType <PropertiesUpdateBulkAction>(); }
private static IBulkAction BuildBulkAction( PropertiesUpdateBulkActionContext context, Mock <ILazyServiceProvider> serviceProvider) { var manager = new Mock <IBulkPropertyUpdateManager>(); manager.Setup(t => t.GetProperties(It.IsAny <PropertiesUpdateBulkActionContext>())) .Returns(new List <Property>().ToArray()); serviceProvider.Setup(t => t.Resolve <IBulkPropertyUpdateManager>()).Returns(manager.Object); return(new PropertiesUpdateBulkAction(serviceProvider.Object, context)); }
public void Context_Result_NotBeNull() { // arrange var context = new PropertiesUpdateBulkActionContext(); var bulkAction = BuildBulkAction(context); // act var result = bulkAction.Context; // assert result.Should().NotBeNull(); }
public async Task Validate_Result_True() { // arrange var context = new PropertiesUpdateBulkActionContext(); var bulkAction = BuildBulkAction(context); // act var result = await bulkAction.ValidateAsync(); // assert result.Succeeded.Should().Be(true); }
public async Task GetActionData_Result_NotBeNull() { // arrange var context = new PropertiesUpdateBulkActionContext(); var bulkAction = BuildBulkAction(context); // act var result = await bulkAction.GetActionDataAsync(); // assert result.Should().NotBeNull(); }
public void GetActionData_ShouldResolve_IBulkPropertyUpdateManager() { // arrange var context = new PropertiesUpdateBulkActionContext(); var serviceProvider = new Mock <ILazyServiceProvider>(); var bulkAction = BuildBulkAction(context, serviceProvider); // act bulkAction.GetActionData(); // assert serviceProvider.Verify(t => t.Resolve <IBulkPropertyUpdateManager>()); }
public async Task GetActionData_BulkPropertyUpdateManager_InvokeGetProperties() { // arrange var context = new PropertiesUpdateBulkActionContext(); var manager = new Mock <IBulkPropertyUpdateManager>(); var bulkAction = BuildBulkAction(context, manager); // act await bulkAction.GetActionDataAsync(); // assert manager.Verify(t => t.GetPropertiesAsync(context)); }
public async Task Execute_BulkPropertyUpdateManager_InvokeUpdateProperties() { // arrange var context = new PropertiesUpdateBulkActionContext(); var manager = new Mock <IBulkPropertyUpdateManager>(); context.Properties = new Property[] { }; var bulkAction = BuildBulkAction(context, manager); // act await bulkAction.ExecuteAsync(Enumerable.Empty <IEntity>()); // assert manager.Verify(t => t.UpdatePropertiesAsync(It.IsAny <CatalogProduct[]>(), context.Properties)); }
public async Task GetProperties_Should_HaveCountGreaterThan(int count) { // arrange var context = new PropertiesUpdateBulkActionContext(); var dataSource = new Mock <IDataSource>(); var dataSourceFactory = new Mock <IDataSourceFactory>(); var manager = BuildManager(dataSourceFactory); dataSourceFactory.Setup(t => t.Create(context)).Returns(dataSource.Object); // act var result = await manager.GetPropertiesAsync(context); // assert result.Should().HaveCountGreaterThan(count); }
public async Task GetProperties_DataSource_InvokeFetch() { // arrange var context = new PropertiesUpdateBulkActionContext(); var dataSource = new Mock <IDataSource>(); var dataSourceFactory = new Mock <IDataSourceFactory>(); var manager = BuildManager(dataSourceFactory); dataSourceFactory.Setup(t => t.Create(context)).Returns(dataSource.Object); // act await manager.GetPropertiesAsync(context); // assert dataSource.Verify(t => t.FetchAsync()); }
public void Create_Result_ProductDataSource() { // arrange var dataSourceFactory = BuildDataSourceFactory(); var dataQuery = new Mock <DataQuery> { DefaultValueProvider = DefaultValueProvider.Mock }; var context = new PropertiesUpdateBulkActionContext { DataQuery = dataQuery.Object }; // act var result = dataSourceFactory.Create(context); // assert result.Should().BeOfType <ProductDataSource>(); }
public void Execute_BulkPropertyUpdateManager_InvokeUpdateProperties() { // arrange var context = new PropertiesUpdateBulkActionContext(); var serviceProvider = new Mock <ILazyServiceProvider>(); var manager = new Mock <IBulkPropertyUpdateManager>(); serviceProvider.Setup(t => t.Resolve <IItemService>()).Returns(Mock.Of <IItemService>()); context.Properties = new CatalogModule.Web.Model.Property[] { }; var bulkAction = BuildBulkAction(context, manager, serviceProvider); // act bulkAction.Execute(Enumerable.Empty <IEntity>()); // assert manager.Verify(t => t.UpdateProperties(It.IsAny <CatalogProduct[]>(), context.Properties)); }
public void Execute_UnknownTypeOfListEntry_ArgumentException() { // arrange var context = new PropertiesUpdateBulkActionContext(); var bulkAction = BuildBulkAction(context); // act var action = new Action( () => { bulkAction.Execute(new List <IEntity> { new ListEntry("someUnknownType", null) }); }); // assert action.Should().Throw <ArgumentException>(); }
public void Execute_ShouldResolve_IBulkPropertyUpdateManager() { // arrange var context = new PropertiesUpdateBulkActionContext(); var bulkAction = BuildBulkAction(context); // act try { bulkAction.ExecuteAsync(Enumerable.Empty <IEntity>()); } catch { // idle } // assert //TODO }
public void Execute_ShouldResolve_IBulkPropertyUpdateManager() { // arrange var context = new PropertiesUpdateBulkActionContext(); var serviceProvider = new Mock <ILazyServiceProvider>(); var bulkAction = BuildBulkAction(context, serviceProvider); // act try { bulkAction.Execute(Enumerable.Empty <IEntity>()); } catch { // idle } // assert serviceProvider.Verify(t => t.Resolve <IBulkPropertyUpdateManager>()); }
public async Task Execute_ItemService_InvokeGetByIds() { // arrange var context = new PropertiesUpdateBulkActionContext(); var itemService = new Mock <IItemService> { DefaultValueProvider = DefaultValueProvider.Mock }; context.Properties = new Property[] { }; var bulkAction = BuildBulkAction(context, itemService); // act await bulkAction.ExecuteAsync(Enumerable.Empty <IEntity>()); // assert itemService.Verify( t => t.GetByIdsAsync( It.IsAny <string[]>(), (ItemResponseGroup.ItemInfo | ItemResponseGroup.ItemProperties).ToString(), null)); }
public void Execute_UnknownTypeOfListEntry_ArgumentException() { // arrange var context = new PropertiesUpdateBulkActionContext(); var bulkAction = BuildBulkAction(context); // act var action = new Action(() => { bulkAction .ExecuteAsync(new List <IEntity> { new ListEntryBase { Type = "somType" } }) .GetAwaiter() .GetResult(); }); // assert action.Should().Throw <ArgumentException>(); }
public void Execute_ItemService_InvokeGetByIds() { // arrange var context = new PropertiesUpdateBulkActionContext(); var serviceProvider = new Mock <ILazyServiceProvider>(); var itemService = new Mock <IItemService> { DefaultValueProvider = DefaultValueProvider.Mock }; serviceProvider.Setup(t => t.Resolve <IItemService>()).Returns(itemService.Object); context.Properties = new CatalogModule.Web.Model.Property[] { }; var bulkAction = BuildBulkAction(context, serviceProvider); // act bulkAction.Execute(Enumerable.Empty <IEntity>()); // assert itemService.Verify( t => t.GetByIds( It.IsAny <string[]>(), ItemResponseGroup.ItemInfo | ItemResponseGroup.ItemProperties, null)); }
/// <summary> /// Initializes a new instance of the <see cref="PropertiesUpdateBulkAction"/> class. /// </summary> /// <param name="lazyServiceProvider"> /// The lazy service provider. /// </param> /// <param name="context"> /// The context. /// </param> public PropertiesUpdateBulkAction(PropertiesUpdateBulkActionContext context, IItemService itemService, IBulkPropertyUpdateManager bulkPropertyUpdateManager) { _context = context ?? throw new ArgumentNullException(nameof(context)); _itemService = itemService; _bulkPropertyUpdateManager = bulkPropertyUpdateManager; }
private IBulkAction BuildBulkAction( PropertiesUpdateBulkActionContext context, IMock <IBulkPropertyUpdateManager> manager) { return(BuildBulkAction(context, _itemServiceMock, manager)); }