public void Code_First_can_use_nested_types() { using (var nested = new NestedContext()) { var cheese = nested.Cheeses.Single(); Assert.Equal("Swiss", cheese.Name); Assert.Equal(Maturity.Todler, cheese.Info.Maturity); Assert.Equal(16, cheese.Info.Image.Length); Assert.Equal(new[] { "Ketchup", "Mustard" }, cheese.Pickles.Select(p => p.Name).OrderBy(n => n)); cheese.Pickles.Add( new Pickle { Name = "Not Pickles" }); ExtendedSqlAzureExecutionStrategy.ExecuteNew( () => { using (nested.Database.BeginTransaction()) { nested.SaveChanges(); Assert.Equal( new[] { "Ketchup", "Mustard", "Not Pickles" }, nested.Pickles.AsNoTracking().Select(p => p.Name).OrderBy(n => n)); } }); } }
/// <summary> /// Gets the context to use when building the inner text of the tag. /// </summary> /// <param name="writer">The text writer passed</param> /// <param name="keyScope">The current scope.</param> /// <param name="arguments">The arguments passed to the tag.</param> /// <returns>The scope to use when building the inner text of the tag.</returns> public override IEnumerable <NestedContext> GetChildContext( TextWriter writer, Scope keyScope, Dictionary <string, object> arguments, Scope contextScope) { object value = arguments[collectionParameter]; int limit = int.Parse(arguments["limit"].ToString()); IList <T> enumerable = value as IList <T>; if (enumerable == null) { yield break; } enumerable = enumerable.Take(limit).ToList(); int index = 0; foreach (object item in enumerable) { NestedContext childContext = new NestedContext() { KeyScope = keyScope.CreateChildScope(item), Writer = writer, ContextScope = contextScope.CreateChildScope(), }; //childContext.ContextScope.Set("index", index); yield return(childContext); ++index; } }
/// <summary>Pushes the specified value on current stack</summary> /// <param name="value">The value to be pushed.</param> /// <returns> /// An instance of the object that implements IDisposable that returns the stack to the previous level when /// IDisposable.Dispose() is called. To be used with C# using() statement. /// </returns> public static IDisposable Push <T>(T value) { var nestedContext = new NestedContext <T>(GetThreadLocal(), value); SetThreadLocal(nestedContext); return(nestedContext); }
/// <summary> /// Gets the context to use when building the inner text of the tag. /// </summary> /// <param name="writer">The text writer passed</param> /// <param name="keyScope">The current scope.</param> /// <param name="arguments">The arguments passed to the tag.</param> /// <returns>The scope to use when building the inner text of the tag.</returns> public override IEnumerable <NestedContext> GetChildContext( TextWriter writer, Scope keyScope, Dictionary <string, object> arguments, Scope contextScope) { object value = arguments[collectionParameter]; var enumerable = value as IEnumerable <object>; if (enumerable == null) { yield break; } int index = 0; var item = enumerable.First(); NestedContext childContext = new NestedContext() { KeyScope = keyScope.CreateChildScope(item), Writer = writer, ContextScope = contextScope.CreateChildScope(), }; childContext.ContextScope.Set("index", index); childContext.ContextScope.Set("value", item.ToString()); yield return(childContext); ++index; }
/// <summary> /// Pushes the specified value on current stack /// </summary> /// <param name="value">The value to be pushed.</param> /// <returns>An instance of the object that implements IDisposable that returns the stack to the previous level when IDisposable.Dispose() is called. To be used with C# using() statement.</returns> public static IDisposable Push <T>(T value) { var parent = GetThreadLocal(); var current = new NestedContext <T>(parent, value); SetThreadLocal(current); return(current); }
public static IDisposable Push(string value) { var parent = GetThreadLocal(); var current = NestedContext.CreateNestedContext(parent, value); SetThreadLocal(current); return(current); }
public void GetDatabaseValues_can_be_used_with_nested_types() { using (var nested = new NestedContext()) { var dbValues = nested.Entry(nested.Cheeses.Single()).GetDatabaseValues(); Assert.Equal("Swiss", dbValues.GetValue <string>("Name")); Assert.Equal(Maturity.Todler, dbValues.GetValue <DbPropertyValues>("Info").GetValue <Maturity>("Maturity")); } }
public void Find_can_be_used_with_nested_types() { using (var nested = new NestedContext()) { var cheese = nested.Cheeses.Find(nested.Cheeses.AsNoTracking().Single().Id); Assert.Equal("Swiss", cheese.Name); Assert.Equal(Maturity.Todler, cheese.Info.Maturity); Assert.Equal(16, cheese.Info.Image.Length); Assert.Equal(new[] { "Ketchup", "Mustard" }, cheese.Pickles.Select(p => p.Name).OrderBy(n => n)); } }
public override IEnumerable<NestedContext> GetChildContext(TextWriter writer, Scope keyScope, Dictionary<string, object> arguments, Scope contextScope) { NestedContext context = new NestedContext() { KeyScope = keyScope, Writer = new StringWriter(), WriterNeedsConsidated = true, }; yield return context; }
public FeatureWithARecursiveContextSteps(NestedContext context) { _context = context; }