public void InitializeContext() { var store = new DslTestStore <PatternModelDomainModel>(); PatternModelSchema patternModel = null; store.TransactionManager.DoWithinTransaction(() => { patternModel = store.ElementFactory.CreateElement <PatternModelSchema>(); }); var serviceProvider = Mock.Get(store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of <IPatternManager>(p => p.InstalledToolkits == new List <IInstalledToolkitInfo>())); var uriService = Mock.Of <IUriReferenceService>( u => u.ResolveUri <IInstanceBase>(It.IsAny <Uri>()) == Mock.Of <IProduct>(p => p.ToolkitInfo.Identifier == "AuthoredToolkit")); var patternSchema = patternModel.Create <PatternSchema>(); patternSchema.Name = "FooPattern"; patternSchema.PatternLink = "patternmanager://foo"; patternSchema.UriService = uriService; this.view = patternSchema.Create <ViewSchema>(); this.view.Name = "View1"; store.TransactionManager.DoWithinTransaction(() => { this.extensionPoint = store.ElementFactory.CreateElement <ExtensionPointSchema>("ExtensionPoint1"); this.view.ExtensionPoints.Add(this.extensionPoint); }); }
/// <summary> /// Returns a tailored pattern model. /// </summary> internal static PatternModelSchema TailorPatternModel(PatternModelSchema basePatternModel, Version baseVersion, string toolkitId = "ToolkitId") { var store = new DslTestStore <PatternModelDomainModel>(); var serviceProvider = Mock.Get(store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of <IPatternManager>(p => p.InstalledToolkits == new List <IInstalledToolkitInfo>())); PatternModelSchema tailoredPatternModel = null; store.TransactionManager.DoWithinTransaction(() => { tailoredPatternModel = store.ElementFactory.CreateElement <PatternModelSchema>(); }); // Set baseId on the pattern line tailoredPatternModel.WithTransaction(pl => pl.BaseId = "Base"); tailoredPatternModel.ClonerFactory = (b, v, t) => Mock.Of <PatternModelCloner>( c => c.SourcePatternModel == b && c.SourceVersion == v && c.TargetPatternModel == t); // Clone the pattern line tailoredPatternModel.Tailor(basePatternModel, baseVersion); return(tailoredPatternModel); }
public void WhenNestedTransactionNotCommited_ThenNestedChangesNotCommited() { var store = new DslTestStore <ProductStateStoreDomainModel>(); IProductState productState = null; IProduct product = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement <ProductState>(); product = productState.CreateProduct(); }); var committed = false; store.Store.EventManagerDirectory.TransactionCommitted.Add(new EventHandler <TransactionCommitEventArgs>( (sender, args) => committed = true)); var parentTx = store.TransactionManager.BeginTransaction(); product.DefinitionName = "foo"; var nestedTx = store.TransactionManager.BeginTransaction(); product.InstanceName = "bar"; nestedTx.Dispose(); Assert.NotEqual("bar", product.InstanceName); parentTx.Commit(); Assert.True(committed); Assert.Equal("foo", product.DefinitionName); }
/// <summary> /// Returns a tailored pattern model. /// </summary> internal static PatternModelSchema TailorPatternModel(PatternModelSchema basePatternModel, Version baseVersion, string toolkitId = "ToolkitId") { var store = new DslTestStore<PatternModelDomainModel>(); var serviceProvider = Mock.Get(store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of<IPatternManager>(p => p.InstalledToolkits == new List<IInstalledToolkitInfo>())); PatternModelSchema tailoredPatternModel = null; store.TransactionManager.DoWithinTransaction(() => { tailoredPatternModel = store.ElementFactory.CreateElement<PatternModelSchema>(); }); // Set baseId on the pattern line tailoredPatternModel.WithTransaction(pl => pl.BaseId = "Base"); tailoredPatternModel.ClonerFactory = (b, v, t) => Mock.Of<PatternModelCloner>( c => c.SourcePatternModel == b && c.SourceVersion == v && c.TargetPatternModel == t); // Clone the pattern line tailoredPatternModel.Tailor(basePatternModel, baseVersion); return tailoredPatternModel; }
public virtual void InitializeContext() { var uriService = Mock.Of <IUriReferenceService>( u => u.ResolveUri <IInstanceBase>(It.IsAny <Uri>()) == Mock.Of <IProduct>(p => p.ToolkitInfo.Identifier == "ToolkitId")); var store = new DslTestStore <PatternModelDomainModel>(); var serviceProvider = Mock.Get(store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of <IPatternManager>(p => p.InstalledToolkits == new List <IInstalledToolkitInfo>())); store.TransactionManager.DoWithinTransaction(() => { this.PatternModel = store.ElementFactory.CreateElement <PatternModelSchema>(); var pattern = this.PatternModel.Create <PatternSchema>(); pattern.Name = "WebService"; pattern.PatternLink = "patternmanager://foo"; pattern.UriService = uriService; this.Property = pattern.Create <PropertySchema>(); this.Property.Name = "Namespace"; }); }
public void InitializeContext() { var sourceStore = new DslTestStore <PatternModelDomainModel>(); sourceStore.TransactionManager.DoWithinTransaction(() => { this.sourcePatternModel = sourceStore.ElementFactory.CreateElement <PatternModelSchema>(); }); var serviceProvider = Mock.Get(sourceStore.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of <IPatternManager>(p => p.InstalledToolkits == new List <IInstalledToolkitInfo>())); var uriService = Mock.Of <IUriReferenceService>( u => u.ResolveUri <IInstanceBase>(It.IsAny <Uri>()) == Mock.Of <IProduct>(p => p.ToolkitInfo.Identifier == "MyToolkit")); var patternSchema = this.sourcePatternModel.Create <PatternSchema>(); patternSchema.Name = "Pattern1"; patternSchema.PatternLink = "patternmanager://foo"; patternSchema.UriService = uriService; var targetStore = new DslTestStore <PatternModelDomainModel>(); var serviceProvider1 = Mock.Get(targetStore.ServiceProvider); serviceProvider1.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of <IPatternManager>(p => p.InstalledToolkits == new List <IInstalledToolkitInfo>())); targetStore.TransactionManager.DoWithinTransaction(() => this.targetPatternModel = targetStore.ElementFactory.CreateElement <PatternModelSchema>()); }
public void InitializeContext() { var sourceStore = new DslTestStore<PatternModelDomainModel>(); sourceStore.TransactionManager.DoWithinTransaction(() => { this.sourcePatternModel = sourceStore.ElementFactory.CreateElement<PatternModelSchema>(); }); var serviceProvider = Mock.Get(sourceStore.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of<IPatternManager>(p => p.InstalledToolkits == new List<IInstalledToolkitInfo>())); var uriService = Mock.Of<IUriReferenceService>( u => u.ResolveUri<IInstanceBase>(It.IsAny<Uri>()) == Mock.Of<IProduct>(p => p.ToolkitInfo.Identifier == "MyToolkit")); var patternSchema = this.sourcePatternModel.Create<PatternSchema>(); patternSchema.Name = "Pattern1"; patternSchema.PatternLink = "patternmanager://foo"; patternSchema.UriService = uriService; patternSchema.Create<ViewSchema>(); var targetStore = new DslTestStore<PatternModelDomainModel>(); var serviceProvider1 = Mock.Get(targetStore.ServiceProvider); serviceProvider1.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of<IPatternManager>(p => p.InstalledToolkits == new List<IInstalledToolkitInfo>())); targetStore.TransactionManager.DoWithinTransaction(() => this.targetPatternModel = targetStore.ElementFactory.CreateElement<PatternModelSchema>()); }
public void InitializeContext() { var store = new DslTestStore<PatternModelDomainModel>().Store; store.TransactionManager.DoWithinTransaction( () => this.product = (PatternSchema)store.ElementFactory.CreateElement<PatternModelSchema>().CreatePatternSchema()); }
public void InitializeContext() { var store = new DslTestStore <PatternModelDomainModel>(); store.TransactionManager.DoWithinTransaction( () => this.product = store.ElementFactory.CreateElement <PatternModelSchema>().Create <PatternSchema>()); }
public virtual void Initialize() { this.DslStore = new DslTestStore <ProductStateStoreDomainModel>(); using (var tx = this.DslStore.TransactionManager.BeginTransaction()) { this.ProductStore = this.DslStore.ElementFactory.CreateElement <ProductState>(); tx.Commit(); } }
public void InitializeContext() { this.store = new DslTestStore <ProductStateStoreDomainModel>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.element = this.store.ElementFactory.CreateElement <Element>(); tx.Commit(); } }
public virtual void InitializeContext() { var store = new DslTestStore<PatternModelDomainModel>(); store.TransactionManager.DoWithinTransaction(() => { this.PatternModel = store.ElementFactory.CreateElement<PatternModelSchema>(); var pattern = this.PatternModel.Create<PatternSchema>(); this.Element = pattern.Create<ElementSchema>(); }); }
public void Initialize() { this.store = new DslTestStore<ProductStateStoreDomainModel>(); this.toolkit = Mocks.Of<IInstalledToolkitInfo>().First( f => f.Id == "foo" && f.Schema.Pattern.Id == Guid.NewGuid()); var serviceProvider = Mock.Get(this.store.ServiceProvider); serviceProvider.Setup(sp => sp.GetService(typeof(IPatternManager))) .Returns(Mocks.Of<IPatternManager>().First(x => x.InstalledToolkits == new[] { this.toolkit })); }
public void InitializeContext() { this.provider = new TestReferenceWithoutItsTypeConverter(); this.store = new DslTestStore <ProductStateStoreDomainModel>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.element = this.store.ElementFactory.CreateElement <Element>(); tx.Commit(); } }
public virtual void InitializeContext() { var store = new DslTestStore <PatternModelDomainModel>(); store.TransactionManager.DoWithinTransaction(() => { this.PatternModel = store.ElementFactory.CreateElement <PatternModelSchema>(); var pattern = this.PatternModel.Create <PatternSchema>(); this.Element = pattern.Create <ElementSchema>(); }); }
public void Initialize() { this.store = new DslTestStore <ProductStateStoreDomainModel>(); this.toolkit = Mocks.Of <IInstalledToolkitInfo>().First( f => f.Id == "foo" && f.Schema.Pattern.Id == Guid.NewGuid()); var serviceProvider = Mock.Get(this.store.ServiceProvider); serviceProvider.Setup(sp => sp.GetService(typeof(IPatternManager))) .Returns(Mocks.Of <IPatternManager>().First(x => x.InstalledToolkits == new[] { this.toolkit })); }
public void Initialize() { this.solutionEvents = new Mock <ISolutionEvents>(); this.itemEvents = new Mock <IItemEvents>(); this.messageService = new Mock <IUserMessageService>(); if (Directory.Exists(solutionItemsDir)) { Directory.Delete(solutionItemsDir, true); } Directory.CreateDirectory(solutionItemsDir); this.solution = new Solution { PhysicalPath = Path.GetTempFileName(), Items = { new SolutionFolder { PhysicalPath = Path.GetTempPath() + "\\Solution Items", Name = "Solution Items" } } }; this.store = new DslTestStore <ProductStateStoreDomainModel>(); this.toolkitInfo = new Mock <IInstalledToolkitInfo> { DefaultValue = DefaultValue.Mock }; this.toolkitInfo.Setup(f => f.Id).Returns("foo"); this.toolkitInfo.Setup(f => f.Version).Returns(new Version("1.0.0.0")); this.toolkitInfo.Setup(f => f.Schema.Pattern.ExtensionId).Returns("foo"); var installedFactories = new[] { this.toolkitInfo.Object }; var componentModel = new Mock <IComponentModel>(); componentModel.Setup(cm => cm.GetService <IEnumerable <IInstalledToolkitInfo> >()).Returns(installedFactories); componentModel.Setup(cm => cm.GetService <IToolkitRepository>()).Returns(Mock.Of <IToolkitRepository>()); var serviceProvider = Mock.Get(this.store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(SComponentModel))).Returns(componentModel.Object); serviceProvider.Setup(s => s.GetService(typeof(ISolution))).Returns(this.solution); this.shellEvents = new Mock <IShellEvents>(); this.shellEvents.Setup(x => x.IsInitialized).Returns(true); this.manager = new TestPatternManager(this.store.ServiceProvider, this.solution, this.shellEvents.Object, this.solutionEvents.Object, this.itemEvents.Object, installedFactories, this.messageService.Object); }
public void InitializeContext() { var store = new DslTestStore <PatternModelDomainModel>(); store.TransactionManager.DoWithinTransaction( () => this.sourcePatternModel = store.ElementFactory.CreateElement <PatternModelSchema>()); var serviceProvider = Mock.Get(store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of <IPatternManager>(p => p.InstalledToolkits == new List <IInstalledToolkitInfo>())); }
public void Initialize() { this.store = new DslTestStore <ProductStateStoreDomainModel>(); this.extension = new Mock <IAutomationExtension>(); this.extension.As <IDisposable>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.element = this.store.ElementFactory.CreateElement <Product>(); tx.Commit(); } this.element.AutomationExtensions.Add(this.extension.Object); }
public void WhenProductInstantiated_ThenRetrievesProductInstance() { var store = new DslTestStore <ProductStateStoreDomainModel>(); IProductState productState = null; IProduct product = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement <ProductState>(); product = productState.CreateProduct(); }); Assert.Equal(1, productState.FindAll <Product>().Count()); Assert.Equal(product.Id, productState.FindAll <Product>().ElementAt(0).Id); }
public void Initialize() { this.store = new DslTestStore<ProductStateStoreDomainModel>(); this.extension = new Mock<IAutomationExtension>(); this.extension.As<IDisposable>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.element = this.store.ElementFactory.CreateElement<Product>(); tx.Commit(); } this.element.AutomationExtensions.Add(this.extension.Object); }
public void Initialize() { this.store = new DslTestStore<ProductStateStoreDomainModel>(); using (var tx = store.TransactionManager.BeginTransaction()) { this.property = store.ElementFactory.CreateElement<Property>(); this.property.Info = Mocks.Of<IPropertyInfo>().First(i => i.Name == PropertyName && i.IsVisible == true && i.IsReadOnly == false); this.element = store.ElementFactory.CreateElement<Element>(); this.element.Properties.Add(this.property); tx.Commit(); } this.descriptor = new ProductElementTypeDescriptor( TypeDescriptor.GetProvider(this.element).GetTypeDescriptor(this.element), this.element); }
public void Initialize() { this.store = new DslTestStore <ProductStateStoreDomainModel>(); using (var tx = store.TransactionManager.BeginTransaction()) { this.property = store.ElementFactory.CreateElement <Property>(); this.property.Info = Mocks.Of <IPropertyInfo>().First(i => i.Name == PropertyName && i.IsVisible == true && i.IsReadOnly == false); this.element = store.ElementFactory.CreateElement <Element>(); this.element.Properties.Add(this.property); tx.Commit(); } this.descriptor = new ProductElementTypeDescriptor( TypeDescriptor.GetProvider(this.element).GetTypeDescriptor(this.element), this.element); }
private static Product CreateProduct() { ProductState productStore = null; DslTestStore <ProductStateStoreDomainModel> store = new DslTestStore <ProductStateStoreDomainModel>(); store.TransactionManager.DoWithinTransaction(() => { productStore = store.ElementFactory.CreateElement <ProductState>(); }); var product = (Product)productStore.CreateProduct(); product.InstanceName = "AProduct1"; product.Info = Mock.Of <IPatternInfo>(i => i.Name == "AProduct" && i.CodeIdentifier == "AProduct"); return(product); }
public void Initialize() { this.store = new DslTestStore <ProductStateStoreDomainModel>(); Mock.Get(this.store.ServiceProvider) .Setup(x => x.GetService(typeof(SComponentModel))) .Returns(new Mock <IComponentModel> { DefaultValue = DefaultValue.Mock } .Object); Mock.Get(this.store.ServiceProvider) .Setup(x => x.GetService(typeof(IBindingCompositionService))) .Returns(new Mock <IBindingCompositionService> { DefaultValue = DefaultValue.Mock } .Object); this.automationExtension = new Mock <IAutomationExtension>(); this.automationExtension.As <IDisposable>(); this.automationExtension.As <ISupportInitialize>(); this.extensionSettings = new Mock <IAutomationSettings>(); this.extensionSettings .Setup(x => x.CreateAutomation(It.IsAny <IProductElement>())) .Returns(this.automationExtension.Object); var settingsContainer = new Mock <IPatternElementInfo>(); var settingsInfo = new Mock <IAutomationSettingsInfo>(); settingsContainer .Setup(x => x.AutomationSettings) .Returns(new[] { settingsInfo.Object }); settingsInfo .Setup(info => info.As <IAutomationSettings>()) .Returns(this.extensionSettings.Object); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.element = this.store.ElementFactory.CreateElement <Product>(); this.element.Info = settingsContainer.Object; tx.Commit(); } }
public void Initialize() { this.store = new DslTestStore<ProductStateStoreDomainModel>(); Mock.Get(this.store.ServiceProvider) .Setup(x => x.GetService(typeof(SComponentModel))) .Returns(new Mock<IComponentModel> { DefaultValue = DefaultValue.Mock } .Object); Mock.Get(this.store.ServiceProvider) .Setup(x => x.GetService(typeof(IBindingCompositionService))) .Returns(new Mock<IBindingCompositionService> { DefaultValue = DefaultValue.Mock } .Object); this.automationExtension = new Mock<IAutomationExtension>(); this.automationExtension.As<IDisposable>(); this.automationExtension.As<ISupportInitialize>(); this.extensionSettings = new Mock<IAutomationSettings>(); this.extensionSettings .Setup(x => x.CreateAutomation(It.IsAny<IProductElement>())) .Returns(this.automationExtension.Object); var settingsContainer = new Mock<IPatternElementInfo>(); var settingsInfo = new Mock<IAutomationSettingsInfo>(); settingsContainer .Setup(x => x.AutomationSettings) .Returns(new[] { settingsInfo.Object }); settingsInfo .Setup(info => info.As<IAutomationSettings>()) .Returns(this.extensionSettings.Object); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.element = this.store.ElementFactory.CreateElement<Product>(); this.element.Info = settingsContainer.Object; tx.Commit(); } }
public void Initialize() { this.store = new DslTestStore <ProductStateStoreDomainModel>(); var productInfo = new Mock <IPatternInfo>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.product = this.store.ElementFactory.CreateElement <Product>(); this.product.Info = productInfo.Object; tx.Commit(); } this.viewInfo = new Mock <IViewInfo>(); this.viewInfo.Setup(v => v.Id).Returns(Guid.NewGuid()); this.viewInfo.Setup(v => v.Pattern).Returns(this.product.Info); productInfo.Setup(p => p.Views).Returns(new[] { this.viewInfo.Object }); }
public void Initialize() { this.store = new DslTestStore<ProductStateStoreDomainModel>(); var viewInfo = new Mock<IViewInfo>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.view = this.store.ElementFactory.CreateElement<View>(); this.view.Info = viewInfo.Object; tx.Commit(); } this.collectionInfo = new Mock<ICollectionInfo>(); this.collectionInfo.Setup(c => c.Id).Returns(Guid.NewGuid()); this.collectionInfo.Setup(c => c.Parent).Returns(this.view.Info); viewInfo.Setup(p => p.Elements).Returns(new[] { this.collectionInfo.Object }); }
public void Initialize() { this.store = new DslTestStore <ProductStateStoreDomainModel>(); var viewInfo = new Mock <IViewInfo>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.view = this.store.ElementFactory.CreateElement <View>(); this.view.Info = viewInfo.Object; tx.Commit(); } this.elementInfo = new Mock <IElementInfo>(); this.elementInfo.Setup(e => e.Id).Returns(Guid.NewGuid()); this.elementInfo.Setup(e => e.Parent).Returns(this.view.Info); viewInfo.Setup(p => p.Elements).Returns(new[] { this.elementInfo.Object }); }
public void Initialize() { this.store = new DslTestStore <ProductStateStoreDomainModel>(); var elementInfo = new Mock <IElementInfo>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.element = this.store.ElementFactory.CreateElement <Element>(); this.element.Info = elementInfo.Object; tx.Commit(); } this.propertyInfo = new Mock <IPropertyInfo>(); this.propertyInfo.Setup(v => v.Id).Returns(Guid.NewGuid()); this.propertyInfo.Setup(v => v.Parent).Returns(this.element.Info); elementInfo.Setup(e => e.Properties).Returns(new[] { this.propertyInfo.Object }); }
public void Initialize() { this.store = new DslTestStore<ProductStateStoreDomainModel>(); var elementInfo = new Mock<IElementInfo>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.element = this.store.ElementFactory.CreateElement<Element>(); this.element.Info = elementInfo.Object; tx.Commit(); } this.propertyInfo = new Mock<IPropertyInfo>(); this.propertyInfo.Setup(v => v.Id).Returns(Guid.NewGuid()); this.propertyInfo.Setup(v => v.Parent).Returns(this.element.Info); elementInfo.Setup(e => e.Properties).Returns(new[] { this.propertyInfo.Object }); }
public void WhenChangingProperty_ThenNotifiesSubscriber() { var store = new DslTestStore <ProductStateStoreDomainModel>(); IProduct product = null; store.TransactionManager.DoWithinTransaction(() => { var productStore = store.ElementFactory.CreateElement <ProductState>(); product = productStore.Create <Product>(); }); var notified = false; product.SubscribeChanged(x => x.InstanceName, p => notified = true); product.InstanceName = "Hello"; Assert.IsTrue(notified); }
public void WhenChangingProperty_ThenNotifiesSubscriber() { var store = new DslTestStore<ProductStateStoreDomainModel>(); IProduct product = null; store.TransactionManager.DoWithinTransaction(() => { var productStore = store.ElementFactory.CreateElement<ProductState>(); product = productStore.Create<Product>(); }); var notified = false; product.SubscribeChanged(x => x.InstanceName, p => notified = true); product.InstanceName = "Hello"; Assert.IsTrue(notified); }
public void Initialize() { this.template = new Mock <ITemplate>(); this.serviceProvider = new Mock <IServiceProvider>(); this.modelBus = new Mock <IModelBus>(); this.serviceProvider.Setup(x => x.GetService(typeof(SModelBus))).Returns(this.modelBus.Object); this.solution = CreateSolution(); this.store = new DslTestStore <ProductStateStoreDomainModel>(); this.store.TransactionManager.DoWithinTransaction(() => { var productStore = this.store.ElementFactory.CreateElement <ProductState>(); this.product = productStore.CreateProduct(prod => prod.InstanceName = "Foo"); var property = (Property)this.product.CreateProperty(); property.RawValue = "GuidanceValue"; property.Info = Mocks.Of <IPropertyInfo>().First(i => i.Name == "GuidanceName" && i.Type == "System.String" && i.IsVisible == true && i.IsReadOnly == false); }); this.uriService = new Mock <IUriReferenceService>(); this.uriService.Setup(x => x.ResolveUri <ITemplate>(It.IsAny <Uri>())).Returns(this.template.Object); this.command = new GenerateModelingCodeCommand { TargetFileName = "Foo", TemplateUri = new Uri("t4://foo.tt"), UriService = this.uriService.Object, ModelElement = (ModelElement)this.product, ModelFile = "C:\\Temp\\foo" + NuPattern.Runtime.StoreConstants.RuntimeStoreExtension, ServiceProvider = this.serviceProvider.Object, Solution = this.solution, }; // Set modelbus adapter var adapter = new Mock <ModelBusAdapterManager>(); this.modelBus.Setup(x => x.FindAdapterManagers(It.IsAny <object[]>())).Returns(new[] { adapter.Object }); adapter.Setup(x => x.GetSupportedLogicalAdapterIds()).Returns(new[] { "FooAdapter" }); adapter.Setup(x => x.GetExposedElementTypes("FooAdapter")).Returns(new[] { new SupportedType(typeof(IProduct)) }); }
public void WhenTransactionCommited_ThenRaisesTransactionCommitedEvent() { var store = new DslTestStore <ProductStateStoreDomainModel>(); IProductState productState = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement <ProductState>(); }); var fired = false; productState.TransactionCommited += (sender, args) => fired = true; store.TransactionManager.DoWithinTransaction(() => { productState.CreateProduct(); }); Assert.True(fired); }
public void Initialize() { this.template = new Mock<ITemplate>(); this.serviceProvider = new Mock<IServiceProvider>(); this.modelBus = new Mock<IModelBus>(); this.serviceProvider.Setup(x => x.GetService(typeof(SModelBus))).Returns(this.modelBus.Object); this.solution = CreateSolution(); this.store = new DslTestStore<ProductStateStoreDomainModel>(); this.store.TransactionManager.DoWithinTransaction(() => { var productStore = this.store.ElementFactory.CreateElement<ProductState>(); this.product = productStore.CreateProduct(prod => prod.InstanceName = "Foo"); var property = (Property)this.product.CreateProperty(); property.RawValue = "GuidanceValue"; property.Info = Mocks.Of<IPropertyInfo>().First(i => i.Name == "GuidanceName" && i.Type == "System.String" && i.IsVisible == true && i.IsReadOnly == false); }); this.uriService = new Mock<IUriReferenceService>(); this.uriService.Setup(x => x.ResolveUri<ITemplate>(It.IsAny<Uri>())).Returns(this.template.Object); this.command = new GenerateModelingCodeCommand { TargetFileName = "Foo", TemplateUri = new Uri("t4://foo.tt"), UriService = this.uriService.Object, ModelElement = (ModelElement)this.product, ModelFile = "C:\\Temp\\foo" + NuPattern.Runtime.StoreConstants.RuntimeStoreExtension, ServiceProvider = this.serviceProvider.Object, Solution = this.solution, }; // Set modelbus adapter var adapter = new Mock<ModelBusAdapterManager>(); this.modelBus.Setup(x => x.FindAdapterManagers(It.IsAny<object[]>())).Returns(new[] { adapter.Object }); adapter.Setup(x => x.GetSupportedLogicalAdapterIds()).Returns(new[] { "FooAdapter" }); adapter.Setup(x => x.GetExposedElementTypes("FooAdapter")).Returns(new[] { new SupportedType(typeof(IProduct)) }); }
public void WhenEventsAreRaised_ThenStoreIsInATransaction() { var store = new DslTestStore <ProductStateStoreDomainModel>(); IProductState productState = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement <ProductState>(); }); IProduct product = null; bool inTransaction = false; productState.ElementInstantiated += (sender, args) => inTransaction = store.Store.TransactionActive; store.TransactionManager.DoWithinTransaction(() => { product = productState.CreateProduct(); }); Assert.True(inTransaction); }
public void WhenTransactionCommitedWhileSerializing_ThenDoesNotRaiseTransactionCommitedEvent() { var store = new DslTestStore <ProductStateStoreDomainModel>(); store.Store.PropertyBag[ProductState.IsSerializingKey] = true; IProductState productState = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement <ProductState>(); }); var fired = false; productState.TransactionCommited += (sender, args) => fired = true; store.TransactionManager.DoWithinTransaction(() => { productState.CreateProduct(); }); Assert.False(fired); }
public void WhenPropertyInstantiated_ThenRaisesInstantiatedEvent() { var store = new DslTestStore <ProductStateStoreDomainModel>(); IProductState productState = null; IProduct product = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement <ProductState>(); product = productState.CreateProduct(); }); IInstanceBase instantiated = null; productState.ElementInstantiated += (sender, args) => instantiated = args.Value; store.TransactionManager.DoWithinTransaction(() => { product.CreateProperty(); }); Assert.NotNull(instantiated); }
public void WhenElementInstantiated_ThenDoesNotRaisePropertyChangedEventsFromInitializerSetters() { var store = new DslTestStore<ProductStateStoreDomainModel>(); IProductState productState = null; IView view = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement<ProductState>(); var product = productState.CreateProduct(); view = product.CreateView(); }); bool changed = false; productState.PropertyChanged += (sender, args) => changed = true; store.TransactionManager.DoWithinTransaction(() => { view.CreateElement(e => e.InstanceName = "Foo"); }); Assert.False(changed); }
public virtual void InitializeContext() { var store = new DslTestStore<PatternModelDomainModel>(); var serviceProvider = Mock.Get(store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of<IPatternManager>(p => p.InstalledToolkits == new List<IInstalledToolkitInfo>())); store.TransactionManager.DoWithinTransaction(() => { this.PatternModel = store.ElementFactory.CreateElement<PatternModelSchema>(); var pattern = this.PatternModel.Create<PatternSchema>(); pattern.PatternLink = "patternmanager://foo"; var uriService = Mock.Of<IUriReferenceService>( u => u.ResolveUri<IInstanceBase>(It.IsAny<Uri>()) == Mock.Of<IProduct>(p => p.ToolkitInfo.Identifier == "ToolkitId")); pattern.UriService = uriService; this.Property = pattern.Create<PropertySchema>(); }); }
public void InitializeContext() { var uriService = Mock.Of<IUriReferenceService>( u => u.ResolveUri<IInstanceBase>(It.IsAny<Uri>()) == Mock.Of<IProduct>(p => p.ToolkitInfo.Identifier == "AuthoredToolkit")); var store = new DslTestStore<PatternModelDomainModel>(); var serviceProvider = Mock.Get(store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of<IPatternManager>(p => p.InstalledToolkits == new List<IInstalledToolkitInfo>())); PatternModelSchema patternModel = null; store.TransactionManager.DoWithinTransaction(() => { patternModel = store.ElementFactory.CreateElement<PatternModelSchema>(); }); var patternSchema = patternModel.Create<PatternSchema>(); patternSchema.Name = "FooPattern"; patternSchema.PatternLink = "patternmanager://foo"; patternSchema.UriService = uriService; var view = patternSchema.Create<ViewSchema>(); view.Name = "View1"; store.TransactionManager.DoWithinTransaction(() => { this.collection = store.ElementFactory.CreateElement<CollectionSchema>("Collection1"); var extensionPoint = store.ElementFactory.CreateElement<ExtensionPointSchema>("ExtensionPoint1"); this.collection.ExtensionPoints.Add(extensionPoint); view.Elements.Add(collection); }); }
public void WhenElementInstantiated_ThenRaisesInstantiatedEvent() { var store = new DslTestStore<ProductStateStoreDomainModel>(); IProductState productState = null; IView view = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement<ProductState>(); var product = productState.CreateProduct(); view = product.CreateView(); }); IInstanceBase instantiated = null; productState.ElementInstantiated += (sender, args) => instantiated = args.Value; store.TransactionManager.DoWithinTransaction(() => { view.CreateElement(); }); Assert.NotNull(instantiated); }
public void WhenProductInstantiatedWhileSerializing_ThenDoesNotRaisePropertyChangeEvents() { var store = new DslTestStore <ProductStateStoreDomainModel>(); store.Store.PropertyBag[ProductState.IsSerializingKey] = true; IProductState productState = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement <ProductState>(); }); bool changed = false; IProduct product = null; productState.PropertyChanged += (sender, args) => changed = true; store.TransactionManager.DoWithinTransaction(() => { product = productState.CreateProduct(); }); Assert.False(changed); }
public void WhenElementInstantiated_ThenDoesNotRaisePropertyChangedEventsFromInitializerSetters() { var store = new DslTestStore <ProductStateStoreDomainModel>(); IProductState productState = null; IView view = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement <ProductState>(); var product = productState.CreateProduct(); view = product.CreateView(); }); bool changed = false; productState.PropertyChanged += (sender, args) => changed = true; store.TransactionManager.DoWithinTransaction(() => { view.CreateElement(e => e.InstanceName = "Foo"); }); Assert.False(changed); }
public void Initialize() { this.store = new DslTestStore <ProductStateStoreDomainModel>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.element = this.store.ElementFactory.CreateElement <Product>(); tx.Commit(); } this.bindingContext = new Mock <IDynamicBindingContext> { DefaultValue = DefaultValue.Mock }; Mock.Get(this.store.ServiceProvider) .Setup(x => x.GetService(typeof(IBindingFactory))) .Returns(Mock.Of <IBindingFactory>(factory => factory.CreateContext() == this.bindingContext.Object)); this.element.InstanceName = "Hello"; this.element.Info = Mock.Of <IElementInfo>(info => info.Name == "My" && info.ValidationSettings == new IBindingSettings[] { Mock.Of <IBindingSettings>() }); }
public void WhenNestedTransactionNotCommited_ThenNestedChangesNotCommited() { var store = new DslTestStore<ProductStateStoreDomainModel>(); IProductState productState = null; IProduct product = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement<ProductState>(); product = productState.CreateProduct(); }); var committed = false; store.Store.EventManagerDirectory.TransactionCommitted.Add(new EventHandler<TransactionCommitEventArgs>( (sender, args) => committed = true)); var parentTx = store.TransactionManager.BeginTransaction(); product.DefinitionName = "foo"; var nestedTx = store.TransactionManager.BeginTransaction(); product.InstanceName = "bar"; nestedTx.Dispose(); Assert.NotEqual("bar", product.InstanceName); parentTx.Commit(); Assert.True(committed); Assert.Equal("foo", product.DefinitionName); }
public void InitializeContext() { var store = new DslTestStore<PatternModelDomainModel>(); var serviceProvider = Mock.Get(store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of<IPatternManager>(p => p.InstalledToolkits == new List<IInstalledToolkitInfo>())); PatternModelSchema authoredPatternModel = null; store.TransactionManager.DoWithinTransaction(() => { authoredPatternModel = store.ElementFactory.CreateElement<PatternModelSchema>(); }); var uriService = Mock.Of<IUriReferenceService>( u => u.ResolveUri<IInstanceBase>(It.IsAny<Uri>()) == Mock.Of<IProduct>(p => p.ToolkitInfo.Identifier == "AuthoredToolkit")); var patternSchema = authoredPatternModel.Create<PatternSchema>(); patternSchema.Name = "FooPattern"; patternSchema.PatternLink = "patternmanager://foo"; patternSchema.UriService = uriService; this.view = patternSchema.Create<ViewSchema>(); this.view.Name = "View1"; store.TransactionManager.DoWithinTransaction(() => { this.authoredExtensionPoint = store.ElementFactory.CreateElement<ExtensionPointSchema>("ExtensionPoint1"); this.view.ExtensionPoints.Add(this.authoredExtensionPoint); }); // Customize Toolkit var tailoredUriService = Mock.Of<IUriReferenceService>( u => u.ResolveUri<IInstanceBase>(It.IsAny<Uri>()) == Mock.Of<IProduct>(p => p.ToolkitInfo.Identifier == "TailoredToolkit")); var tailoredPatternModel = PatternModelSpec.TailorPatternModel(authoredPatternModel, new Version("1.0.0.0"), "AuthoredToolkit"); store.TransactionManager.DoWithinTransaction(() => { tailoredPatternModel.Pattern.UriService = tailoredUriService; tailoredPatternModel.BaseId = "AuthoredToolkit"; }); this.tailoredExtensionPoint = tailoredPatternModel.Pattern.Views[0].ExtensionPoints[0]; }
public void WhenProductInstantiatedWhileSerializing_ThenDoesNotRaiseInstantiatedEvent() { var store = new DslTestStore<ProductStateStoreDomainModel>(); store.Store.PropertyBag[ProductState.IsSerializingKey] = true; IProductState productState = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement<ProductState>(); }); IInstanceBase instantiated = null; IProduct product = null; productState.ElementInstantiated += (sender, args) => instantiated = args.Value; store.TransactionManager.DoWithinTransaction(() => { product = productState.CreateProduct(); }); Assert.Null(instantiated); }
public void WhenProductInstantiatedWhileSerializing_ThenDoesNotRaisePropertyChangeEvents() { var store = new DslTestStore<ProductStateStoreDomainModel>(); store.Store.PropertyBag[ProductState.IsSerializingKey] = true; IProductState productState = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement<ProductState>(); }); bool changed = false; IProduct product = null; productState.PropertyChanged += (sender, args) => changed = true; store.TransactionManager.DoWithinTransaction(() => { product = productState.CreateProduct(); }); Assert.False(changed); }
public void Initialize() { this.solutionEvents = new Mock<ISolutionEvents>(); this.itemEvents = new Mock<IItemEvents>(); this.messageService = new Mock<IUserMessageService>(); if (Directory.Exists(solutionItemsDir)) { Directory.Delete(solutionItemsDir, true); } Directory.CreateDirectory(solutionItemsDir); this.solution = new Solution { PhysicalPath = Path.GetTempFileName(), Items = { new SolutionFolder { PhysicalPath = Path.GetTempPath() + "\\Solution Items", Name = "Solution Items" } } }; this.store = new DslTestStore<ProductStateStoreDomainModel>(); this.toolkitInfo = new Mock<IInstalledToolkitInfo> { DefaultValue = DefaultValue.Mock }; this.toolkitInfo.Setup(f => f.Id).Returns("foo"); this.toolkitInfo.Setup(f => f.Version).Returns(new Version("1.0.0.0")); this.toolkitInfo.Setup(f => f.Schema.Pattern.ExtensionId).Returns("foo"); var installedFactories = new[] { this.toolkitInfo.Object }; var componentModel = new Mock<IComponentModel>(); componentModel.Setup(cm => cm.GetService<IEnumerable<IInstalledToolkitInfo>>()).Returns(installedFactories); componentModel.Setup(cm => cm.GetService<IToolkitRepository>()).Returns(Mock.Of<IToolkitRepository>()); var serviceProvider = Mock.Get(this.store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(SComponentModel))).Returns(componentModel.Object); serviceProvider.Setup(s => s.GetService(typeof(ISolution))).Returns(this.solution); this.shellEvents = new Mock<IShellEvents>(); this.shellEvents.Setup(x => x.IsInitialized).Returns(true); this.manager = new TestPatternManager(this.store.ServiceProvider, this.solution, this.shellEvents.Object, this.solutionEvents.Object, this.itemEvents.Object, installedFactories, this.messageService.Object); }
public void Initialize() { this.store = new DslTestStore<ProductStateStoreDomainModel>(); var productInfo = new Mock<IPatternInfo>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.product = this.store.ElementFactory.CreateElement<Product>(); this.product.Info = productInfo.Object; tx.Commit(); } this.viewInfo = new Mock<IViewInfo>(); this.viewInfo.Setup(v => v.Id).Returns(Guid.NewGuid()); this.viewInfo.Setup(v => v.Pattern).Returns(this.product.Info); productInfo.Setup(p => p.Views).Returns(new[] { this.viewInfo.Object }); }
public void WhenTransactionCommitedWhileSerializing_ThenDoesNotRaiseTransactionCommitedEvent() { var store = new DslTestStore<ProductStateStoreDomainModel>(); store.Store.PropertyBag[ProductState.IsSerializingKey] = true; IProductState productState = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement<ProductState>(); }); var fired = false; productState.TransactionCommited += (sender, args) => fired = true; store.TransactionManager.DoWithinTransaction(() => { productState.CreateProduct(); }); Assert.False(fired); }
public void WhenTransactionCommited_ThenRaisesTransactionCommitedEvent() { var store = new DslTestStore<ProductStateStoreDomainModel>(); IProductState productState = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement<ProductState>(); }); var fired = false; productState.TransactionCommited += (sender, args) => fired = true; store.TransactionManager.DoWithinTransaction(() => { productState.CreateProduct(); }); Assert.True(fired); }
public void Initialize() { this.store = new DslTestStore<ProductStateStoreDomainModel>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.element = this.store.ElementFactory.CreateElement<Product>(); tx.Commit(); } this.bindingContext = new Mock<IDynamicBindingContext> { DefaultValue = DefaultValue.Mock }; Mock.Get(this.store.ServiceProvider) .Setup(x => x.GetService(typeof(IBindingFactory))) .Returns(Mock.Of<IBindingFactory>(factory => factory.CreateContext() == this.bindingContext.Object)); this.element.InstanceName = "Hello"; this.element.Info = Mock.Of<IElementInfo>(info => info.Name == "My" && info.ValidationSettings == new IBindingSettings[] { Mock.Of<IBindingSettings>() }); }
public void InitializeContext() { var type = typeof(ISolutionEvents); var store = new DslTestStore<PatternModelDomainModel>(); store.TransactionManager.DoWithinTransaction( () => this.product = store.ElementFactory.CreateElement<PatternModelSchema>().Create<PatternSchema>()); }
public void WhenProductInstantiated_ThenRetrievesProductInstance() { var store = new DslTestStore<ProductStateStoreDomainModel>(); IProductState productState = null; IProduct product = null; store.TransactionManager.DoWithinTransaction(() => { productState = store.ElementFactory.CreateElement<ProductState>(); product = productState.CreateProduct(); }); Assert.Equal(1, productState.FindAll<Product>().Count()); Assert.Equal(product.Id, productState.FindAll<Product>().ElementAt(0).Id); }
public void Initialize() { this.store = new DslTestStore<ProductStateStoreDomainModel>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.element = this.store.ElementFactory.CreateElement<Product>(); tx.Commit(); } }
public void InitializeContext() { var store = new DslTestStore<PatternModelDomainModel>(); store.TransactionManager.DoWithinTransaction( () => this.sourcePatternModel = store.ElementFactory.CreateElement<PatternModelSchema>()); var serviceProvider = Mock.Get(store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of<IPatternManager>(p => p.InstalledToolkits == new List<IInstalledToolkitInfo>())); }
private static Product CreateProduct() { ProductState productStore = null; DslTestStore<ProductStateStoreDomainModel> store = new DslTestStore<ProductStateStoreDomainModel>(); store.TransactionManager.DoWithinTransaction(() => { productStore = store.ElementFactory.CreateElement<ProductState>(); }); var product = (Product)productStore.CreateProduct(); product.InstanceName = "AProduct1"; product.Info = Mock.Of<IPatternInfo>(i => i.Name == "AProduct" && i.CodeIdentifier == "AProduct"); return product; }