Ejemplo n.º 1
0
 public static GenerateProductCodeCommand CreateTempGenerateCodeCommand(this IProductElement element,
     IServiceProvider sp
     , string targetFileName
     , string targetPath
     , string templateUri
     , string namePrefix = "GenerateCode"
     , string buildAction = "Compile")
 {
     var guid = Guid.NewGuid();
     ISolution solution = sp.TryGetService<ISolution>();
     IPatternManager patternManager = sp.TryGetService<IPatternManager>();
     IUriReferenceService uriService = sp.TryGetService<IUriReferenceService>();
     var command = new GenerateProductCodeCommand
     {
         TargetBuildAction = buildAction,
         TargetCopyToOutput = CopyToOutput.DoNotCopy,
         Settings = new EmptySettings { Name = String.Format("{0}{1}", namePrefix, guid.ToString()), Id = guid },
         PatternManager = patternManager,
         UriService = uriService,
         Solution = solution,
         ServiceProvider = sp,
         TargetFileName = targetFileName,
         TargetPath = targetPath,
         CurrentElement = element,
         TemplateUri = new Uri(templateUri)
     };
     return command;
 }
            public virtual void Initialize()
            {
                this.Store = new DslTestStore<ProductStateStoreDomainModel>();
                this.Store.TransactionManager.DoWithinTransaction(() =>
                {
                    var productStore = this.Store.ElementFactory.CreateElement<ProductState>();
                    this.Product = productStore.CreateProduct(prod => prod.InstanceName = "Pattern");
                    this.View = this.Product.CreateView();
                    this.Collection = this.View.CreateCollection(x => x.InstanceName = "Collection");
                    this.Element = this.Collection.CreateElement(x => x.InstanceName = "CurrentElement");
                });

                this.Solution = new Solution
                {
                    Name = "Solution",
                    Items = 
                    {
                        new SolutionFolder
                        {
                            Name = "Solution Items", 
                            Items = 
                            {
                                new Item
                                {
                                    Name = "Foo.cs",
                                },
                                new Item
                                {
                                    Name = "Bar.cs",
                                }
                            }
                        }
                    }
                };

                this.PatternManager = new Mock<IPatternManager>();
                this.UriService = new Mock<IUriReferenceService>();
                this.Listener = new Mock<TraceListener>();

                this.Command = new Mock<GenerateProductCodeCommand> { CallBase = true }.Object;
                this.Command.PatternManager = this.PatternManager.Object;
                this.Command.CurrentElement = this.Element;
                this.Command.ModelElement = this.Element as ModelElement;
                this.Command.ModelFile = "TestModelFile";
                this.Command.ServiceProvider = new Mock<IServiceProvider>().Object;
                this.Command.Settings = Mock.Of<ICommandSettings>(x => x.Id == Guid.NewGuid());
                this.Command.Solution = this.Solution;
                this.Command.TargetFileName = "Bar.cs";
                this.Command.TargetPath = "Solution Items";
                this.Command.TemplateUri = new Uri("template://foo/bar");
                this.Command.UriService = this.UriService.Object;

                this.Template = new Mock<ITemplate>();
                this.Template
                    .Setup(x => x.Unfold(It.IsAny<string>(), It.IsAny<IItemContainer>()))
                    .Returns(this.Solution.Traverse().OfType<IItem>().First(i => i.Name == this.Command.TargetFileName));

                this.UriService.Setup(x => x.ResolveUri<ITemplate>(It.Is<Uri>(u => u.Scheme == "template")))
                    .Returns(this.Template.Object);
                this.UriService.Setup(x => x.CreateUri(It.IsAny<IItem>(), null)).Returns(new Uri("solution://folder/solution items/foo.cs"));

                Mock.Get(this.Command).Protected().Setup<string>("SerializeReference").Returns("foo://bar");

                Tracer.Manager.AddListener(typeof(GenerateProductCodeCommand).FullName, this.Listener.Object);
                Tracer.Manager.GetSource(typeof(GenerateProductCodeCommand).FullName).Switch.Level = SourceLevels.All;
            }