static void Main(string[] args) { var codeFile = new CodeFile { DefinedInNamespace = "BlueprintTech.CodeGeneration.Test", UsingNamespaces = new[] { "System" }, ClassName = "ACodeGenerationTestClass", AccessModifiers = new[] { SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword }, Members = () => new[] { Methods.Header("Test", Types.Void) .WithModifiers(Tokens.StaticModifier) .WithBody( Invocations.Invoke("Console", "WriteLine", "Hello world!".AsLiteral().AsArgument()) .AsStatement().AsBlock()) } }; File.WriteAllText("ACodeGenerationTestClass.cs", codeFile.Definition()); }
public static ExecutionMode Parse(WordReader reader, uint wordCount) { var id = (Enumerant)reader.ReadWord(); switch (id) { case Enumerant.Invocations: return(Invocations.Parse(reader, wordCount - 1)); case Enumerant.LocalSize: return(LocalSize.Parse(reader, wordCount - 1)); case Enumerant.LocalSizeHint: return(LocalSizeHint.Parse(reader, wordCount - 1)); case Enumerant.OutputVertices: return(OutputVertices.Parse(reader, wordCount - 1)); case Enumerant.VecTypeHint: return(VecTypeHint.Parse(reader, wordCount - 1)); default: return(new ExecutionMode(id)); } }
public void TestRecordingSingleFieAndReadBack() { var testFile = GetFile(); var invocations = Invocations.CreateForTesting(5, testFile); Assert.False(File.Exists(testFile)); var recordDate = new DateTime(2222, 2, 2, 2, 2, 2, DateTimeKind.Utc); invocations.RecordInvocation(LoggingContext, CreateTestInvocation(1, recordDate)); Assert.True(File.Exists(testFile)); var lines = File.ReadAllLines(testFile); Assert.Equal(1, lines.Length); Assert.Equal("0\ts-1\t2222-02-02T02:02:02.0000000Z\tPrimaryConfigFile\tLogsFolder\tEngineVersion\tEngineBinFolder\tEngineCommitId", lines[0]); var allEntires = invocations.GetInvocations(LoggingContext); Assert.Equal(1, allEntires.Count); var entry = allEntires.First(); Assert.Equal(0, entry.LineVersion); Assert.Equal(recordDate, entry.BuildStartTimeUtc); Assert.Equal("PrimaryConfigFile", entry.PrimaryConfigFile); Assert.Equal("LogsFolder", entry.LogsFolder); Assert.Equal("EngineVersion", entry.EngineVersion); Assert.Equal("EngineBinFolder", entry.EngineBinFolder); Assert.Equal("EngineCommitId", entry.EngineCommitId); }
public void TestGetLatestInFaceOfErrors() { var testFile = GetFile(); File.WriteAllLines(testFile, new [] { "error", "0\ts-1\tBadTime\tConfig\tLogsFolder\tEngineVersion\tEngineBin\tEngineCommitId", "", // empty line "0\ts-2\t2018-08-15T19:35:50.1539252Z\tConfig\tEngineVersion\tOneColLess", "#\ts-x", // non numeric version number "0\ts-3\t2018-08-15T19:35:50.1539252Z\tConfig\tLogsFolder\tEngineVersion\tEngineBin\tEngineCommitId\tExtraCol", CreateTestInvocation(4).ToTsvLine(), CreateTestInvocation(5).ToTsvLine(), "99\ts-6\t2018-08-15T19:35:50.1539252Z\tConfig\tLogsFolder\tEngineVersion\tEngineBin\tEngineCommitId", }); var invocations = Invocations.CreateForTesting(3, testFile); // Last Assert.Equal("s-5", invocations.GetLastInvocation(LoggingContext).Value.SessionId); Assert.Equal(2, invocations.GetInvocations(LoggingContext).Count); Assert.Equal("s-4", invocations.GetInvocations(LoggingContext)[0].SessionId); Assert.Equal("s-5", invocations.GetInvocations(LoggingContext)[1].SessionId); }
public IMethodReturn Invoke(IMethodInvocation invocation, GetNextBehavior getNext) { if (invocation.MethodBase.DeclaringType == typeof(IMocked)) { return(invocation.CreateValueReturn(this)); } CallContext <IMethodInvocation> .SetData(nameof(IMethodInvocation), invocation); Invocations.Add(invocation); if (Behaviors.Count == 0) { return(getNext().Invoke(invocation, getNext)); } // This is the only added functionality of this behavior, to first match // applicable InvokeBehaviors and execute them in sequence. var applicableBehaviors = Behaviors.Where(behavior => behavior.AppliesTo(invocation)).ToArray(); if (applicableBehaviors.Length == 0) { return(getNext().Invoke(invocation, getNext)); } var index = 0; return(applicableBehaviors[0].Invoke(invocation, () => { ++index; return (index < applicableBehaviors.Length) ? applicableBehaviors[index].Invoke : getNext(); })); }
public void TestGetLatestEmpty() { var testFile = GetFile(); var invocations = Invocations.CreateForTesting(3, testFile); Assert.Equal(null, invocations.GetLastInvocation(LoggingContext)); }
public new static Invocations Parse(WordReader reader, uint wordCount) { var end = reader.Position + wordCount; var res = new Invocations(); res.NumberofInvocations = Spv.LiteralInteger.Parse(reader, end - reader.Position); return(res); }
public void Handle(UserContextMessageBase message) { Invocations.Add(GetType()); Console.WriteLine("Processing UserContextMessageBase"); MessageContext.GetCurrent().Items[UserContextKey] = message.UserContext; }
private IEnumerable <StatementSyntax> Generate(IEnumerable <T> instances) { foreach (var instance in instances) { var instantiation = Mapper.InstanceToSyntax(instance); yield return(Invocations.InvokeOnLocalMethod("Add", instantiation.AsArgument()).AsStatement()); } }
public void TestGetLatestSingle() { var testFile = GetFile(); var invocations = Invocations.CreateForTesting(3, testFile); invocations.RecordInvocation(LoggingContext, CreateTestInvocation(1)); Assert.Equal("s-1", invocations.GetLastInvocation(LoggingContext).Value.SessionId); }
public void Handle(SimpleMessage message) { Invocations.Add(GetType()); var userContext = (UserContext)MessageContext.GetCurrent().Items[UserContextHandler.UserContextKey]; // allow to use the _context to process this message Console.WriteLine("Received SimpleMessage {0} - context: {1}", message.Data, userContext.UserId); }
public void TestNoFileAccess() { var testFile = GetFile(); var invocations = Invocations.CreateForTesting(3, testFile); // No exception should be thrown even if the invocations file cannot be opened using (var fs = new FileStream(testFile, FileMode.CreateNew, FileAccess.Write, FileShare.None)) { invocations.RecordInvocation(LoggingContext, CreateTestInvocation(2)); } }
/// <summary> /// Performs an invocation on the mock. /// </summary> /// <remarks> /// Whether or not a behavior matches the invocation, the actual invocation /// is always recorded. /// </remarks> public virtual void Invoke(IInvocation invocation) { Invocations.Add(invocation); var behavior = Behaviors.FirstOrDefault(x => x.AppliesTo(invocation)); if (behavior != null) { behavior.ExecuteFor(invocation); } }
public void TestGetLatestOverflow() { var testFile = GetFile(); var invocations = Invocations.CreateForTesting(3, testFile); for (int i = 0; i < 10; i++) { invocations.RecordInvocation(LoggingContext, CreateTestInvocation(i)); } Assert.Equal("s-9", invocations.GetLastInvocation(LoggingContext).Value.SessionId); }
/// <summary> /// Returns true if ResponseMetricsListData instances are equal /// </summary> /// <param name="other">Instance of ResponseMetricsListData to be compared</param> /// <returns>Boolean</returns> public bool Equals(ResponseMetricsListData other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( RequestTime == other.RequestTime || RequestTime != null && RequestTime.Equals(other.RequestTime) ) && ( Availability == other.Availability || Availability != null && Availability.Equals(other.Availability) ) && ( Invocations == other.Invocations || Invocations != null && Invocations.Equals(other.Invocations) ) && ( AverageResponse == other.AverageResponse || AverageResponse != null && AverageResponse.Equals(other.AverageResponse) ) && ( AverageTps == other.AverageTps || AverageTps != null && AverageTps.Equals(other.AverageTps) ) && ( PeakTps == other.PeakTps || PeakTps != null && PeakTps.Equals(other.PeakTps) ) && ( Errors == other.Errors || Errors != null && Errors.Equals(other.Errors) ) && ( Rejections == other.Rejections || Rejections != null && Rejections.Equals(other.Rejections) )); }
public void OnVisitSyntaxNode(SyntaxNode syntaxNode) { switch (syntaxNode) { case InvocationExpressionSyntax invocation: Invocations.Add(invocation); break; case VariableDeclarationSyntax variableDeclarationSyntax: VariableDeclarations.Add(variableDeclarationSyntax); break; } }
protected async Task <CachedGraph> GetCachedGraphAsync(string buildId) { var loggingContext = new LoggingContext("Website"); var invocations = new Invocations().GetInvocations(loggingContext); var thisInvocation = invocations.First(invocation => invocation.SessionId == buildId); var entry = await Cache.GetOrCreateAsync( "CachedGraph: =" + buildId, (newEntry) => CachedGraph.LoadAsync( Path.Combine(thisInvocation.LogsFolder, "BuildXL"), loggingContext, true )); return(entry); }
public void TestFillingAndOverFlow() { var testFile = GetFile(); var invocations = Invocations.CreateForTesting(3, testFile); for (int i = 0; i < 12; i++) { invocations.RecordInvocation(LoggingContext, CreateTestInvocation(i)); } Assert.True(File.Exists(testFile)); var lines = File.ReadAllLines(testFile); Assert.Equal(3, lines.Length); Assert.True(lines[0].StartsWith("0\ts-9\t")); Assert.True(lines[1].StartsWith("0\ts-10\t")); Assert.True(lines[2].StartsWith("0\ts-11\t")); }
IReadOnlyDictionary <string, Invocations.Invocation> GetInvocations() { return(Cache.GetOrCreate( "Builds.tsv", newEntry => { var buildXLInvocations = new Invocations(); newEntry.ExpirationTokens.Add(m_fileProvider.Watch(buildXLInvocations.GetBuildTsvFilePath())); newEntry.SetSlidingExpiration(TimeSpan.FromMinutes(5)); var invocations = buildXLInvocations.GetInvocations(m_loggingContext); var dictionary = new Dictionary <string, Invocations.Invocation>(invocations.Count, StringComparer.OrdinalIgnoreCase); foreach (var invocation in invocations) { dictionary.Add(invocation.SessionId, invocation); } return dictionary; })); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (RequestTime != null) { hashCode = hashCode * 59 + RequestTime.GetHashCode(); } if (Availability != null) { hashCode = hashCode * 59 + Availability.GetHashCode(); } if (Invocations != null) { hashCode = hashCode * 59 + Invocations.GetHashCode(); } if (AverageResponse != null) { hashCode = hashCode * 59 + AverageResponse.GetHashCode(); } if (AverageTps != null) { hashCode = hashCode * 59 + AverageTps.GetHashCode(); } if (PeakTps != null) { hashCode = hashCode * 59 + PeakTps.GetHashCode(); } if (Errors != null) { hashCode = hashCode * 59 + Errors.GetHashCode(); } if (Rejections != null) { hashCode = hashCode * 59 + Rejections.GetHashCode(); } return(hashCode); } }
public void TestShrinking() { var testFile = GetFile(); File.WriteAllLines(testFile, new [] { "a", "b", "c", "d", "e", "f" }); var invocations = Invocations.CreateForTesting(4, testFile); invocations.RecordInvocation(LoggingContext, CreateTestInvocation(1)); invocations.RecordInvocation(LoggingContext, CreateTestInvocation(2)); Assert.True(File.Exists(testFile)); var lines = File.ReadAllLines(testFile); Assert.Equal(4, lines.Length); Assert.True(lines[0].StartsWith("e")); Assert.True(lines[1].StartsWith("f")); Assert.True(lines[2].StartsWith("0\ts-1\t")); Assert.True(lines[3].StartsWith("0\ts-2\t")); }
public void Arguments() { Invocations.Arguments(); }
public void Statics() { Invocations.Static(); }
public void Locals() { Invocations.Local(); }
private ExpressionSyntax ValueToSyntax(object value) { if (value != null) { var type = value.GetType(); if (type == typeof(int)) { return(Literals.Integer((int)value)); } if (type == typeof(string)) { return(Literals.String((string)value)); } if (type == typeof(bool)) { return(Literals.Boolean((bool)value)); } if (type == typeof(float)) { return(Literals.Float((float)value)); } if (type == typeof(double)) { return(SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal((double)value))); } if (type == typeof(TimeSpan)) { var timespan = (TimeSpan)value; var expression = SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(timespan.Ticks)); return(Instantiations.NewUp("System.TimeSpan", expression.AsArgument())); } if (type.IsEnum) { RegisterFoundType(type); return(Invocations.InvokeProperty(type.Name, value.ToString())); } if (type.IsArray) { dynamic values = value; var valuesSyntax = new List <ExpressionSyntax>(); foreach (var val in values) { valuesSyntax.Add(ValueToSyntax(val)); } return(valuesSyntax.AsArraySyntax()); } if (type.IsDictionaryType()) { RegisterFoundType(type); var kvpExpressions = new List <ExpressionSyntax>(); dynamic values = value; foreach (dynamic kvp in values) { kvpExpressions.Add(Collections.KeyValuePairInitializer(ValueToSyntax(kvp.Key), ValueToSyntax(kvp.Value))); } var kvpType = type.GetDictionaryKeyValuePairType(); var keyType = Types.Type(kvpType.GetGenericArguments()[0]); // Floats come through as System.Single instead of float. Hack but it fixes it var valueType = kvpType.GetGenericArguments()[1] == typeof(float) ? Types.Type("float") : Types.Type(kvpType.GetGenericArguments()[1]); return(Collections.InstantiateDictionary(keyType, valueType, kvpExpressions)); } if (!_childMappers.ContainsKey(type)) { RegisterFoundType(type); _childMappers.Add(type, new InstanceToSyntaxMapper(Logger)); } return(_childMappers[type].InstanceToSyntax(value)); } return(Literals.Null); }
public void Member() { Invocations.Member(); }
public void AsyncAwait() { Invocations.AsyncAwait(); }
public void StaticInstances() { Invocations.StaticInstance(); }
public void Instances() { Invocations.Instance(); }
public void Types() { Invocations.Type(); }