public void Fill_InvalidProperty_UsesDefaultValue() { var target = new List<ScatterPoint>(); var filler = new ListBuilder<ScatterPoint>(); filler.Add("B", 0d); filler.Fill(target, this.src, args => new ScatterPoint(Convert.ToDouble(args[0]), 0)); }
/// <summary> /// Constructs the list. /// </summary> /// <param name="builder">The builder.</param> public void ConstructList(ListBuilder builder) { builder.CreateList(); builder.AddFields(); if (builder.CreateDefaultValues) builder.AddSampleData(); builder.HideList(); }
public void FillDataPoints() { var target = new List<DataPoint>(); var filler = new ListBuilder<DataPoint>(); filler.Add("A", 0d); filler.Fill(target, this.src, args => new DataPoint(Convert.ToDouble(args[0]), 0)); Assert.AreEqual(1, target.Count); Assert.AreEqual(3.14, target[0].X); }
public void Fill_NullProperty_DefaultValueIsExpected() { var target = new List<ScatterPoint>(); var filler = new ListBuilder<ScatterPoint>(); filler.Add(null, 42); filler.Fill(target, this.src, args => new ScatterPoint(Convert.ToDouble(args[0]), 0)); Assert.AreEqual(1, target.Count); Assert.AreEqual(42, target[0].X); }
public void Constructing_AssignsValuesToProperties() { using (mocks.Record()) propertyNamer.Expect(x => x.SetValuesOfAllIn(Arg<IList<MyClass>>.Is.TypeOf)); var list = new List<MyClass>(); var builder = new ListBuilder<MyClass>(listSize, propertyNamer, reflectionUtil, new BuilderSettings()); using (mocks.Playback()) builder.Name(list); }
public void ShouldConstructDeclarations() { IGlobalDeclaration<MyClass> declaration = MockRepository.GenerateMock<IGlobalDeclaration<MyClass>>(); var builder = new ListBuilder<MyClass>(listSize, propertyNamer, reflectionUtil); builder.AddDeclaration(declaration); using (mocks.Record()) declaration.Expect(x => x.Construct()); using (mocks.Playback()) builder.Construct(); }
public void BuildStringListTest() { // Arrange ListBuilder listBuilder = new ListBuilder(); // Act var result = listBuilder.BuildStringList(); // Analyze result.ForEach(s => TestContext.WriteLine(s)); // Assert Assert.IsNotNull(result); }
public void CompareListTest() { // Arrange ListBuilder listBuilder = new ListBuilder(); // Act var result = listBuilder.CompareLists(); // Analyze result.ForEach(i => TestContext.WriteLine(i.ToString())); // Assert Assert.IsNotNull(result); }
public void IfNoAllExistsAndSumOfAffectedItemsInDeclarationsIsLessThanCapacity_ShouldAddADefaultAll() { var builder = new ListBuilder<MyClass>(30, propertyNamer, reflectionUtil, new BuilderSettings()); builder.TheFirst(10); using (mocks.Record()) { reflectionUtil.Expect(x => x.RequiresConstructorArgs(typeof (MyClass))).Return(false).Repeat.Any(); // Even though a declaration of 10 has been added, we expect the list builder to add // a default GlobalDeclaration (All). Therefore we expect CreateInstanceOf to be called 40 times reflectionUtil.Expect(x => x.CreateInstanceOf<MyClass>()).Return(myClass).Repeat.Times(40); } using (mocks.Playback()) builder.Construct(); }
public void ConstructShouldComplainIfTypeNotParameterlessNoAllAndSumOfItemsInDeclarationsDoNotEqualCapacity() { IDeclaration<MyClassWithConstructor> declaration1 = MockRepository.GenerateMock<IDeclaration<MyClassWithConstructor>>(); IDeclaration<MyClassWithConstructor> declaration2 = MockRepository.GenerateMock<IDeclaration<MyClassWithConstructor>>(); using (mocks.Record()) { declaration1.Expect(x => x.NumberOfAffectedItems).Return(2); declaration2.Expect(x => x.NumberOfAffectedItems).Return(2); reflectionUtil.Expect(x => x.RequiresConstructorArgs(typeof (MyClass))).Return(true); } var builder = new ListBuilder<MyClass>(10, propertyNamer, reflectionUtil,new BuilderSettings()); using (mocks.Playback()) { // TODO FIX #if !SILVERLIGHT Assert.Throws<BuilderException>(() => builder.Construct()); #endif } }
/// <summary> /// Updates the data. /// </summary> protected internal override void UpdateData() { if (this.ItemsSource != null) { this.Items.Clear(); var filler = new ListBuilder<IntervalBarItem>(); filler.Add(this.MinimumField, double.NaN); filler.Add(this.MaximumField, double.NaN); filler.FillT(this.Items, this.ItemsSource, args => new IntervalBarItem() { Start = Convert.ToDouble(args[0]), End = Convert.ToDouble(args[1]) }); } }
public void ShouldBeAbleToBuildAList() { IDeclaration<MyClass> declaration = MockRepository.GenerateMock<IDeclaration<MyClass>>(); var builder = new ListBuilder<MyClass>(listSize, propertyNamer, reflectionUtil, new BuilderSettings()); using (mocks.Record()) { reflectionUtil.Stub(x => x.RequiresConstructorArgs(typeof (MyClass))).Return(false).Repeat.Any(); reflectionUtil.Expect(x => x.CreateInstanceOf<MyClass>()).Return(myClass).Repeat.Any(); declaration.Expect(x => x.Construct()); declaration.Expect(x => x.AddToMaster(Arg<MyClass[]>.Is.TypeOf)); propertyNamer.Expect(x => x.SetValuesOfAllIn(Arg<IList<MyClass>>.Is.TypeOf)); declaration.Expect(x => x.CallFunctions(Arg<IList<MyClass>>.Is.TypeOf)).IgnoreArguments(); } using (mocks.Playback()) builder.Build(); }
public static void Main(string[] args) { var options = new Options(); CommandLine.ICommandLineParser cmdParser = new CommandLine.CommandLineParser(new CommandLine.CommandLineParserSettings(System.Console.Error)); if (cmdParser.ParseArguments(args, options)) { string connectionString = string.Format("URI=file:{0}", options.Database); #if (NET) var connection = new System.Data.SQLite.SQLiteConnection(connectionString); #else var connection = new Mono.Data.Sqlite.SqliteConnection(connectionString); #endif connection.Open(); var command = connection.CreateCommand(); command.CommandText = "CREATE TABLE IF NOT EXISTS at (id INTEGER PRIMARY KEY NOT NULL,name VARCHAR,surname VARCHAR,year INTEGER,gender CHAR,time VARCHAR)"; command.ExecuteNonQuery(); var repo = new AthleteRepository(command); switch (options.Action) { case Action.Module: { // 10mm d=> 28pt // 15mm => 42pt //float marginLeft, float marginRight, float marginTop, float marginBottom var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10, 10, 36, 36); iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream("./module.pdf", System.IO.FileMode.Create)); document.Open(); var builder = new ModuleBuilder(document, options.YearEdition, 10); for (int page = 0; page < 10; page++) { builder.AddPage(); } document.Close(); break; } case Action.Insert: { System.Console.WriteLine("Drop all results?[y/N]?"); string yes = System.Console.ReadLine(); if (yes == "y") { FileHelpers.FileHelperEngine<Athlete> engine = new FileHelpers.FileHelperEngine<Athlete>(); Athlete[] athletes = engine.ReadFile(options.Input); repo.DeleteAll(); foreach (var a in athletes) { System.Console.WriteLine(a.Name); repo.Insert(a); } } break; } case Action.CreateList: case Action.CreateResult: { string catFileName = GetCatFileName(options); string reportFileName = GetReportFileName(options); var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10, 10, 36, 36); iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(reportFileName, System.IO.FileMode.Create)); document.Open(); IBuilder builder = null; if (options.Action == Action.CreateList) { builder = new ListBuilder(document); } else { builder = new PdfBuilder(document); } Category[] cats = GetCategories(catFileName); foreach (Category cat in cats) { if (log.IsDebugEnabled) log.Debug("parse" + cat.Id); builder.BeginReport(cat.Title, options.YearEdition); var athletes = repo.Query(string.Format (cat.Sql, options.YearEdition)); foreach (Athlete athlete in athletes) { builder.Add(athlete); } builder.EndReport(); } document.Close(); break; } case Action.Interactive: { Category[] cats = GetCategories(GetCatFileName(options)); var parser = new TimeParser(); foreach (Category cat in cats) { System.Console.WriteLine("========{0}=========", cat.Id); var athletes = repo.Query(string.Format (cat.Sql, options.YearEdition)); foreach (Athlete athlete in athletes) { System.Console.Write("{0:00} {1}\t{2}({3}):", athlete.Id, athlete.Surname, athlete.Name, athlete.Gender); string time = string.Empty; string fmt = string.Empty; do { time = System.Console.ReadLine(); fmt = parser.Parse(time); if (!string.IsNullOrEmpty(fmt) ) { System.Console.WriteLine(fmt); repo.UpdateTime(athlete.Id, fmt); } else { if (time != "s") { System.Console.WriteLine("invalid.."); } } } while (string.IsNullOrEmpty(fmt) && time != "s"); } } break; } } connection.Close(); } }
/// <summary> /// Updates the points from the <see cref="ItemsSeries.ItemsSource" />. /// </summary> private void UpdateItemsSourcePoints() { // Use the Mapping property to generate the points if (this.Mapping != null) { this.ClearItemsSourcePoints(); foreach (var item in this.ItemsSource) { this.itemsSourcePoints.Add(this.Mapping(item)); } return; } var sourceAsListOfDataPoints = this.ItemsSource as List<DataPoint>; if (sourceAsListOfDataPoints != null) { this.itemsSourcePoints = sourceAsListOfDataPoints; this.ownsItemsSourcePoints = false; return; } this.ClearItemsSourcePoints(); var sourceAsEnumerableDataPoints = this.ItemsSource as IEnumerable<DataPoint>; if (sourceAsEnumerableDataPoints != null) { this.itemsSourcePoints.AddRange(sourceAsEnumerableDataPoints); return; } // Get DataPoints from the items in ItemsSource // if they implement IDataPointProvider // If DataFields are set, this is not used if (this.DataFieldX == null || this.DataFieldY == null) { foreach (var item in this.ItemsSource) { if (item is DataPoint) { this.itemsSourcePoints.Add((DataPoint)item); continue; } var idpp = item as IDataPointProvider; if (idpp == null) { continue; } this.itemsSourcePoints.Add(idpp.GetDataPoint()); } } else { var filler = new ListBuilder<DataPoint>(); filler.Add(this.DataFieldX, double.NaN); filler.Add(this.DataFieldY, double.NaN); filler.Fill(this.itemsSourcePoints, this.ItemsSource, args => new DataPoint(Axes.Axis.ToDouble(args[0]), Axes.Axis.ToDouble(args[1]))); } }
public static object CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes) { if (type == null) throw new ArgumentNullException(nameof(type)); // If they didn't specify a lookup, then we will provide the default lookup. const BindingFlags LookupMask = (BindingFlags)0x000000FF; if ((bindingAttr & LookupMask) == 0) bindingAttr |= BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance; if (activationAttributes != null && activationAttributes.Length > 0) throw new NotSupportedException(SR.NotSupported_ActivAttr); type = type.UnderlyingSystemType; CreateInstanceCheckType(type); if (args == null) args = Array.Empty<object>(); int numArgs = args.Length; // This short-circuit depends on the fact that the toolchain prohibits valuetypes with nullary constructors. Unfortunately, we can't check for the presence of nullary // constructors without risking a MissingMetadataException, and we can't regress the prior N behavior that allowed CreateInstance on valuetypes to work regardless of metadata. if (numArgs == 0 && type.IsValueType) return RuntimeAugments.NewObject(type.TypeHandle); Type[] argTypes = new Type[numArgs]; for (int i = 0; i < numArgs; i++) { argTypes[i] = args[i]?.GetType(); } ConstructorInfo[] candidates = type.GetConstructors(bindingAttr); ListBuilder<MethodBase> matches = new ListBuilder<MethodBase>(candidates.Length); for (int i = 0; i < candidates.Length; i++) { if (candidates[i].QualifiesBasedOnParameterCount(bindingAttr, CallingConventions.Any, argTypes)) matches.Add(candidates[i]); } if (matches.Count == 0) throw new MissingMethodException(SR.Arg_NoDefCTor); if (binder == null) binder = Type.DefaultBinder; object state = null; MethodBase invokeMethod = binder.BindToMethod(bindingAttr, matches.ToArray(), ref args, null, culture, null, out state); if (invokeMethod.GetParametersNoCopy().Length == 0) { if (args.Length != 0) { Debug.Assert((invokeMethod.CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs); throw new NotSupportedException(SR.NotSupported_CallToVarArg); } // Desktop compat: CoreClr invokes a "fast-path" here (call Activator.CreateInstance(type, true)) that also // bypasses the binder.ReorderArgumentArray() call. That "fast-path" isn't a fast-path for us so we won't do that // but we'll still null out the "state" variable to bypass the Reorder call. // // The only time this matters at all is if (1) a third party binder is being used and (2) it actually reordered the array // which it shouldn't have done because (a) we didn't request it to bind arguments by name, and (b) it's kinda hard to // reorder a zero-length args array. But who knows what a third party binder will do if we make a call to it that we didn't // used to do, so we'll preserve the CoreClr order of calls just to be safe. state = null; } object result = ((ConstructorInfo)invokeMethod).Invoke(bindingAttr, binder, args, culture); if (state != null) binder.ReorderArgumentArray(ref args, state); return result; }
/// <summary> /// Updates the data. /// </summary> protected internal override void UpdateData() { if (this.ItemsSource == null) { return; } this.slices.Clear(); var filler = new ListBuilder<PieSlice>(); filler.Add(this.LabelField, (string)null); filler.Add(this.ValueField, double.NaN); filler.Add(this.ColorField, OxyColors.Automatic); filler.Add(this.IsExplodedField, false); filler.FillT( this.slices, this.ItemsSource, args => new PieSlice((string)args[0], Convert.ToDouble(args[1])) { Fill = (OxyColor)args[2], IsExploded = (bool)args[3] }); }
static Extensions() { _listBuilder = new ListBuilder(); }
/// <summary> /// Updates the data. /// </summary> protected internal override void UpdateData() { if (this.ItemsSource == null) { return; } this.items.Clear(); // Use the mapping to generate the points if (this.Mapping != null) { foreach (var item in this.ItemsSource) { this.items.Add(this.Mapping(item)); } return; } var sequenceOfHighLowItems = this.ItemsSource as IEnumerable<HighLowItem>; if (sequenceOfHighLowItems != null) { this.items.AddRange(sequenceOfHighLowItems); return; } var filler = new ListBuilder<HighLowItem>(); filler.Add(this.DataFieldX, double.NaN); filler.Add(this.DataFieldHigh, double.NaN); filler.Add(this.DataFieldLow, double.NaN); filler.Add(this.DataFieldOpen, double.NaN); filler.Add(this.DataFieldClose, double.NaN); filler.FillT(this.items, this.ItemsSource, args => new HighLowItem(Axis.ToDouble(args[0]), Convert.ToDouble(args[1]), Convert.ToDouble(args[2]), Convert.ToDouble(args[3]), Convert.ToDouble(args[4]))); }
/// <summary> /// The update data. /// </summary> protected internal override void UpdateData() { base.UpdateData(); if (this.ItemsSource == null) { this.IsPoints2Defined = this.points2.Count > 0; if (this.IsPoints2Defined) { this.actualPoints2 = this.points2; } else { this.actualPoints2 = this.GetConstantPoints2().ToList(); } return; } this.itemsSourcePoints2.Clear(); // TODO: make it consistent with DataPointSeries.UpdateItemsSourcePoints // Using reflection on DataFieldX2 and DataFieldY2 this.IsPoints2Defined = this.DataFieldX2 != null && this.DataFieldY2 != null; if (this.IsPoints2Defined) { var filler = new ListBuilder<DataPoint>(); filler.Add(this.DataFieldX2, double.NaN); filler.Add(this.DataFieldY2, double.NaN); filler.Fill(this.itemsSourcePoints2, this.ItemsSource, args => new DataPoint(Axes.Axis.ToDouble(args[0]), Axes.Axis.ToDouble(args[1]))); } else { this.itemsSourcePoints2.AddRange(this.GetConstantPoints2()); } }