예제 #1
0
        public void ResourceFileProvider_FullPath()
        {
            var path     = new Uri("res://Effort.Test/Internal/Resources/");
            var provider = new ResourceFileProvider(path);

            provider.IsValid.Should().BeTrue();

            var file = provider.GetFile("EmptyResource.txt");

            file.Exists.Should().BeTrue();

            using (StreamReader reader = new StreamReader(file.Open()))
            {
                reader.ReadLine().Should().Be("Hello World!");
            }
        }
예제 #2
0
        public void Invoke()
        {
            var traceListener = new ConsolidatedConsoleTraceListener(
                new Dictionary<string, string>
                    {
                        {
                            "LostDoc.Core.Template",
                            "Template"
                        },
                        {
                            "LostDoc.Core.Bundle",
                            "Bundle"
                        },
                        {
                            "LostDoc.Core.Template.AssetResolver",
                            "Resolve"
                        }
                    });

            
            TraceSources.TemplateSource.Listeners.Add(traceListener);
            TraceSources.AssetResolverSource.Listeners.Add(traceListener);
            try
            {
                if (this.Verbose.IsPresent)
                {
                    const SourceLevels verboseLevel = SourceLevels.All;
                    TraceSources.TemplateSource.Switch.Level = verboseLevel;
                    TraceSources.AssetResolverSource.Switch.Level = verboseLevel;
                    TraceSources.BundleSource.Listeners.Add(traceListener);
                }
                else
                {
                    const SourceLevels normalLevel = SourceLevels.Information | SourceLevels.Warning | SourceLevels.Error | SourceLevels.ActivityTracing;
                    TraceSources.TemplateSource.Switch.Level = normalLevel;
                    TraceSources.AssetResolverSource.Switch.Level = normalLevel;
                }

                LinkedList<FileInfo> includedFiles = new LinkedList<FileInfo>();

                if (File.Exists(this.Path))
                    includedFiles.AddLast(new FileInfo(this.Path));
                else if (Directory.Exists(this.Path))
                {
                    Directory.GetFiles(this.Path, "*.ldoc", SearchOption.AllDirectories)
                             .Aggregate(includedFiles,
                                        (l, f) => l.AddLast(new FileInfo(f)).List);
                }
                else
                    throw new FileNotFoundException(System.IO.Path.GetFullPath(this.Path));


                Bundle bundle = new Bundle(this.IgnoreVersionComponent);

                TraceSources.TemplateSource.TraceInformation("Merging LostDoc files into bundle.");

                var xmlSettings = new XmlReaderSettings
                {
                    CheckCharacters = false
                };

                foreach (FileInfo file in includedFiles)
                {
                    TraceSources.TemplateSource.TraceEvent(TraceEventType.Information, 0, "Path: {0}", file.Name);
                    XDocument fileDoc;
                    using (var reader = XmlReader.Create(file.FullName, xmlSettings))
                        fileDoc = XDocument.Load(reader);

                    bundle.Add(fileDoc);
                }

                // find template
                string appDir = Assembly.GetExecutingAssembly().Location;
                string cwDir = Directory.GetCurrentDirectory();


                IFileProvider fsProvider = new DirectoryFileProvider();
                IFileProvider resourceProvider = new ResourceFileProvider("LBi.LostDoc.ConsoleApplication.Templates");

                IFileProvider selectedFileProvider = null;
                string templatePath = null;

                if (System.IO.Path.IsPathRooted(this.Template) &&
                    fsProvider.FileExists(System.IO.Path.Combine(this.Template, "template.xml")))
                {
                    selectedFileProvider = fsProvider;
                    templatePath = this.Template;
                }
                else if (!System.IO.Path.IsPathRooted(this.Template))
                {
                    string tmp = System.IO.Path.Combine(cwDir, this.Template, "template.xml");
                    if (fsProvider.FileExists(tmp))
                    {
                        selectedFileProvider = fsProvider;
                        templatePath = tmp;
                    }
                    else
                    {
                        tmp = System.IO.Path.Combine(appDir, this.Template, "template.xml");
                        if (fsProvider.FileExists(tmp))
                        {
                            selectedFileProvider = fsProvider;
                            templatePath = tmp;
                        }
                        else
                        {
                            tmp = System.IO.Path.Combine(this.Template, "template.xml");
                            if (resourceProvider.FileExists(tmp))
                            {
                                selectedFileProvider = resourceProvider;
                                templatePath = tmp;
                            }
                        }
                    }
                }

                if (templatePath == null)
                    throw new FileNotFoundException(this.Template);

                string outputDir = this.Output
                                   ?? (Directory.Exists(this.Path)
                                           ? this.Path
                                           : System.IO.Path.GetDirectoryName(this.Path));

                Template template = new Template(selectedFileProvider);

                template.Load(templatePath);
                AssetRedirectCollection assetRedirects;
                XDocument mergedDoc = bundle.Merge(out assetRedirects);
                var templateData = new TemplateData
                                       {
                                           OverwriteExistingFiles = this.Force.IsPresent,
                                           AssetRedirects = assetRedirects,
                                           Document = mergedDoc,
                                           IgnoredVersionComponent = this.IgnoreVersionComponent,
                                           Arguments = this.Arguments,
                                           TargetDirectory = outputDir
                                       };

                template.Generate(templateData);
            }
            finally
            {
                TraceSources.TemplateSource.Listeners.Remove(traceListener);
                TraceSources.AssetResolverSource.Listeners.Remove(traceListener);
            }
        }
예제 #3
0
        public void CollectData_ShouldSuccess2()
        {
            const string resourceTestFileName = "AdvertisementDataShort.xml";

            var products = ResourceFileProvider.GetParsedObjectFromResourceFile <Products>(resourceTestFileName);

            var domainProducts = new List <Product>
            {
                new Product()
                {
                    Name        = "Sole - Dover, Whole, Fresh",
                    Description = "Subcutaneous fat necrosis due to birth injury",
                    Price       = new Price()
                    {
                        Value    = 60,
                        Discount = 65,
                        Currency = new Currency()
                        {
                            Code = "IDR"
                        }
                    },
                    ProductCategories = new List <ProductCategory>
                    {
                        new ProductCategory()
                        {
                            Category = new Category
                            {
                                Name = "Tools"
                            }
                        }
                    },
                    ImageUrl        = @"http://dummyimage.com/127x193.jpg/dddddd/000000",
                    ProductShipping = new ProductShipping()
                    {
                        Currency = new Currency()
                        {
                            Code = "CNY"
                        },
                        ShippingPrice  = 14,
                        ShippingMethod = new ShippingMethod
                        {
                            Name = "PowerShares KBW Bank Portfolio"
                        }
                    }
                },
                new Product()
                {
                    Name        = "Pepperoni Slices",
                    Description = "Rapidly progressive nephritic syndrome with unspecified morphologic changes",
                    Price       = new Price()
                    {
                        Value    = 15,
                        Discount = 80,
                        Currency = new Currency()
                        {
                            Code = "BAM"
                        }
                    },
                    ProductCategories = new List <ProductCategory>
                    {
                        new ProductCategory()
                        {
                            Category = new Category
                            {
                                Name = "Computers"
                            }
                        }
                    },
                    ImageUrl        = @"http://dummyimage.com/225x231.jpg/cc0000/ffffff",
                    ProductShipping = new ProductShipping()
                    {
                        Currency = new Currency()
                        {
                            Code = "MKD"
                        },
                        ShippingPrice  = 63,
                        ShippingMethod = new ShippingMethod
                        {
                            Name = "Rapidly progressive nephritic syndrome with unspecified morphologic changes"
                        }
                    }
                },
                new Product()
                {
                    Name        = "Raisin - Golden",
                    Description = "Postprocedural ovarian failure",
                    Price       = new Price()
                    {
                        Value    = 41,
                        Discount = 11,
                        Currency = new Currency()
                        {
                            Code = "RSD"
                        }
                    },
                    ProductCategories = new List <ProductCategory>
                    {
                        new ProductCategory()
                        {
                            Category = new Category
                            {
                                Name = "Electronics"
                            }
                        }
                    },
                    ImageUrl        = @"http://dummyimage.com/150x136.jpg/5fa2dd/ffffff",
                    ProductShipping = new ProductShipping()
                    {
                        Currency = new Currency()
                        {
                            Code = "IRR"
                        },
                        ShippingPrice  = 58,
                        ShippingMethod = new ShippingMethod
                        {
                            Name = "Brady Corporation"
                        }
                    }
                }
            };

            _externalClientDataProviderMock.Setup(ecdp => ecdp.GetData())
            .Returns(products);

            _productExtractorMock.Setup(pe => pe.ExtractProducts(products))
            .Returns(domainProducts);

            //ACT
            IEnumerable <Product> actual = _followingUpDataCollector.CollectData();

            ContentAssert.AreEqual(domainProducts, actual);
        }