private void AddNewProduct() { var ex = NuPattern.VisualStudio.TraceSourceExtensions.Shield(tracer, () => { var viewModel = new AddNewProductViewModel(this.context.PatternManager, this.context.UserMessageService); var view = this.context.NewProductDialogFactory(viewModel); if (view.ShowDialog().GetValueOrDefault()) { using (new MouseCursor(System.Windows.Input.Cursors.Wait)) { var toolkitInfo = viewModel.CurrentToolkit != null ? viewModel.CurrentToolkit.ToolkitInfo : null; var product = this.context.PatternManager.CreateProduct(toolkitInfo, viewModel.ProductName); this.Select(product); } } }, Resources.SolutionBuilderViewModel_ProductInstantiationFailed); if (ex != null) { // If there was an explicit cancellation, show the author message, // otherwise show a generic error message, compatible with existing behavior. if (ex is OperationCanceledException) { this.context.UserMessageService.ShowError(ex.Message); } else { this.context.UserMessageService.ShowError(Resources.SolutionBuilderViewModel_ProductInstantiationFailed); } } }
public void Initialize() { var products = new List<IProduct>(); var toolkits = new[] { GetInstalledToolkit("Foo"), GetInstalledToolkit("Bar") }; this.patternManager = new Mock<IPatternManager>(); this.patternManager.Setup(pm => pm.InstalledToolkits).Returns(toolkits); this.patternManager.Setup(pm => pm.CreateProduct(It.IsAny<IInstalledToolkitInfo>(), It.IsAny<string>(), true)) .Callback<IInstalledToolkitInfo, string, bool>((f, n, r) => products.Add(Mocks.Of<IProduct>().First(p => p.InstanceName == n))); this.patternManager.Setup(pm => pm.Products) .Returns(products); this.target = new AddNewProductViewModel(this.patternManager.Object, new Mock<IUserMessageService>().Object); }