public static void Create(InvoiceModel model, AppContext context) { EntityParser parser = new EntityParser(); ModelFactory factory = new ModelFactory(); Repository <Invoice> invoiceRepository = new Repository <Invoice>(context); Repository <Item> itemRepository = new Repository <Item>(context); Invoice invoice = new Invoice(); invoice.Id = model.Id; invoice.Date = model.Date; invoice.Customer = context.Customers.Find(model.Customer); invoice.Status = (Status)Enum.Parse(typeof(Status), model.Status); //a way to avoid a front-end problem when BillTo and Ship to are the same person - one of them is always null if (model.BillTo == null) { invoice.BillTo = context.Customers.Find(model.ShipTo.Id); } else if (model.ShipTo == null) { invoice.BillTo = context.Customers.Find(model.BillTo.Id); } else { invoice.BillTo = context.Customers.Find(model.BillTo.Id); invoice.ShipTo = context.Customers.Find(model.ShipTo.Id); } invoiceRepository.Insert(invoice); }
public void GetProperties_WhenEntityWithAttributes_ExpectPermittedNames() { // Arrange var entityParser = new EntityParser <TestEntity>(); // Act var stopwatch = Stopwatch.StartNew(); var permittedProperties = entityParser.PermittedProperties; stopwatch.Stop(); // Assert this.WriteTimeElapsed(stopwatch); Assert.That(permittedProperties, Is.Not.Null); var expected = new List <EntityProperty> { new EntityProperty { InternalName = "PropertyFour", QueryName = "property_four", IsPermitted = true }, new EntityProperty { InternalName = "PropertyOne", QueryName = "PropertyOne", IsPermitted = true }, new EntityProperty { InternalName = "PropertyThree", QueryName = "property_three", IsPermitted = true } }; permittedProperties.ShouldDeepEqual(expected); }
public void DtoBuilder_SimpleEntity_PropertiesAdded() { var code = SampleCodeProvider.EntityOnlySimpleProperties; var metadata = EntityParser.FromString(code); metadata.DtoName = "EntityOnlySimplePropertiesDTO"; var tree = DtoBuilder.BuildDto(metadata, dtoNamespace: "Test.Namespace.Extra.Long"); Assert.IsNotNull(tree); var codeText = tree.ToString(); foreach (var prop in metadata.Properties.ToList()) { Assert.IsTrue(codeText.Contains($"public {prop.Type} {prop.Name} {{ get; set; }}")); if (prop != metadata.Properties.Last()) { Assert.IsTrue(codeText.Contains($"{prop.Name} = p.{prop.Name},")); } else { Assert.IsTrue(codeText.Contains($"{prop.Name} = p.{prop.Name}")); } Assert.IsFalse(codeText.Contains($",{prop.Name} = p.{prop.Name}")); Assert.IsTrue(codeText.Contains($"model.{prop.Name} = dto.{prop.Name};")); } Assert.IsTrue(codeText.Contains("using DtoGenerator.Tests.CodeSamples;")); }
public void EntityParser_ParseEntity_MultipleClassDeclarations() { var code = SampleCodeProvider.MultipleClasses; var metadata = EntityParser.FromString(code); Assert.Fail("Should not reach here."); }
public void DtoBuilder_ComplexEntityDto_Regenerated() { var code = SampleCodeProvider.ComplexEntity; var metadata = EntityParser.FromString(code); metadata.DtoName = "ComplexEntityDTO"; var otherEntityProp = metadata.Properties.Where(p => p.RelatedEntityName == "OtherEntity").Single(); otherEntityProp.RelationMetadata = EntityParser.FromString(SampleCodeProvider.OtherEntity); var existingDtoTree = CSharpSyntaxTree.ParseText(SampleCodeProvider.ComplexEntityDto); var tree = DtoBuilder.BuildDto(metadata, existingDto: existingDtoTree); Assert.IsNotNull(tree); var codeText = tree.ToString(); Assert.IsTrue(codeText.Contains("public string OtherNumber { get; set; }")); Assert.IsTrue(codeText.Contains("OtherNumber = p.Other != null ? p.Other.Number : default (string),")); Assert.IsTrue(codeText.Contains("public IEnumerable<SomethingDTO> List1 { get; set; }")); Assert.IsTrue(codeText.Contains("public IEnumerable<SomethingDTO> Enumerable2 { get; set; }")); Assert.IsTrue(codeText.Contains("public IEnumerable<SomethingDTO> Collection2 { get; set; }")); Assert.IsTrue(codeText.Contains("List1 = p.List1.AsQueryable().Select(this._somethingMapper.SelectorExpression),")); Assert.IsTrue(codeText.Contains("Enumerable2 = p.Enumerable2.AsQueryable().Select(this._somethingMapper.SelectorExpression),")); Assert.IsTrue(codeText.Contains("Collection2 = p.Collection2.AsQueryable().Select(this._somethingMapper.SelectorExpression),")); }
public static void UpdateCompany(CompanyModel model, AppContext context) { Repository <Company> companyRepository = new Repository <Company>(context); Company company = new Company(); EntityParser parser = new EntityParser(); company = parser.Create(model, context); companyRepository.Update(company, model.Id); }
public static void UpdateInvoice(InvoiceModel model, AppContext context) { Repository <Invoice> invoiceRepository = new Repository <Invoice>(context); Invoice invoice = new Invoice(); EntityParser parser = new EntityParser(); invoice = parser.Create(model, context); invoiceRepository.Update(invoice, model.Id); }
private static IMetaDataBuilder ResolveMetaDataBuilder() { var genericTypesToMapToArray = new List<string> { "List`1", "IEnumerable`1" }; var entityParser = new EntityParser( new JavascriptTypeMapper(), genericTypesToMapToArray, ResolveValidationMetaDataProvider()); return new MetaDataBuilder(entityParser); }
public void TestDbContextFile() { var filePath = Utils.GetDbContextType(); var parser = new EntityParser(filePath); var result = parser.ParseToString(); Utils.WriteResultInDebug(result); Assert.True(string.IsNullOrWhiteSpace(result)); }
public void TestEntityFile() { var filePath = Utils.GetFirstEntityFile(); var parser = new EntityParser(filePath); var result = parser.ParseToString(); Utils.WriteResultInDebug(result); Assert.NotNull(result); }
public void EntityParser_ParseEntity_WithCollectionProperties() { var code = SampleCodeProvider.EntityWithCollectionProperties; var metadata = EntityParser.FromString(code); Assert.AreEqual(6, metadata.Properties.Count); Assert.IsTrue(metadata.Properties.All(p => !p.IsSimpleProperty)); Assert.IsTrue(metadata.Properties.All(p => p.IsCollection)); Assert.IsTrue(metadata.Properties.All(p => p.IsRelation)); Assert.IsTrue(metadata.Properties.All(p => p.RelatedEntityName == "Something")); }
public ShipLoader(ILogger <ShipLoader> logger, EntityParser entityParser, IOptions <ServiceOptions> options, IJsonFileReaderWriter jsonFileReaderWriter, VehicleParser vehicleParser, LocalisationService localisationService, LoaderService <Manufacturer> manufacturersService) { _logger = logger; _entityParser = entityParser; _jsonFileReaderWriter = jsonFileReaderWriter; _vehicleParser = vehicleParser; _localisationService = localisationService; Manufacturers = manufacturersService.Items; _options = options.Value; }
public void DuplicateHashtagIsFoundTwice() { // Arrange const string text = "#test #test"; // Act var hashtags = EntityParser.ExtractHashtags(text); // Assert Assert.AreEqual(2, hashtags.Count); Assert.IsTrue(hashtags.All(t => t.Tag == "test")); }
public CommodityLoader(ILogger <CommodityLoader> logger, EntityParser entityParser, IJsonFileReaderWriter jsonFileReaderWriter, LoaderService <CommodityTypeAndSubType> commodityTypeService, IOptions <ServiceOptions> options, LocalisationService localisationService) { _logger = logger; _entityParser = entityParser; _jsonFileReaderWriter = jsonFileReaderWriter; _localisationService = localisationService; CommodityTypes = commodityTypeService.Items; _options = options.Value; }
public void SetHeroAvatarUnpacked(string hero, string avatar) { Logger.Log.Verbose("verbose test"); var extractionDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(extractionDirectory); try { var heroResourcesName = GetHeroResourcesName(hero); var rootResourcesDirectory = _resourcesManager.ExtractHeroResources(extractionDirectory, heroResourcesName); var heroResourcesDirectory = Path.Combine(rootResourcesDirectory, "heroes"); var heroDirectoryPath = Path.Combine(heroResourcesDirectory, heroResourcesName); var heroEntityPath = GetHeroEntityPath(heroDirectoryPath, heroResourcesName); var heroXml = _xmlManager.GetXmlDocument(heroEntityPath); var heroNode = heroXml.QuerySelector("hero"); var avatarElements = heroNode.QuerySelectorAll("altavatar"); var avatarKey = GetHeroAvatarKey(hero, avatar); var avatarElement = avatarElements.FirstOrDefault(a => string.Equals(a.GetAttribute("key"), avatarKey, StringComparison.InvariantCultureIgnoreCase)); if (avatarElement == null) { throw ThrowHelper.AvatarNotFound($"Avatar {avatar} not found for hero {hero}.", avatar); } foreach (var parser in EntityParser.GetRegisteredEntityParsers(_xmlManager)) { parser.SetEntity(heroDirectoryPath, avatarKey); } var destinationHeroDirectory = Path.Combine(_appConfiguration.HoNPath, "game", "heroes"); Directory.CreateDirectory(destinationHeroDirectory); foreach (string dirPath in Directory.GetDirectories(heroResourcesDirectory, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(heroResourcesDirectory, destinationHeroDirectory)); } foreach (string newPath in Directory.GetFiles(heroResourcesDirectory, "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace(heroResourcesDirectory, destinationHeroDirectory), true); } } finally { Directory.Delete(extractionDirectory, true); } }
public ExcelReader(String fileName) { FileStream stream = new FileStream(fileName, FileMode.Open); workBook = WorkbookFactory.Create(stream); stream.Close(); empleadoParser = new EmployeeParser(); percepcionParser = new PercepcionParser(); deduccionParser = new DeduccionParser(); incapacidadParser = new IncapacidadParser(); horasExtraParser = new HorasExtraParser(); }
private static IMetaDataBuilder ResolveMetaDataBuilder() { var genericTypesToMapToArray = new List <string> { "List`1", "IEnumerable`1" }; var entityParser = new EntityParser( new JavascriptTypeMapper(), genericTypesToMapToArray, ResolveValidationMetaDataProvider()); return(new MetaDataBuilder(entityParser)); }
protected override void Initialize() { IEntityParser entityParser = new EntityParser(); entityParser.OpenFile("../../../Data/Entities.xml"); var entityDataCollection = entityParser.LoadEntities(); foreach (var entityData in entityDataCollection) { var entity = _entityFactory.CreateEntity(entityData.Components); _entityRepository.InsertEntity(entity); } }
public void EntityParser_ParseEntity_SimplePropertiesOnly() { var code = SampleCodeProvider.EntityOnlySimpleProperties; var metadata = EntityParser.FromString(code); Assert.AreEqual(5, metadata.Properties.Count); Assert.IsTrue(metadata.Properties.Any(p => p.Name == "Id" && p.IsSimpleProperty && p.Type == "int")); Assert.IsTrue(metadata.Properties.Any(p => p.Name == "Name" && p.IsSimpleProperty && p.Type == "string")); Assert.IsTrue(metadata.Properties.Any(p => p.Name == "Date" && p.IsSimpleProperty && p.Type == "DateTime?")); Assert.IsTrue(metadata.Properties.Any(p => p.Name == "Date2" && p.IsSimpleProperty && p.Type == "Nullable<System.DateTime>" && !p.IsCollection)); Assert.IsTrue(metadata.Properties.Any(p => p.Name == "OtherString" && p.IsSimpleProperty && p.Type == "string")); }
public void TestReadInvalidEntity(string fileName) { // Given var invalidEntity = GetFileContents(fileName); var entityData = Encoding.ASCII.GetBytes(invalidEntity); // When var parser = new EntityParser(entityData); var entities = parser.Parse(); // Then Assert.IsNotNull(entities); Assert.IsTrue(entities.Count == 0); }
public ItemLoader(ILogger <ItemLoader> logger, EntityParser entityParser, IJsonFileReaderWriter jsonFileReaderWriter, LoaderService <Manufacturer> manufacturersService, IOptions <ServiceOptions> options, LocalisationService localisationService, LoaderService <Ship> shipService, LoaderService <Commodity> commodtiyService) { _logger = logger; _entityParser = entityParser; _jsonFileReaderWriter = jsonFileReaderWriter; _localisationService = localisationService; Manufacturers = manufacturersService.Items; Ships = shipService.Items; Commodities = commodtiyService.Items; _options = options.Value; }
public void DtoBuilder_EntityWithBase_DataAnnotations_MetadataType() { var code = SampleCodeProvider.SampleTable3; var metadata = EntityParser.FromString(code); metadata.DtoName = "SampleTable3DTO"; var tree = DtoBuilder.BuildDto(metadata, dtoNamespace: "Some.Namespace", addDataAnnotations: true); Assert.IsNotNull(tree); var codeText = tree.ToString(); Assert.IsTrue(codeText.Contains("[MetadataType(typeof(SampleTable3MD))]")); }
public bool IsPermitted_WhenNameProvided_ExpectCorrectValue(string value) { // Arrange var entityParser = new EntityParser <TestEntity>(); // Act var stopwatch = Stopwatch.StartNew(); var isPermitted = entityParser.IsPermitted(value); stopwatch.Stop(); // Assert this.WriteTimeElapsed(stopwatch); return(isPermitted); }
public void MentionInMiddleIsExtractedCorrectly() { // Arrange const string text = "Hello @World how are you?"; // Act var mentions = EntityParser.ExtractMentions(text); // Assert Assert.AreEqual(1, mentions.Count); var m = mentions.First(); Assert.AreEqual(6, m.Start); Assert.AreEqual(12, m.End); Assert.AreEqual("World", m.ScreenName); }
public static async Task <PropertySelectorViewModel> Create(Document doc, string dtoName, SolutionLocation dtoLocation, Document existingDto = null) { var autogeneratedProperties = await EntityParser.GetAutoGeneratedProperties(existingDto); var instance = new PropertySelectorViewModel(); instance.EntityModel = await EntityViewModel.CreateRecursive(doc, depth : 3, existingProperties : autogeneratedProperties, canReuseBaseMapper : true); instance.EntityModel.DtoName = dtoName; instance.DtoLocation = dtoLocation; var isDerived = await EntityParser.HasBaseDto(existingDto, instance.EntityModel.BaseEntityDtoName); instance.EntityModel.ReuseBaseEntityMapper |= isDerived; return(instance); }
public void DtoBuilder_SimpleEntityExistingDto_PropertiesAdded() { var code = SampleCodeProvider.EntityOnlySimpleProperties; var metadata = EntityParser.FromString(code); metadata.DtoName = "EntityOnlySimplePropertiesDTO"; var existingDtoTree = CSharpSyntaxTree.ParseText(SampleCodeProvider.EntityOnlySimplePropertiesDto); var tree = DtoBuilder.BuildDto(metadata, existingDto: existingDtoTree); Assert.IsNotNull(tree); var codeText = tree.ToString(); foreach (var prop in metadata.Properties.ToList()) { Assert.IsTrue(codeText.Contains($"public {prop.Type} {prop.Name} {{ get; set; }}")); if (prop != metadata.Properties.Last()) { Assert.IsTrue(codeText.Contains($"{prop.Name} = p.{prop.Name},")); } else { Assert.IsTrue(codeText.Contains($"{prop.Name} = p.{prop.Name}")); } Assert.IsFalse(codeText.Contains($",{prop.Name} = p.{prop.Name}")); Assert.IsTrue(codeText.Contains($"model.{prop.Name} = dto.{prop.Name};")); } var customCodeBeginIdx = codeText.IndexOf("////BCC/"); var customCodeEndIdx = codeText.IndexOf("////ECC/"); var customPropIdx = codeText.IndexOf("public int CustomProperty { get; set; }"); var genPropIdx = codeText.IndexOf("public DateTime? Date { get; set; }"); Assert.AreNotEqual(-1, customPropIdx); Assert.AreNotEqual(-1, genPropIdx); Assert.AreNotEqual(-1, customCodeBeginIdx); Assert.AreNotEqual(-1, customCodeEndIdx); Assert.IsTrue(customPropIdx > customCodeBeginIdx && customPropIdx < customCodeEndIdx); Assert.IsTrue(genPropIdx > customCodeEndIdx || genPropIdx < customCodeBeginIdx); }
public void MentionAtEndIsCorrectlyExtracted() { // Arrange const string text = "This is a @test"; // Act var mentions = EntityParser.ExtractMentions(text); // Assert Assert.AreEqual(1, mentions.Count); var m = mentions.First(); Assert.AreEqual(10, m.Start); Assert.AreEqual(15, m.End); Assert.AreEqual("test", m.ScreenName); }
public void HashtagsInMiddleAreCorrectlyExtracted() { // Arrange const string text = "Hello #World this is a test"; // Act var hashtags = EntityParser.ExtractHashtags(text); // Assert Assert.AreEqual(1, hashtags.Count); var tag = hashtags.First(); Assert.AreEqual(6, tag.Start); Assert.AreEqual(12, tag.End); Assert.AreEqual("World", tag.Tag); }
private static CommandDefinitionModel BuildModel(InputDtoClassLocator locator) { var model = new CommandDefinitionModel(); // set the class name to create the command with var className = locator.InputDtoName.Replace("InputDTO", "Command"); model.ClassName = className; // parse the input class var entityParser = new EntityParser(); var entityMetadata = entityParser.Parse(locator.InputDtoNode); model.InputMetadata = entityMetadata; return(model); }
public ScheduleItem(SchedulerJob job, UserViewModel user, IScheduler scheduler, IConfig config, IViewServiceRepository viewServices) : base(config, viewServices) { Job = job; User = user; Scheduler = scheduler; ViewServices = viewServices; Entities = new Entities { HashTagEntities = EntityParser.ExtractHashtags(job.Text), MediaEntities = new List <MediaEntity>(), SymbolEntities = new List <SymbolEntity>(), UrlEntities = new List <UrlEntity>(), UserMentionEntities = EntityParser.ExtractMentions(job.Text) }; }
public void HashtagAtStartIsCorrectlyExtracted() { // Arrange const string text = "#Hello World!"; // Act var hashtags = EntityParser.ExtractHashtags(text); // Assert Assert.AreEqual(1, hashtags.Count); var tag = hashtags.First(); Assert.AreEqual(0, tag.Start); Assert.AreEqual(6, tag.End); Assert.AreEqual("Hello", tag.Tag); }
public void MentionAtStartIsCorrectlyExtracted() { // Arrange const string text = "@username Hello"; // Act var mentions = EntityParser.ExtractMentions(text); // Assert Assert.AreEqual(1, mentions.Count); var m = mentions.First(); Assert.AreEqual(0, m.Start); Assert.AreEqual(9, m.End); Assert.AreEqual("username", m.ScreenName); }
public Parsers() { // Create inline parsers LineBreakParser = new LineBreakParser(); BacktickParser = new BacktickParser(); InlineCodeParser = new InlineCodeParser(); EscapedCharParser = new EscapedCharParser(); EntityParser = new EntityParser(); StrWithEntitiesParser = new StrWithEntitiesParser(this); EscapedStringParser = new EscapedStringParser(this); AutolinkParser = new AutolinkParser(this); AutolinkEmailParser = new AutolinkEmailParser(this); RawHtmlParser = new RawHtmlParser(); LinkLabelParser = new LinkLabelParser(this); LinkDestinationParser = new LinkDestinationParser(this); LinkTitleParser = new LinkTitleParser(this); LinkReferenceParser = new LinkReferenceParser(this); LinkParser = new LinkParser(this); ImageParser = new ImageParser(this); ImageReferenceParser = new ImageReferenceParser(this); LinkDefinitionParser = new LinkDefinitionParser(this); EmphasisParser = new EmphasisParser(this); InlineParser = new InlineParser(this); CommonMarkInlineParser = new CommonMarkInlineParser(this); // Create block parsers IndentedCodeParser = new IndentedCodeParser(); LazyParagraphContinuationParser = new LazyParagraphContinuationParser(); BlockQuoteParser = new BlockQuoteParser(); ATXHeaderParser = new ATXHeaderParser(); FencedCodeParser = new FencedCodeParser(); HtmlBlockParser = new HtmlBlockParser(); SetExtHeaderParser = new SetExtHeaderParser(); HorizontalRuleParser = new HorizontalRuleParser(); ListParser = new ListParser(); }
public void findNullTextures () { //make a list of textures that need to be loaded from wad files TexInfoClass[] texinfo = new TexInfoClass[NumTexLoadFromWad]; //iterate miptexLump and add a TexInfoClass for each null texture we need to load int IndexOfTexinfo = 0; for (int j=0; j<miptexLump.Length; j++)//!!!!!!!!!! do this in the load miptexLump method instead!!!!!!!!!!!!!!!!!! { if (miptexLump [j].texture == null) { texinfo [IndexOfTexinfo] = new TexInfoClass (miptexLump [j].name, j); IndexOfTexinfo++; } } //next get the string of wads we need string[] wadFileNames; myParser = new EntityParser (entityLump.rawEntities); Dictionary<string, string> mylist = myParser.ReadEntity (); string tempString; if (mylist.ContainsKey ("wad")) { tempString = mylist ["wad"]; wadFileNames = tempString.Split (';'); for (int i =0; i<wadFileNames.Length; i++) { wadFileNames [i] = wadFileNames [i].Substring (wadFileNames [i].LastIndexOf ("\\") + 1);//remove unwanted text if (wadFileNames [i].Length > 3) { Debug.Log (wadFileNames [i].ToString ()); LoadTextureFromWad (wadFileNames [i], texinfo); } } } else { Debug.Log ("no textures to load from wad, or no wad key found in bsp"); } }