protected override void Context() { base.Context(); Sut = new FunctionSpecification <int>(i => i < 0); }
public async Task BuildSpecs() { //create function specs C# object FunctionSpecification functionSpecification = new FunctionSpecification(); functionSpecification.functionName = BuilderHelper.Instance.builderSettings.functionBodyFileName; foreach (var dllinfo in dllInfos) { //here is the tweak , as this path is based on execution directoy , thus choose the relative path string destinationFile = Path.Combine(BuilderHelper.Instance.builderSettings.DllDirectory, Path.GetFileName(dllinfo.path)).GetrelevantPathAsPerOS(); Library library = new Library() { name = dllinfo.name, nugetPackage = dllinfo.rootPackage, path = destinationFile }; functionSpecification.libraries.Add(library); } //serialize that object to save it in json file string funcMetaJson = JsonConvert.SerializeObject(functionSpecification); string funcMetaFile = Path.Combine(this.SRC_PKG, BuilderHelper.Instance.builderSettings.functionSpecFileName); BuilderHelper.Instance.WriteTofile(funcMetaFile, funcMetaJson); }
public void StaticMethodShouldReturnTheCorrectSpecification() { var passing = new FunctionSpecification <int>(i => i > 0); var failing = new FunctionSpecification <int>(i => i < 0); var sut = passing.Or(failing); sut.Should().BeOfType <OrSpecification <int> >(); }
public void WithAFailingSpecItShouldPass() { var specification = new FunctionSpecification<int>(i => i > 0); var sut = new NotSpecification<int>(specification); var result = sut.IsSatisfiedBy(1); result.Should().BeFalse(); }
public void WithAPassingSpecItShouldReturnAFail() { var specification = new FunctionSpecification<int>(i => i > 0); var sut = new NotSpecification<int>(specification); var result = sut.IsSatisfiedBy(0); result.Should().BeTrue(); }
public void ItShouldReturnAnAndSpecification() { var first = new FunctionSpecification<int>(i => i > 0); var second = new FunctionSpecification<int>(i => i > 0); var result = first.And(second).IsSatisfiedBy(1); result.Should().BeTrue(); }
public void ItShouldReturnAnAndSpecification() { var first = new FunctionSpecification <int>(i => i > 0); var second = new FunctionSpecification <int>(i => i > 0); var result = first.And(second).IsSatisfiedBy(1); result.Should().BeTrue(); }
public void WithAPassingSpecItShouldReturnAFail() { var specification = new FunctionSpecification <int>(i => i > 0); var sut = new NotSpecification <int>(specification); var result = sut.IsSatisfiedBy(0); result.Should().BeTrue(); }
public void WithAFailingSpecItShouldPass() { var specification = new FunctionSpecification <int>(i => i > 0); var sut = new NotSpecification <int>(specification); var result = sut.IsSatisfiedBy(1); result.Should().BeFalse(); }
public void StaticMethodShouldReturnTheCorrectSpecification() { var passing = new FunctionSpecification<int>(i => i > 0); var failing = new FunctionSpecification<int>(i => i < 0); var sut = passing.Or(failing); sut.Should().BeOfType<OrSpecification<int>>(); }
public void PassessWithTwoPassingSpecifications() { var passingSpec = new FunctionSpecification <int>(i => i > 0); const int testNumber = 1; var sut = new OrSpecification <int>(passingSpec, passingSpec); var result = sut.IsSatisfiedBy(testNumber); result.Should().BeTrue(); }
public void PassessWithTwoPassingSpecifications() { var passingSpec = new FunctionSpecification<int>(i => i > 0); const int testNumber = 1; var sut = new OrSpecification<int>(passingSpec, passingSpec); var result = sut.IsSatisfiedBy(testNumber); result.Should().BeTrue(); }
public void FailsTwoFailingSpecifications() { const int testNumber = 1; var failingSpec = new FunctionSpecification<int>(i => i < 0); var sut = new OrSpecification<int>(failingSpec, failingSpec); var result = sut.IsSatisfiedBy(testNumber); result.Should().BeFalse(); }
public void PassesWithOnePassingSpec() { const int testNumber = 1; var passingSpec = new FunctionSpecification<int>(i => i > 0); var failingSpec = new FunctionSpecification<int>(i => i < 0); var result = (passingSpec | failingSpec).IsSatisfiedBy(testNumber); result.Should().BeTrue(); }
public void WithTwoFailingSpecsItShouldFail() { const int testNumber = 0; var passingSpec = new FunctionSpecification<int>(i => i > 0); var failingSpec = new FunctionSpecification<int>(i => i > 0); var result = (passingSpec & failingSpec).IsSatisfiedBy(testNumber); result.Should().BeFalse(); }
public void FailsTwoFailingSpecifications() { const int testNumber = 1; var failingSpec = new FunctionSpecification <int>(i => i < 0); var sut = new OrSpecification <int>(failingSpec, failingSpec); var result = sut.IsSatisfiedBy(testNumber); result.Should().BeFalse(); }
private void button1_Click(object sender, EventArgs e) { FunctionSpecification fs = new FunctionSpecification(txtFunctionSpecification.Text); StringBuilder sb = new StringBuilder(); sb.AppendLine(fs.GenerateInputFunction()); sb.AppendLine(fs.GenerateOutputFunction()); sb.AppendLine(fs.GenerateMainFunction()); txtResult.Text = sb.ToString(); }
public void WithTwoFailingSpecsItShouldFail() { const int testNumber = 0; var passingSpec = new FunctionSpecification <int>(i => i > 0); var failingSpec = new FunctionSpecification <int>(i => i > 0); var result = (passingSpec & failingSpec).IsSatisfiedBy(testNumber); result.Should().BeFalse(); }
public void PassesWithOnePassingSpec() { const int testNumber = 1; var passingSpec = new FunctionSpecification <int>(i => i > 0); var failingSpec = new FunctionSpecification <int>(i => i < 0); var result = (passingSpec | failingSpec).IsSatisfiedBy(testNumber); result.Should().BeTrue(); }
public Function Compilev2(string code, out List <string> errors, out List <string> oinfo) { errors = new List <string>(); oinfo = new List <string>(); #region syntext tree and default reference build SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(code); string assemblyName = Path.GetRandomFileName(); var coreDir = Directory.GetParent(typeof(Enumerable).GetTypeInfo().Assembly.Location); Console.WriteLine("Adding core references !!"); List <MetadataReference> references = new List <MetadataReference> { MetadataReference.CreateFromFile(coreDir.FullName + Path.DirectorySeparatorChar + "mscorlib.dll"), MetadataReference.CreateFromFile(coreDir.FullName + Path.DirectorySeparatorChar + "netstandard.dll"), MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location), MetadataReference.CreateFromFile(Assembly.GetEntryAssembly().Location), MetadataReference.CreateFromFile(typeof(System.Runtime.Serialization.Json.DataContractJsonSerializer).GetTypeInfo().Assembly.Location) }; Console.WriteLine("Adding parent assembly based references !!"); foreach (var referencedAssembly in Assembly.GetEntryAssembly().GetReferencedAssemblies()) { var assembly = Assembly.Load(referencedAssembly); references.Add(MetadataReference.CreateFromFile(assembly.Location)); } #endregion #region load function specs based dlls Console.WriteLine($"going to get function specification..."); //load all available dlls from deployment folder in dllinfo object functionSpecification = EnvironmentHelper.Instance.GetFunctionSpecs(packagepath); Console.WriteLine($"going to get package dlls..."); //iterate and all all libraries mentioned foreach (var library in functionSpecification.libraries) { string dllCompletePath = Path.Combine(packagepath, library.path).GetrelevantPathAsPerOS(); references.Add(MetadataReference.CreateFromFile(dllCompletePath)); Console.WriteLine($"referred folder based dll : {dllCompletePath} from package {library.nugetPackage}"); } Console.WriteLine($"referred all available dlls!!"); oinfo.Add("referred all available dlls!!"); #endregion #region dynamic resolve handler registration AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; #endregion #region function compile Console.WriteLine($"Trying to Compile"); CSharpCompilation compilation = CSharpCompilation.Create( assemblyName, syntaxTrees: new[] { syntaxTree }, references: references, options: new CSharpCompilationOptions( OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release)); using (var ms = new MemoryStream()) { EmitResult result = compilation.Emit(ms); if (!result.Success) { Console.WriteLine($"Compile Failed , see pod logs for more details"); IEnumerable <Diagnostic> failures = result.Diagnostics.Where(diagnostic => diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error).ToList(); foreach (Diagnostic diagnostic in failures) { errors.Add($"{diagnostic.Id}: {diagnostic.GetMessage()}"); Console.WriteLine($"COMPILE ERROR :{diagnostic.Id}: {diagnostic.GetMessage()}", "ERROR"); } } else { oinfo.Add("COMPILE SUCCESS!!"); Console.WriteLine($"COMPILE SUCCESS!!"); ms.Seek(0, SeekOrigin.Begin); Assembly assembly = AssemblyLoadContext.Default.LoadFromStream(ms); //var type = assembly.GetType("FissionFunction"); //support for Namespace , as well as backward compatibility for existing functions var type = assembly.GetTypes().FirstOrDefault(x => x.Name.EndsWith("FissionFunction")); //assembly.GetTypes().Where(x=>x.Name.ToLower().EndsWith("FissionFunction".ToLower())).FirstOrDefault(); var info = type.GetMember("Execute").First() as MethodInfo; return(new Function(assembly, type, info)); } } return(null); #endregion }
public void ItShouldReturnTheCorrectSpecification() { var specification = new FunctionSpecification <int>(i => i > 0); specification.Not().IsSatisfiedBy(1).Should().BeFalse(); }
private void button1_Click(object sender, EventArgs e) { FunctionSpecification fs = new FunctionSpecification(txtText.Text); txtResult.Text = fs.GenerateInputFunction(); }
protected override void Context() { base.Context(); Sut = new FunctionSpecification<int>(i => i < 0); }
public void ItShouldReturnTheCorrectSpecification() { var specification = new FunctionSpecification<int>(i => i > 0); specification.Not().IsSatisfiedBy(1).Should().BeFalse(); }
public string ParseFomular(List <FunctionSpecification> sourceFuncSpecs, List <FunctionSpecification> targetFuncSpecs, FunctionFomular fomular, MappingFunctionInfo targetFunctionInfo, out Dictionary <string, string> dictDataType) { dictDataType = new Dictionary <string, string>(); string name = fomular.Name; FunctionSpecification sourceFuncSpec = sourceFuncSpecs.FirstOrDefault(item => item.Name.ToUpper() == name.ToUpper()); FunctionSpecification targetFuncSpec = targetFuncSpecs.FirstOrDefault(item => item.Name.ToUpper() == targetFunctionInfo.Name.ToUpper()); string newExpression = fomular.Expression; if (sourceFuncSpec != null && targetFuncSpec != null) { string delimiter = sourceFuncSpec.Delimiter == "," ? "," : $" {sourceFuncSpec.Delimiter} "; fomular.Delimiter = delimiter; List <string> fomularArgs = fomular.Args; int fetchCount = string.IsNullOrEmpty(targetFunctionInfo.Args) ? fomularArgs.Count : -1; Dictionary <int, string> sourceTokens = this.GetFunctionArgumentTokens(sourceFuncSpec, null, fetchCount); Dictionary <int, string> targetTokens = this.GetFunctionArgumentTokens(targetFuncSpec, targetFunctionInfo.Args, fetchCount); bool ignore = false; if (fomularArgs.Count > 0 && (targetTokens.Count == 0 || sourceTokens.Count == 0)) { ignore = true; } if (!ignore) { List <string> args = new List <string>(); foreach (var kp in targetTokens) { int targetIndex = kp.Key; string token = kp.Value; if (sourceTokens.ContainsValue(token)) { int sourceIndex = sourceTokens.FirstOrDefault(item => item.Value == token).Key; if (fomularArgs.Count > sourceIndex) { string oldArg = fomular.Args[sourceIndex]; string newArg = oldArg; switch (token.ToUpper()) { case "TYPE": if (!dictDataType.ContainsKey(oldArg)) { newArg = this.GetNewDataType(this.dataTypeMappings, oldArg); dictDataType.Add(oldArg, newArg.Trim()); } else { newArg = dictDataType[oldArg]; } break; } args.Add(newArg); } } else if (!string.IsNullOrEmpty(targetFunctionInfo.Args)) { args.Add(token); } } string targetDelimiter = targetFuncSpec.Delimiter == "," ? "," : $" {targetFuncSpec.Delimiter} "; string strArgs = string.Join(targetDelimiter, args); newExpression = $"{targetFunctionInfo.Name}{ (targetFuncSpec.NoParenthesess ? "" : $"({strArgs})") }"; } }