public void Test() { ISourceMapper <Student, Person> mapper1 = FactoryMapper.DynamicResolutionMapper <Student, Person>(); ISourceMapper mapper2 = FactoryMapper.DynamicResolutionMapper(typeof(PersonaGiuridica), typeof(PersonDetails)); ISourceMapper mapper3 = FactoryMapper.DynamicResolutionMapper(typeof(IPersonHeader), typeof(PersonDetails)); IList <IPropertyMapper <Student, Person> > propMappers = new List <IPropertyMapper <Student, Person> > { new PropertyMapper <Student, Person>((student, person) => person.Name = student.Name, "Name", "Name") , new PropertyMapper <Student, Person>((student, person) => person.AnnoNascita = student.AnnoNascita) , new PropertyMapper <Student, Person>((student, person) => person.Parent = student.Father) }; SourceMapper <Student, Person> mapper4 = new SourceMapper <Student, Person>(propMappers, null, null); StudentDetails example = new StudentDetails(); ServiceTransformer <ISourceMapper <Student, Person> > srv1 = new ServiceTransformer <ISourceMapper <Student, Person> >("default", mapper4); var res1 = srv1.Match <ISourceMapper <Student, Person> >("default"); var res2 = srv1.Match <SourceMapper <Student, Person> >("default"); var res3 = srv1.Match <ISourceMapper <Student, Person> >("ss"); var res4 = srv1.Match <SourceMapper <Student, Person> >("ss"); var res5 = srv1.Match("default", example.GetType(), typeof(Person)); Assert.IsTrue(res1); Assert.IsFalse(res2); Assert.IsFalse(res3); Assert.IsFalse(res4); Assert.IsTrue(res5); }
public void TestReferenceProperty() { IList <IPropertyMapper <Student, Person> > propMappers = new List <IPropertyMapper <Student, Person> > { new PropertyMapper <Student, Person>((student, person) => person.Name = student.Name, "Name", "Name") , new PropertyMapper <Student, Person>((student, person) => person.AnnoNascita = student.AnnoNascita) , new PropertyMapper <Student, Person>((student, person) => person.Parent = student.Father) }; ISourceMapper <Student, Person> mapper = new SourceMapper <Student, Person>(propMappers, null, null); Student st = new Student { Name = "mario", Surname = "monti", AnnoNascita = 1990, Father = new PersonaGiuridica { Name = "father", Surname = "father_surname", AnnoNascita = 1970, Code = "nick" } }; Person pr = mapper.Map(st); Assert.AreEqual(st.Name, pr.Name); Assert.AreNotEqual(st.Surname, pr.Surname); Assert.AreEqual(st.AnnoNascita, pr.AnnoNascita); Assert.AreEqual(st.Father, pr.Parent); Assert.AreSame(st.Father, pr.Parent); Assert.AreEqual(st.Father.GetType(), pr.Parent.GetType()); }
public void RegisterMapperTest3() { TransformerObserver observer = new TransformerObserver(); IList <IPropertyMapper <Student, Person> > propMappers = new List <IPropertyMapper <Student, Person> > { new PropertyMapper <Student, Person>((student, person) => person.Name = student.Name, "Name", "Name") , new PropertyMapper <Student, Person>((student, person) => person.AnnoNascita = student.AnnoNascita) , new PropertyMapper <Student, Person>((student, person) => person.Parent = student.Father) }; ISourceMapper mapper1 = new SourceMapper <Student, Person>(propMappers, null, null); ISourceMapper <Student, Person> mapper2 = new SourceMapper <Student, Person>(propMappers, null, null); Assert.IsTrue(observer.BuildAutoResolverMapper <User, UserDto>(null, null)); //register a mapper which transfomr User into UserDto (1) Assert.IsTrue(observer.BuildAutoResolverMapper <Student, Person>(null, null)); //register a mapper which transfomr Student into Person (1) Assert.IsFalse(observer.RegisterMapper(mapper1)); // this mapper cannot be registered 'cause It was registered another similar mapper ( as (1) ) Assert.IsFalse(observer.RegisterMapper(mapper2)); // this mapper cannot be registered 'cause It was registered another similar mapper ( as (1) ) Assert.IsFalse(observer.BuildAutoResolverMapper <User, UserDto>(null, null)); //It's equals to mapper (1), so It cannot be registered. Assert.IsFalse(observer.BuildAutoResolverMapper <User, UserDto>(null, Console.WriteLine)); //It's similar to mapper (2), so It cannot be registered. Assert.IsTrue(observer.RegisterMapper(mapper1, KeyService.Type1)); // this mapper can be registered 'cause It was registered with another KeyService nevertheless using a similar mapper ( as (1) ) Assert.IsFalse(observer.RegisterMapper(mapper2, KeyService.Type1)); // this mapper cannot be registered 'cause It was registered another similar mapper ( as (1) ), using the same serviceKey like a previous registration. }
//Non-Startup private void SourceAdded(SourceDto source) { Device.BeginInvokeOnMainThread(() => { this._profile.Sources.Add(SourceMapper.GetMcSourceFromDtoSource(source)); }); }
//[Test] public void TestReflection() { TransformerObserver a = new TransformerObserver(); ITransformerResolver aa = a; ISourceMapper <Person, PersonaGiuridica> mapper0 = FactoryMapper.DynamicResolutionMapper <Person, PersonaGiuridica>(); SourceMapper <Person, PersonaGiuridica> mapper = new SourceMapper <Person, PersonaGiuridica>(new List <IPropertyMapper <Person, PersonaGiuridica> >(), null, null); //aa.Register<ISourceMapper<Person, PersonaGiuridica>>(mapper); //aa.Register(mapper0); object obj1 = new Person(); object obj2 = new Person(); Type t1 = typeof(IPersonHeader); Type t2 = typeof(Person); try { object instance = 5.5; //int i = (int) instance; byte bb = Convert.ToByte(instance); byte b = (byte)instance; double d = (double)instance; } catch (Exception) { Assert.IsFalse(true, "Cast invalid"); } Compare <IPersonHeader>(obj1, obj2); //Compare<long>(1, 10); }
public void RegisterMapperTest1() { TransformerObserver observer = new TransformerObserver(); IList <IPropertyMapper <Student, Person> > propMappers = new List <IPropertyMapper <Student, Person> > { new PropertyMapper <Student, Person>((student, person) => person.Name = student.Name, "Name", "Name") , new PropertyMapper <Student, Person>((student, person) => person.AnnoNascita = student.AnnoNascita) , new PropertyMapper <Student, Person>((student, person) => person.Parent = student.Father) }; SourceMapper <Student, Person> mapper1 = new SourceMapper <Student, Person>(propMappers, null, null); observer.RegisterMapper(mapper1); Student st = new Student { Name = "mario", Surname = "monti", AnnoNascita = 19 }; StudentDetails st2 = new StudentDetails { Name = "mario", Surname = "monti", AnnoNascita = 19, CF = "CF" }; var res = observer.TryToMap <Student, Person>(st); var res2 = observer.TryToMap <Student, Person>(st2); Assert.IsNotNull(res); Assert.IsNotNull(res2); }
public void TestMapToOriginal() { var mapper = new SourceMapper(); var mapInfo = mapper.MapToOriginal(TestData.GetPath(@"TestData\DebuggerProject\TypeScriptTest.js"), 1, 0); Assert.AreEqual("TypeScriptTest.ts", mapInfo.FileName); }
public void RequestSources() { using (var context = new ExodusPrototype1Entities()) { Clients.Caller.ReceivedSources(SourceMapper.GetDtoSourceListFromEntSourceList(context.Sources)); } }
public MatchyBackend.Cv mapToService(Cv cv) { var eduMapper = new EducationMapper(); var sourceMapper = new SourceMapper(); MatchyBackend.Cv result = new MatchyBackend.Cv(); if (cv != null) { return new MatchyBackend.Cv() { Name = cv.Name, CvID = cv.CvID, Age = cv.Age, Sex = cv.Sex, Interests = cv.Interests, Personal = cv.Personal, City = cv.City, Date = cv.Date, Discipline = cv.Discipline, EducationHistory = cv.EducationHistory, EducationLevel = eduMapper.MapToService(cv.EducationLevel), Hours = cv.Hours, Profession = cv.Profession, Province = cv.Province, Email = cv.Email, JobRequirements = cv.JobRequirements, WorkExperience = cv.WorkExperience, Source = sourceMapper.MapToService(cv.Source) }; } else return result; }
public void TryProcessStartupCache() { //If we've already processed the startup cache, we don't need to. if (this._startupCacheProcessed) { return; } //If the startup cache does not contain all the necessary data, we can't process it yet. if ((this._startupCache.ContainsKey(StartupCacheKey.Sources) && this._startupCache.ContainsKey(StartupCacheKey.SourceInstances) && this._startupCache.ContainsKey(StartupCacheKey.DigitalWalls) && this._startupCache.ContainsKey(StartupCacheKey.SpaceSessions)) == false) { return; } Device.BeginInvokeOnMainThread(() => { this._profile.Sources = SourceMapper.GetMcSourceListFromDtoSourceList((IEnumerable <SourceDto>) this._startupCache[StartupCacheKey.Sources]); var sourceInstances = SourceInstanceMapper.GetMcSourceInstanceListFromMcSourceListAndDtoSourceInstanceList(this._profile.Sources, (IEnumerable <SourceInstanceDto>) this._startupCache[StartupCacheKey.SourceInstances]); this._profile.DigitalWalls = DigitalWallMapper.GetMcDigitalWallListFromDtoDigitalWallList(sourceInstances, (IEnumerable <DigitalWallDto>) this._startupCache[StartupCacheKey.DigitalWalls]); this._profile.SpaceSessions = SpaceSessionMapper.GetMcSpaceSessionListFromMcDigitalWallListAndDtoSpaceSessionList(this._profile.DigitalWalls, (IEnumerable <SpaceSessionDto>) this._startupCache[StartupCacheKey.SpaceSessions]); }); this._startupCacheProcessed = true; }
public void TryProcessStartupCache() { //If we've already processed the startup cache, we don't need to. if (this._startupCacheProcessed) { return; } //If the startup cache does not contain all the necessary data, we can't process it yet. if ((this._startupCache.ContainsKey(StartupCacheKey.Sources) && this._startupCache.ContainsKey(StartupCacheKey.SourceInstances) && this._startupCache.ContainsKey(StartupCacheKey.DigitalWalls) && this._startupCache.ContainsKey(StartupCacheKey.SpaceSessions)) == false) { return; } var context = SynchronizationContext.Current; App.Current.Dispatcher.Invoke((Action) delegate { this._profile.Sources = SourceMapper.GetDcSourceListFromDtoSourceList((IEnumerable <SourceDto>) this._startupCache[StartupCacheKey.Sources]); var sourceInstances = SourceInstanceMapper.GetDcSourceInstanceListFromDcSourceListAndDtoSourceInstanceList(this._profile.Sources, (IEnumerable <SourceInstanceDto>) this._startupCache[StartupCacheKey.SourceInstances]); this._profile.DigitalWalls = DigitalWallMapper.GetDcDigitalWallListFromDtoDigitalWallList(sourceInstances, (IEnumerable <DigitalWallDto>) this._startupCache[StartupCacheKey.DigitalWalls]); this._profile.SpaceSessions = SpaceSessionMapper.GetDcSpaceSessionListFromDcDigitalWallListAndDtoSpaceSessionList(this._profile.DigitalWalls, (IEnumerable <SpaceSessionDto>) this._startupCache[StartupCacheKey.SpaceSessions]); }); this._startupCacheProcessed = true; }
public void DiscoverTests(IEnumerable <string> fileList, TestFramework testFx, IMessageLogger logger, ITestCaseDiscoverySink discoverySink, string testDiscovererName) { // If it's a framework name we support, is safe to submit the string to telemetry. var testAdapterName = Enum.GetNames(typeof(SupportedFramework)).Contains(testFx.Name, StringComparer.OrdinalIgnoreCase) ? testFx.Name : "Other"; TelemetryHelper.LogTestDiscoveryStarted(testAdapterName, testDiscovererName); if (!File.Exists(this.nodeExePath)) { logger.SendMessage(TestMessageLevel.Error, "Node.exe was not found. Please install Node.js before running tests."); return; } var files = string.Join(";", fileList); logger.SendMessage(TestMessageLevel.Informational, $"Processing: {files}"); var discoveredTestCases = testFx.FindTests(fileList, this.nodeExePath, logger, projectRoot: this.workingDir); if (!discoveredTestCases.Any()) { logger.SendMessage(TestMessageLevel.Warning, "Discovered 0 test cases."); return; } foreach (var discoveredTest in discoveredTestCases) { var qualifiedName = discoveredTest.FullyQualifiedName; const string indent = " "; logger.SendMessage(TestMessageLevel.Informational, $"{indent}Creating Test Case:{qualifiedName}"); //figure out the test source info such as line number var filePath = CommonUtils.GetAbsoluteFilePath(this.workingDir, discoveredTest.TestFile); // We try to map every time, so we work with .ts files and post-processed js files. var fi = SourceMapper.MaybeMap(new FunctionInformation(string.Empty, discoveredTest.TestName, discoveredTest.SourceLine, filePath)); var testCase = new TestCase(qualifiedName, NodejsConstants.ExecutorUri, this.testSource) { CodeFilePath = fi?.Filename ?? filePath, LineNumber = fi?.LineNumber ?? discoveredTest.SourceLine, DisplayName = discoveredTest.TestName }; testCase.SetPropertyValue(JavaScriptTestCaseProperties.TestFramework, testFx.Name); testCase.SetPropertyValue(JavaScriptTestCaseProperties.WorkingDir, this.workingDir); testCase.SetPropertyValue(JavaScriptTestCaseProperties.ProjectRootDir, this.workingDir); testCase.SetPropertyValue(JavaScriptTestCaseProperties.NodeExePath, this.nodeExePath); testCase.SetPropertyValue(JavaScriptTestCaseProperties.TestFile, filePath); testCase.SetPropertyValue(JavaScriptTestCaseProperties.ConfigDirPath, discoveredTest.ConfigDirPath); discoverySink.SendTestCase(testCase); } logger.SendMessage(TestMessageLevel.Informational, $"Processing finished for framework '{testFx.Name}'."); }
public void TestMapToJavaScript() { var mapper = new SourceMapper(); string fileName; int lineNo, columnNo; Assert.IsTrue(mapper.MapToJavaScript(TestData.GetPath(@"TestData\DebuggerProject\TypeScriptTest.ts"), 1, 0, out fileName, out lineNo, out columnNo)); Assert.AreEqual(TestData.GetPath(@"TestData\DebuggerProject\TypeScriptTest.js"), fileName); }
public void GetOriginalFileNameWithStackFrame() { string javaScriptFileName = TestData.GetPath(@"TestData\TypeScriptMultfile\all.js"); var sourceMapper = new SourceMapper(); int? line = 24, column = 9; string originalFileName = sourceMapper.GetOriginalFileName(javaScriptFileName, line, column); Assert.IsTrue(originalFileName.Contains("file2.ts")); }
//Non-Startup private void SourceAdded(SourceDto source) { var context = SynchronizationContext.Current; App.Current.Dispatcher.Invoke((Action) delegate { this._profile.Sources.Add(SourceMapper.GetDcSourceFromDtoSource(source)); }); }
/// <summary> /// Gets the position in the target JavaScript file using the provided SourceMapper. /// /// This translates the breakpoint from the location where the user set it (possibly /// a TypeScript file) into the location where it lives in JavaScript code. /// </summary> public FilePosition GetPosition(SourceMapper mapper) { if (mapper != null && mapper.MapToJavaScript(this.Target.FileName, this.Target.Line, this.Target.Column, out var javaScriptFileName, out var javaScriptLine, out var javaScriptColumn)) { return(new FilePosition(javaScriptFileName, javaScriptLine, javaScriptColumn)); } return(this.Target); }
public void NewServiceTransformer1() { IList<IPropertyMapper<Student, Person>> propMappers = new List<IPropertyMapper<Student, Person>> { new PropertyMapper<Student, Person>( (student, person) => person.Name = student.Name, "Name", "Name") ,new PropertyMapper<Student, Person>( (student, person) => person.AnnoNascita = student.AnnoNascita ) ,new PropertyMapper<Student, Person>( (student, person) => person.Parent = student.Father ) }; SourceMapper<Student, Person> mapper = new SourceMapper<Student, Person>(propMappers, null, null); new ServiceTransformer<ISourceMapper<Student, Person>>(null, mapper); }
public void NewServiceTransformer1() { IList <IPropertyMapper <Student, Person> > propMappers = new List <IPropertyMapper <Student, Person> > { new PropertyMapper <Student, Person>((student, person) => person.Name = student.Name, "Name", "Name") , new PropertyMapper <Student, Person>((student, person) => person.AnnoNascita = student.AnnoNascita) , new PropertyMapper <Student, Person>((student, person) => person.Parent = student.Father) }; SourceMapper <Student, Person> mapper = new SourceMapper <Student, Person>(propMappers, null, null); new ServiceTransformer <ISourceMapper <Student, Person> >(null, mapper); }
public int AddSource(Common.Data.Models.SourceDto newSource) { using (var context = new ExodusPrototype1Entities()) { var newSourceEnt = SourceMapper.GetEntSourceFromDtoSource(newSource); context.Sources.Add(newSourceEnt); context.SaveChanges(); Clients.All.SourceAdded(SourceMapper.GetDtoSourceFromEntSource(newSourceEnt)); this.WriteToWindowConsole($"Client: {Context.ConnectionId} - Added Source With Id: {newSourceEnt.Id} and Name: {newSourceEnt.Name}"); return(newSourceEnt.Id); } }
/// <summary> /// Gets the position in the target JavaScript file using the provided SourceMapper. /// /// This translates the breakpoint from the location where the user set it (possibly /// a TypeScript file) into the location where it lives in JavaScript code. /// </summary> public FilePosition GetPosition(SourceMapper mapper) { // Checks whether source map is available string javaScriptFileName; int javaScriptLine; int javaScriptColumn; if (mapper != null && mapper.MapToJavaScript(this.Target.FileName, this.Target.Line, this.Target.Column, out javaScriptFileName, out javaScriptLine, out javaScriptColumn)) { return(new FilePosition(javaScriptFileName, javaScriptLine, javaScriptColumn)); } return(this.Target); }
public void RegisterMapperTest2() { TransformerObserver observer = new TransformerObserver(); IList <IPropertyMapper <Student, Person> > propMappers = new List <IPropertyMapper <Student, Person> > { new PropertyMapper <Student, Person>((student, person) => person.Name = student.Name, "Name", "Name") , new PropertyMapper <Student, Person>((student, person) => person.AnnoNascita = student.AnnoNascita) , new PropertyMapper <Student, Person>((student, person) => person.Parent = student.Father) }; SourceMapper <Student, Person> mapper1 = new SourceMapper <Student, Person>(propMappers, null, null); Assert.IsTrue(observer.RegisterMapper(mapper1)); Assert.IsTrue(observer.RegisterMapper(mapper1, KeyService.Type1)); Assert.IsTrue(observer.RegisterMapper(mapper1, KeyService.Type2)); Assert.IsFalse(observer.RegisterMapper(mapper1)); Assert.IsFalse(observer.RegisterMapper(mapper1, "default")); Student st = new Student { Name = "mario", Surname = "monti", AnnoNascita = 19 }; var res1 = observer.TryToMap <Student, Person>(st); Assert.IsNotNull(res1); var res11 = observer.TryToMap(st, typeof(Person)); Assert.IsTrue(res11 is Person); Assert.IsNotNull(res11); var res2 = observer.TryToMap(st, typeof(Person), KeyService.Type1); Assert.IsNotNull(res2); var res22 = observer.TryToMap(st, typeof(Person), KeyService.Type1); Assert.IsNotNull(res22); var res0 = observer.TryToMap(st, typeof(Person), KeyService.Type3); Assert.IsNull(res0); var res00 = observer.TryToMap <Student, Person>(st, KeyService.Type3); Assert.IsNull(res00); }
public void TestCustomMapper() { IList<IPropertyMapper<Student, Person>> propMappers = new List<IPropertyMapper<Student, Person>> { new PropertyMapper<Student, Person>( (student, person) => person.Name = student.Name.ToUpper(), "Name", "Name") , new PropertyMapper<Student, Person>( (student, person) => person.AnnoNascita = student.AnnoNascita ) }; ISourceMapper<Student, Person> mapper = new SourceMapper<Student, Person>(propMappers, null, null); Student st = new Student { Name = "mario", Surname = "monti", AnnoNascita = 19 }; Person pr = mapper.Map(st); Assert.AreEqual(st.Name.ToUpper(), pr.Name, "Property [Name] was not set."); Assert.AreNotEqual(st.Surname.ToUpper(), pr.Surname); Assert.AreEqual(st.AnnoNascita, pr.AnnoNascita); }
public void TestCustomMapper() { IList <IPropertyMapper <Student, Person> > propMappers = new List <IPropertyMapper <Student, Person> > { new PropertyMapper <Student, Person>((student, person) => person.Name = student.Name.ToUpper(), "Name", "Name") , new PropertyMapper <Student, Person>((student, person) => person.AnnoNascita = student.AnnoNascita) }; ISourceMapper <Student, Person> mapper = new SourceMapper <Student, Person>(propMappers, null, null); Student st = new Student { Name = "mario", Surname = "monti", AnnoNascita = 19 }; Person pr = mapper.Map(st); Assert.AreEqual(st.Name.ToUpper(), pr.Name, "Property [Name] was not set."); Assert.AreNotEqual(st.Surname.ToUpper(), pr.Surname); Assert.AreEqual(st.AnnoNascita, pr.AnnoNascita); }
public void TryProcessStartupCache() { //If we've already processed the startup cache, we don't need to. if (this._startupCacheProcessed) { return; } //If the startup cache does not contain all the necessary data, we can't process it yet. if ((this._startupCache.ContainsKey(StartupCacheKey.Sources) && this._startupCache.ContainsKey(StartupCacheKey.SourceInstances) && this._startupCache.ContainsKey(StartupCacheKey.DigitalWalls) && this._startupCache.ContainsKey(StartupCacheKey.SpaceSessions)) == false) { return; } this._unityMainThreadDispatcher.Enqueue(() => { this._profile.Sources = SourceMapper.GetUcSourceListFromDtoSourceList((IEnumerable <SourceDto>) this._startupCache[StartupCacheKey.Sources]); var sourceInstances = SourceInstanceMapper.GetUcSourceInstanceListFromUcSourceListAndDtoSourceInstanceList(this._profile.Sources, (IEnumerable <SourceInstanceDto>) this._startupCache[StartupCacheKey.SourceInstances], this._commonValues.PixelToUnityUnitScale, this._unityMainThreadDispatcher); this._profile.DigitalWalls = DigitalWallMapper.GetUcDigitalWallListFromDtoDigitalWallList(sourceInstances, (IEnumerable <DigitalWallDto>) this._startupCache[StartupCacheKey.DigitalWalls], this._commonValues.PixelToUnityUnitScale, this._commonValues.WallCenter, this._unityMainThreadDispatcher); this._profile.SpaceSessions = SpaceSessionMapper.GetUcSpaceSessionListFromUcDigitalWallListAndDtoSpaceSessionList(this._profile.DigitalWalls, (IEnumerable <SpaceSessionDto>) this._startupCache[StartupCacheKey.SpaceSessions]); //If we have any digital walls, render the first. UcDigitalWall firstWall = this._profile.DigitalWalls.FirstOrDefault(); if (firstWall != null) { firstWall.Render(); this._profile.SelectedWall = firstWall; } }); this._startupCacheProcessed = true; }
internal static FunctionInformation ExtractNamespaceAndMethodName(string location, bool isRecompilation, string type = "LazyCompile", Dictionary <string, SourceMap> sourceMaps = null) { string fileName = null; string moduleName = ""; string methodName = location; List <int> pos = null; if (location.Length >= 2 && location.StartsWith("\"") && location.EndsWith("\"")) { // v8 usually includes quotes, strip them location = location.Substring(1, location.Length - 2); } int firstSpace; if (type == "Script" || type == "Function") { // code-creation,Function,0xf1c38300,1928," assert.js:1",0xa6d4df58,~ // code-creation,Script,0xf1c38aa0,244,"assert.js",0xa6d4e050,~ // code-creation,Script,0xf1c141c0,844,"native runtime.js",0xa6d1aa98,~ // this is a top level script or module, report it as such methodName = _topLevelModule; if (type == "Function") { location = location.Substring(location.IndexOf(' ') + 1); } ParseLocation(location, out fileName, out moduleName, out pos); pos = new List <int> { 1 }; } else { // " net.js:931" // "func C:\Source\NodeApp2\NodeApp2\server.js:5" // " C:\Source\NodeApp2\NodeApp2\server.js:16" firstSpace = FirstSpace(location); if (firstSpace != -1) { if (firstSpace == 0) { methodName = "anonymous method"; } else { methodName = location.Substring(0, firstSpace); } location = location.Substring(firstSpace + 1); ParseLocation(location, out fileName, out moduleName, out pos); } } var lineNo = pos == null ? null : pos.Select(x => (int?)x).FirstOrDefault(); return(SourceMapper.MaybeMap(new FunctionInformation(moduleName, methodName, lineNo, fileName, isRecompilation), sourceMaps)); }
private void DiscoverTests(Dictionary <string, List <TestFileEntry> > testItems, MSBuild.Project proj, ITestCaseDiscoverySink discoverySink, IMessageLogger logger) { var result = new List <TestFrameworks.NodejsTestInfo>(); var projectHome = Path.GetFullPath(Path.Combine(proj.DirectoryPath, ".")); var projSource = proj.FullPath; var nodeExePath = Nodejs.GetAbsoluteNodeExePath( projectHome, proj.GetPropertyValue(NodeProjectProperty.NodeExePath)); if (!File.Exists(nodeExePath)) { logger.SendMessage(TestMessageLevel.Error, string.Format(CultureInfo.CurrentCulture, "Node.exe was not found. Please install Node.js before running tests.")); return; } var testCount = 0; foreach (var testFx in testItems.Keys) { var testFramework = GetTestFrameworkObject(testFx); if (testFramework == null) { logger.SendMessage(TestMessageLevel.Warning, string.Format(CultureInfo.CurrentCulture, "Ignoring unsupported test framework {0}", testFx)); continue; } var fileList = testItems[testFx]; var files = string.Join(";", fileList.Select(p => p.File)); logger.SendMessage(TestMessageLevel.Informational, string.Format(CultureInfo.CurrentCulture, "Processing: {0}", files)); var discoveredTestCases = testFramework.FindTests(fileList.Select(p => p.File), nodeExePath, logger, projectHome); testCount += discoveredTestCases.Count; foreach (var discoveredTest in discoveredTestCases) { var qualifiedName = discoveredTest.FullyQualifiedName; logger.SendMessage(TestMessageLevel.Informational, string.Format(CultureInfo.CurrentCulture, " " /*indent*/ + "Creating TestCase:{0}", qualifiedName)); //figure out the test source info such as line number var filePath = discoveredTest.ModulePath; var entry = fileList.Find(p => p.File.Equals(filePath, StringComparison.OrdinalIgnoreCase)); FunctionInformation fi = null; if (entry.IsTypeScriptTest) { fi = SourceMapper.MaybeMap(new FunctionInformation(string.Empty, discoveredTest.TestName, discoveredTest.SourceLine, entry.File)); } discoverySink.SendTestCase( new TestCase(qualifiedName, TestExecutor.ExecutorUri, projSource) { CodeFilePath = (fi != null) ? fi.Filename : filePath, LineNumber = (fi != null && fi.LineNumber.HasValue) ? fi.LineNumber.Value : discoveredTest.SourceLine, DisplayName = discoveredTest.TestName }); } logger.SendMessage(TestMessageLevel.Informational, string.Format(CultureInfo.CurrentCulture, "Processing finished for framework of {0}", testFx)); } if (testCount == 0) { logger.SendMessage(TestMessageLevel.Warning, string.Format(CultureInfo.CurrentCulture, "Discovered 0 testcases.")); } }
public SetBreakpointCommand(int id, NodeModule module, NodeBreakpoint breakpoint, bool withoutPredicate, bool remote, SourceMapper sourceMapper = null) : base(id, "setbreakpoint") { Utilities.ArgumentNotNull("breakpoint", breakpoint); _module = module; _breakpoint = breakpoint; _sourceMapper = sourceMapper; _position = breakpoint.GetPosition(_sourceMapper); // Zero based line numbers int line = _position.Line; // Zero based column numbers // Special case column to avoid (line 0, column 0) which // Node (V8) treats specially for script loaded via require // Script wrapping process: https://github.com/joyent/node/blob/v0.10.26-release/src/node.js#L880 int column = _position.Column; if (line == 0) { column += NodeConstants.ScriptWrapBegin.Length; } _arguments = new Dictionary <string, object> { { "line", line }, { "column", column } }; if (_module != null) { _arguments["type"] = "scriptId"; _arguments["target"] = _module.Id; } else if (remote) { _arguments["type"] = "scriptRegExp"; _arguments["target"] = GetCaseInsensitiveRegex(_position.FileName); } else { _arguments["type"] = "script"; _arguments["target"] = _position.FileName; } if (!NodeBreakpointBinding.GetEngineEnabled(_breakpoint.Enabled, _breakpoint.BreakOn, 0)) { _arguments["enabled"] = false; } if (withoutPredicate) { return; } int ignoreCount = NodeBreakpointBinding.GetEngineIgnoreCount(_breakpoint.BreakOn, 0); if (ignoreCount > 0) { _arguments["ignoreCount"] = ignoreCount; } if (!string.IsNullOrEmpty(_breakpoint.Condition)) { _arguments["condition"] = _breakpoint.Condition; } }
public void RegisterMapperTest1() { TransformerObserver observer = new TransformerObserver(); IList<IPropertyMapper<Student, Person>> propMappers = new List<IPropertyMapper<Student, Person>> { new PropertyMapper<Student, Person>( (student, person) => person.Name = student.Name, "Name", "Name") ,new PropertyMapper<Student, Person>( (student, person) => person.AnnoNascita = student.AnnoNascita ) ,new PropertyMapper<Student, Person>( (student, person) => person.Parent = student.Father ) }; SourceMapper<Student, Person> mapper1 = new SourceMapper<Student, Person>(propMappers, null, null); observer.RegisterMapper(mapper1); Student st = new Student { Name = "mario", Surname = "monti", AnnoNascita = 19 }; StudentDetails st2 = new StudentDetails { Name = "mario", Surname = "monti", AnnoNascita = 19, CF = "CF"}; var res = observer.TryToMap<Student, Person>(st); var res2 = observer.TryToMap<Student, Person>(st2); Assert.IsNotNull(res); Assert.IsNotNull(res2); }
public async Task <int> AddSource(UcSource source) { int id = await HubProxy.Invoke <int>("AddSource", SourceMapper.GetDtoSourceFromUcSource(source)); return(id); }
private void DiscoverTests(Dictionary <string, HashSet <TestFileEntry> > testItems, MSBuild.Project proj, ITestCaseDiscoverySink discoverySink, IMessageLogger logger) { var result = new List <NodejsTestInfo>(); var projectHome = Path.GetFullPath(Path.Combine(proj.DirectoryPath, ".")); var projSource = proj.FullPath; var nodeExePath = Nodejs.GetAbsoluteNodeExePath( projectHome, proj.GetPropertyValue(NodeProjectProperty.NodeExePath)); if (!File.Exists(nodeExePath)) { logger.SendMessage(TestMessageLevel.Error, "Node.exe was not found. Please install Node.js before running tests."); return; } var testCount = 0; foreach (var testFx in testItems.Keys) { var testFramework = FrameworkDiscoverer.Instance.Get(testFx); if (testFramework == null) { logger.SendMessage(TestMessageLevel.Warning, $"Ignoring unsupported test framework '{testFx}'."); continue; } var fileList = testItems[testFx]; var files = string.Join(";", fileList.Select(p => p.FullPath)); logger.SendMessage(TestMessageLevel.Informational, string.Format(CultureInfo.CurrentCulture, "Processing: {0}", files)); var discoveredTestCases = testFramework.FindTests(fileList.Select(p => p.FullPath), nodeExePath, logger, projectRoot: projectHome); testCount += discoveredTestCases.Count(); foreach (var discoveredTest in discoveredTestCases) { var qualifiedName = discoveredTest.FullyQualifiedName; const string indent = " "; logger.SendMessage(TestMessageLevel.Informational, $"{indent}Creating TestCase:{qualifiedName}"); //figure out the test source info such as line number var filePath = discoveredTest.TestPath; var entry = fileList.First(p => StringComparer.OrdinalIgnoreCase.Equals(p.FullPath, filePath)); FunctionInformation fi = null; if (entry.IsTypeScriptTest) { fi = SourceMapper.MaybeMap(new FunctionInformation(string.Empty, discoveredTest.TestName, discoveredTest.SourceLine, entry.FullPath)); } var testcase = new TestCase(qualifiedName, NodejsConstants.ExecutorUri, projSource) { CodeFilePath = fi?.Filename ?? filePath, LineNumber = fi?.LineNumber ?? discoveredTest.SourceLine, DisplayName = discoveredTest.TestName }; testcase.SetPropertyValue(JavaScriptTestCaseProperties.TestFramework, testFx); testcase.SetPropertyValue(JavaScriptTestCaseProperties.NodeExePath, nodeExePath); testcase.SetPropertyValue(JavaScriptTestCaseProperties.ProjectRootDir, projectHome); testcase.SetPropertyValue(JavaScriptTestCaseProperties.WorkingDir, projectHome); testcase.SetPropertyValue(JavaScriptTestCaseProperties.TestFile, filePath); discoverySink.SendTestCase(testcase); } logger.SendMessage(TestMessageLevel.Informational, string.Format(CultureInfo.CurrentCulture, "Processing finished for framework '{0}'.", testFx)); } }
public void TestReferenceProperty() { IList<IPropertyMapper<Student, Person>> propMappers = new List<IPropertyMapper<Student, Person>> { new PropertyMapper<Student, Person>( (student, person) => person.Name = student.Name, "Name", "Name") ,new PropertyMapper<Student, Person>( (student, person) => person.AnnoNascita = student.AnnoNascita ) ,new PropertyMapper<Student, Person>( (student, person) => person.Parent = student.Father ) }; ISourceMapper<Student, Person> mapper = new SourceMapper<Student, Person>(propMappers, null, null); Student st = new Student { Name = "mario", Surname = "monti", AnnoNascita = 1990, Father = new PersonaGiuridica { Name = "father", Surname = "father_surname", AnnoNascita = 1970, Code = "nick"} }; Person pr = mapper.Map(st); Assert.AreEqual(st.Name, pr.Name); Assert.AreNotEqual(st.Surname, pr.Surname); Assert.AreEqual(st.AnnoNascita, pr.AnnoNascita); Assert.AreEqual(st.Father, pr.Parent); Assert.AreSame(st.Father, pr.Parent); Assert.AreEqual(st.Father.GetType(), pr.Parent.GetType()); }
//Non-Startup private void SourceAdded(SourceDto source) { this._unityMainThreadDispatcher.Enqueue(() => { this._profile.Sources.Add(SourceMapper.GetUcSourceFromDtoSource(source)); }); }
public void Test() { ISourceMapper<Student, Person> mapper1 = FactoryMapper.DynamicResolutionMapper<Student, Person>(); ISourceMapper mapper2 = FactoryMapper.DynamicResolutionMapper(typeof(PersonaGiuridica), typeof(PersonDetails)); ISourceMapper mapper3 = FactoryMapper.DynamicResolutionMapper(typeof(IPersonHeader), typeof(PersonDetails)); IList<IPropertyMapper<Student, Person>> propMappers = new List<IPropertyMapper<Student, Person>> { new PropertyMapper<Student, Person>( (student, person) => person.Name = student.Name, "Name", "Name") ,new PropertyMapper<Student, Person>( (student, person) => person.AnnoNascita = student.AnnoNascita ) ,new PropertyMapper<Student, Person>( (student, person) => person.Parent = student.Father ) }; SourceMapper<Student, Person> mapper4 = new SourceMapper<Student, Person>(propMappers, null, null); StudentDetails example = new StudentDetails(); ServiceTransformer<ISourceMapper<Student, Person>> srv1 = new ServiceTransformer<ISourceMapper<Student, Person>>("default", mapper4); var res1 = srv1.Match<ISourceMapper<Student, Person>>("default"); var res2 = srv1.Match<SourceMapper<Student, Person>>("default"); var res3 = srv1.Match<ISourceMapper<Student, Person>>("ss"); var res4 = srv1.Match<SourceMapper<Student, Person>>("ss"); var res5 = srv1.Match("default", example.GetType(), typeof(Person)); Assert.IsTrue(res1); Assert.IsFalse(res2); Assert.IsFalse(res3); Assert.IsFalse(res4); Assert.IsTrue(res5); }
public void RegisterMapperTest2() { TransformerObserver observer = new TransformerObserver(); IList<IPropertyMapper<Student, Person>> propMappers = new List<IPropertyMapper<Student, Person>> { new PropertyMapper<Student, Person>( (student, person) => person.Name = student.Name, "Name", "Name") ,new PropertyMapper<Student, Person>( (student, person) => person.AnnoNascita = student.AnnoNascita ) ,new PropertyMapper<Student, Person>( (student, person) => person.Parent = student.Father ) }; SourceMapper<Student, Person> mapper1 = new SourceMapper<Student, Person>(propMappers, null, null); Assert.IsTrue(observer.RegisterMapper(mapper1)); Assert.IsTrue(observer.RegisterMapper(mapper1, KeyService.Type1)); Assert.IsTrue(observer.RegisterMapper(mapper1, KeyService.Type2)); Assert.IsFalse(observer.RegisterMapper(mapper1)); Assert.IsFalse(observer.RegisterMapper(mapper1, "default")); Student st = new Student { Name = "mario", Surname = "monti", AnnoNascita = 19 }; var res1 = observer.TryToMap<Student, Person>(st); Assert.IsNotNull(res1); var res11 = observer.TryToMap(st, typeof(Person)); Assert.IsTrue(res11 is Person); Assert.IsNotNull(res11); var res2 = observer.TryToMap(st, typeof(Person), KeyService.Type1); Assert.IsNotNull(res2); var res22 = observer.TryToMap(st, typeof (Person), KeyService.Type1); Assert.IsNotNull(res22); var res0 = observer.TryToMap(st, typeof (Person), KeyService.Type3); Assert.IsNull(res0); var res00 = observer.TryToMap<Student, Person>(st, KeyService.Type3); Assert.IsNull(res00); }
public void RegisterMapperTest3() { TransformerObserver observer = new TransformerObserver(); IList<IPropertyMapper<Student, Person>> propMappers = new List<IPropertyMapper<Student, Person>> { new PropertyMapper<Student, Person>( (student, person) => person.Name = student.Name, "Name", "Name") ,new PropertyMapper<Student, Person>( (student, person) => person.AnnoNascita = student.AnnoNascita ) ,new PropertyMapper<Student, Person>( (student, person) => person.Parent = student.Father ) }; ISourceMapper mapper1 = new SourceMapper<Student, Person>(propMappers, null, null); ISourceMapper<Student, Person> mapper2 = new SourceMapper<Student, Person>(propMappers, null, null); Assert.IsTrue(observer.BuildAutoResolverMapper<User, UserDto>(null, null)); //register a mapper which transfomr User into UserDto (1) Assert.IsTrue(observer.BuildAutoResolverMapper<Student, Person>(null, null)); //register a mapper which transfomr Student into Person (1) Assert.IsFalse(observer.RegisterMapper(mapper1)); // this mapper cannot be registered 'cause It was registered another similar mapper ( as (1) ) Assert.IsFalse(observer.RegisterMapper(mapper2)); // this mapper cannot be registered 'cause It was registered another similar mapper ( as (1) ) Assert.IsFalse(observer.BuildAutoResolverMapper<User, UserDto>(null, null)); //It's equals to mapper (1), so It cannot be registered. Assert.IsFalse(observer.BuildAutoResolverMapper<User, UserDto>(null, Console.WriteLine)); //It's similar to mapper (2), so It cannot be registered. Assert.IsTrue(observer.RegisterMapper(mapper1, KeyService.Type1)); // this mapper can be registered 'cause It was registered with another KeyService nevertheless using a similar mapper ( as (1) ) Assert.IsFalse(observer.RegisterMapper(mapper2, KeyService.Type1)); // this mapper cannot be registered 'cause It was registered another similar mapper ( as (1) ), using the same serviceKey like a previous registration. }