/// <summary> /// 获取所有要查询的字段信息的数组. /// </summary> /// <returns></returns> internal IDescription[] GetFieldsArray() { List <IDescription> fields = new List <IDescription>(); PropertyInfo[] ps = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); if (ps != null && ps.Length > 0) { IDescription buffer = null; foreach (PropertyInfo pi in ps) { if (pi.PropertyType.IsValueType) { continue; } buffer = pi.GetValue(this) as IDescription; if (buffer == null) { continue; } fields.Add(buffer); } } if (fields.Count < 1) { fields.Add(td.Field("*")); } return(fields.ToArray()); }
public override void Describe(IDescription description) { description.AppendText("a string "); description.AppendValue(_originalValue); description.AppendText(" compressing white space to "); description.AppendValue(_value); }
/// <summary> /// Binds a <see cref="PerspexProperty"/> to an observable. /// </summary> /// <param name="property">The property.</param> /// <param name="source">The observable.</param> /// <param name="priority">The priority of the binding.</param> /// <returns> /// A disposable which can be used to terminate the binding. /// </returns> public IDisposable Bind( PerspexProperty property, IObservable <object> source, BindingPriority priority = BindingPriority.LocalValue) { Contract.Requires <NullReferenceException>(property != null); PriorityValue v; IDescription description = source as IDescription; if (!IsRegistered(property)) { throw new InvalidOperationException(string.Format( "Property '{0}' not registered on '{1}'", property.Name, GetType())); } if (!_values.TryGetValue(property, out v)) { v = CreatePriorityValue(property); _values.Add(property, v); } _propertyLog.Verbose( "Bound {Property} to {Binding} with priority {Priority}", property, source, priority); return(v.Add(source, (int)priority)); }
/// <summary> /// Count 函数解释。 /// </summary> /// <param name="D">FunDescription 对象。</param> /// <param name="DbParameters">用于缓存在解释过程中可能会产生的参数。</param> /// <returns></returns> protected virtual string CountParsing(FunDescription D, ref List <IDbDataParameter> DbParameters) { if (D.Parameter is IDescription) { // 参数为表达式或都字段。 IDescription pDes = (IDescription)(D.Parameter); pDes.DescriptionParserAdapter = D.DescriptionParserAdapter; string param_buf = pDes.GetParser().Parsing(ref DbParameters); if (param_buf[0] == (char)0x20) { param_buf = param_buf.Remove(0, 1); } return(string.Format("COUNT({0})", param_buf)); } else if (D.Parameter is string || D.Parameter is char) { string param_v = D.Parameter.ToString(); if (param_v == "*") { // COUNT(*) 解释。 return("COUNT(*)"); } else { throw new Exception("Count 函数使用了不正确的参数。"); } } else { // 其它情况。 IDbDataParameter p = Adapter.CreateDbParameter("uf_count", D.Parameter); AddDbParameter(ref DbParameters, p); return(string.Format("COUNT({0})", p.ParameterName)); } }
/// <summary> /// 解释 FROM 子句。 /// </summary> /// <param name="DbParameters">用于缓存在解释过程中可能会产生的参数。</param> /// <returns></returns> public override string Parsing(ref List <IDbDataParameter> DbParameters) { FromBlock fb = (FromBlock)this.Description; StringBuilder cBuffer = new StringBuilder(" FROM"); foreach (object item in fb.Content) { if (item is IDescription) { IDescription D = (IDescription)item; D.DescriptionParserAdapter = fb.DescriptionParserAdapter; cBuffer.Append(D.GetParser().Parsing(ref DbParameters)); } else { if (cBuffer[cBuffer.Length - 1] == (char)0x20) { cBuffer.Append(item); } else { cBuffer.AppendFormat(" {0}", item); } } } return(cBuffer.ToString()); }
public override void DescribeTo(IDescription description) { description.AppendText("a dictionary consisting of:"); var first = true; using (description.IndentBy(4)) { foreach (var entryDescriptor in _entryDescriptors) { if (!first) { description.AppendText(","); } description.AppendNewLine() .AppendText("an entry where:"); using (description.IndentBy(4)) { description.AppendNewLine() .AppendText("key: ") .AppendDescriptionOf(entryDescriptor.KeyMatcher) .AppendNewLine() .AppendText("value: ") .AppendDescriptionOf(entryDescriptor.ValueMatcher); } first = false; } } }
public void DescribeTo(IDescription desc) { if (desc != this)//prevent accidental self recursion { desc.Value(ToString()); } }
public static void Move(IDescription d) { LivingEntity le = d as LivingEntity; if (le == null) { return; } double dir = le.Direction(le.MoveTarget); WalkDirection(le, dir); double scale = 1; Skill skill = le.PreppedSkill ?? le.ActiveSkill; if (skill?.Name == "block") { scale = 0.5; } else if (skill?.Name == "counter") { scale = 0; } le.ChangeCoordsDelta(Math.Cos(dir) * scale, Math.Sin(dir) * scale); }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public override void DescribeOn(IDescription description) { description.AppendText("containing ") .AppendText("\"") .AppendText(substring) .AppendText("\""); }
protected override bool MatchesSafely(IEnumerable <T> items, IDescription mismatchDescription) { List <IMatcher <T> > matchers = new List <IMatcher <T> >(_matchers); object lastMatchedItem = null; int nextMatchIx = 0; foreach (var item in items) { if (nextMatchIx < matchers.Count) { var matcher = matchers.ElementAt(nextMatchIx); if (matcher.Matches(item)) { lastMatchedItem = item; nextMatchIx++; } } } if (nextMatchIx >= matchers.Count) { return(true); } mismatchDescription.AppendDescribable(matchers.ElementAt(nextMatchIx)) .AppendText(" was not found"); if (lastMatchedItem != null) { mismatchDescription.AppendText(" after ") .AppendValue(lastMatchedItem); } return(false); }
public static string Serialize <K, V>(Dictionary <K, V> dict) { if (!dict.Any()) { return("{}"); } StringBuilder sb = new StringBuilder(); sb.Append("{"); foreach (KeyValuePair <K, V> kvp in dict) { sb.Append("("); sb.Append(kvp.Key); sb.Append(","); IDescription idv = kvp.Value as IDescription; if (idv != null) { sb.Append(idv.Serialize()); } else { sb.Append(kvp.Value); } sb.Append(")"); sb.Append(","); } sb.Remove(sb.Length - 1, 1); sb.Append("}"); return(sb.ToString()); }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public void DescribeOn(IDescription description) { description.AppendText("set "); description.AppendText(name); description.AppendText("="); description.AppendValue(value); }
public static string Serialize <T>(IEnumerable <T> list) { if (!list.Any()) { return("[]"); } StringBuilder sb = new StringBuilder(); sb.Append("["); foreach (T t in list) { IDescription idt = t as IDescription; if (idt != null) { sb.Append(idt.Serialize()); } else { sb.Append(t); } sb.Append(","); } sb.Remove(sb.Length - 1, 1); sb.Append("]"); return(sb.ToString()); }
public static Dictionary <K, V> Deserialize <K, V>(string state, Func <string, K> fkey, Func <string, V> fVal) { Dictionary <K, V> dict = new Dictionary <K, V>(); List <string> tokens = DeserializeTokens(state); int start = 1; int pos = start; do { pos = GetClosingIndex(state, start, '(', ')'); tokens = DeserializeTokens(state.Substring(start, pos - start)); if (tokens[1].Contains(":")) { int indextype = tokens[1].IndexOf(':'); string type = tokens[1].Substring(0, indextype); Type t = GetType(type); object o = Activator.CreateInstance(t); IDescription idescr = o as IDescription; if (idescr != null) { idescr.Deserialize(tokens[1].Substring(indextype + 1)); dict.Add(fkey(tokens[0]), (V)idescr); } } else { dict.Add(fkey(tokens[0]), fVal(tokens[1])); } start = pos + 1; }while (++pos < state.Length); return(dict); }
/// <summary> /// 列的解析默认值设置. /// </summary> /// <param name="definition"></param> /// <param name="DbParameters"></param> /// <returns></returns> private string ParseDefaultValue(DbTableColumnDefinition definition, ref List <IDbDataParameter> DbParameters) { IDescription valueDes = definition.Default as IDescription; if (valueDes == null) { switch (definition.DataType) { case GenericDbType.Boolean: return(string.Format("DEFAULT({0})", Convert.ToBoolean(definition.Default) ? 1 : 0)); case GenericDbType.SmallInt: case GenericDbType.Int: case GenericDbType.BigInt: case GenericDbType.Single: case GenericDbType.Money: case GenericDbType.Double: return(string.Format("DEFAULT({0})", definition.Default)); case GenericDbType.Binary: case GenericDbType.VarBinary: case GenericDbType.Image: throw new NotSupportedException(string.Format("Data type {0} does not support setting default value.", definition.Default)); default: return(string.Format("DEFAULT('{0}')", definition.Default.ToString())); } } valueDes.DescriptionParserAdapter = this.Adapter; return(string.Format("DEFAULT({0})", valueDes.GetParser().Parsing(ref DbParameters))); }
public override void DescribeTo(IDescription desc) { var sb = new StringBuilder("A DateTimeOffset equal to "); var sign = m_inclusive ? "= " : " "; if (!m_expect.HasValue) { sb.Append("Null"); } else { sb.Append(m_expect.ToPrettyString()); if (m_maxMinus.HasValue || m_maxPlus.HasValue) { sb.Append(" where "); if (m_maxMinus.HasValue) { sb.Append(m_maxMinus.Value.ToPrettyString()).Append(" <").Append(sign); } sb.Append(" max diff "); if (m_maxPlus.HasValue) { sb.Append(" >").Append(sign).Append(m_maxPlus.Value.ToPrettyString()); } } } desc.Text(sb.ToString()); }
static void Main(string[] args) { IDescription[] array = new IDescription[6]; array[0] = new PrintEdition("Gari", 300, 50); array[1] = new Magazine("Сказки деда", 100, 20, 155); array[2] = new Book("Сказки бабушки", 10, 90, 255, "Фентази"); array[3] = new Textbook("Сказки Славы", 1000, 950, 55, "Приключения", 2004); array[4] = new Author("Сказки Влада", 1500, 50, 155, "Детектив", 2001, "Савченко"); array[5] = new IZdatelstvo("Сказки Вани", 1545, 540, 14555, "Сказки", 2019, "Иванов", "Беларусь"); Console.WriteLine(array[4] is IZdatelstvo); //for(int i =0; i< array.Length; i++) //{ // Console.WriteLine($"{array[i]}\n"); //} //user2 pr = new user2(); //pr.Display(); Printer p = new Printer(); for (int i = 0; i < 5; i++) { p.IAmPrinting(array[i]); } }
private void AddItemToBasketGrid(IDescription itemDescription) { Grid newItemGrid = new Grid(); newItemGrid.Margin = new Thickness(5, 0, 0, 10); newItemGrid.Height = 50; var imageColumn = new ColumnDefinition(); imageColumn.Width = new GridLength(50); newItemGrid.ColumnDefinitions.Add(imageColumn); newItemGrid.ColumnDefinitions.Add(new ColumnDefinition()); ElementRenderer.VisualizeImageInPanel( newItemGrid, itemDescription.Name, App.FileManager.GetBaseDirectory(itemDescription.GetType().Name)); var textBlock = new TextBlock(); textBlock.Text = itemDescription.Name; textBlock.VerticalAlignment = System.Windows.VerticalAlignment.Center; textBlock.Margin = new Thickness(5, 0, 0, 0); textBlock.FontSize = 15; Grid.SetColumn(textBlock, 1); newItemGrid.Children.Add(textBlock); this.BasketElementsStackPanel.Children.Add(newItemGrid); }
public override void Describe(IDescription description) { MatchCollection matches = ArgPattern.Matches(_descriptionTemplate); int textStart = 0; foreach (Match match in matches) { // Add the description string subStr = _descriptionTemplate.Substring(textStart, match.Index - textStart); description.AppendText(subStr); // Add the value of the description int argIndex = getIndex(match); description.AppendValue(_args[argIndex]); // Move our new start location textStart = match.Index + match.Length; } if (textStart < _descriptionTemplate.Length) { string postLength = _descriptionTemplate.Substring(textStart); description.AppendText(postLength); } }
public static IDescription CreateProductDescription(string name, string[] values) { IDescription description = null; try { // Type of product class var type = FoundType(name); // Type of description type var propertyType = GetPropertyType(type, "Description"); var list = new List <Type>(); foreach (var value in GetCharacteristicInfo(propertyType)) { list.Add(value.Type); } var types = list.ToArray(); // Convert values from string var objValues = ConvertTypes(values, types); description = (IDescription)propertyType.GetConstructor(types).Invoke(objValues); } catch { } return(description); }
public override void DescribeTo(IDescription description) { description .AppendText("origin String should contains ") .AppendValue(_substring) .AppendText($" {_expectedCount} times"); }
public static void PrintExpectButGot(IDescription desc, Object actual, IMatcher matcher) { if (desc.IsNull) { return; } desc.Value("matcherType", GetMatcherType(matcher)); desc.Child("expected", matcher); String s = actual as String; if (s != null) { int len = s.Length; if (len == 0) { desc.Child("but was (empty string,quoted)", "'" + actual + "'"); } else if (s.Trim().Length == 0) { desc.Child("but was (blank string,length " + len + ",quoted)", "'" + actual + "'"); } else { desc.Child("but was (string,length " + len + ",quoted)", "'" + actual + "'"); } } else { desc.Child("but was", actual); } }
public static T GetDescription <T>(IContext context, string path, IRandom random) where T : class, IDescription { var parts = GetParts(path); IDescription current = null; for (int i = 0; i < parts.Count; i++) { current = current == null?context.dataSources.GetChild(parts[i][0]) : current.GetChild(parts[i][0]); if (SelectPathUtil.IsSimple(parts[i][1])) { current = current.GetChild(parts[i][1]); } else { var allKeys = new List <string>(); allKeys.AddRange(current.GetNode().GetSortedKeys()); var affectedKeys = SelectPathUtil.GetAffectedKeys(parts[i][1], allKeys); if (affectedKeys.Count == 0) { return(null); } var selectedKey = affectedKeys[random.Range(0, affectedKeys.Count)]; current = current.GetChild(selectedKey); } } return((T)current); }
protected override bool Matches(Action action, IDescription mismatchDescription) { try { action(); mismatchDescription.AppendText("no exception was thrown"); } catch (T ex) { if (predicate(ex)) { return(true); } mismatchDescription.AppendText("the exception was of the correct type, but did not match the predicate") .AppendNewLine() .AppendValue(ex); } catch (Exception ex) { mismatchDescription.AppendText("an exception of type {0} was thrown", ex.GetType()) .AppendNewLine() .AppendValue(ex); } return(false); }
public override void DescribeMismatch(object actual, IDescription mismatch) { var converted = ConvertToString(actual); mismatch.AppendText("ToString()").AppendText(" "); _subMatcher.DescribeMismatch(converted, mismatch); }
/// /// <param name="description">Description of dataset from module 1</param> public ICollectionDescription RepackToCollectionDescription(IDescription description) { int id = description.ID; Dataset dataset = description.Dataset; logger.LogNewInfo(string.Format("Repacking description with dataset {0} and id {1} to Collection description.", dataset, id)); List <IModule2Property> properties = new List <IModule2Property>(); List <SignalCode> processedSignals = new List <SignalCode>(); foreach (IModule1Property property in description.Properties) { if (processedSignals.Contains(property.Code)) { logger.LogNewWarning("Two signals of the same type in one description"); throw new ArgumentException("ERROR Two signals of the same type in one description"); } if (DatasetRepository.GetDataset(property.Code) != dataset) { logger.LogNewWarning(string.Format("Received dataset {0} does not match dataset for signal {1}", dataset, property.Code)); throw new ArgumentException("Data set does not match signal."); } processedSignals.Add(property.Code); properties.Add(RepackToModule2Property(property)); } HistoricalCollection historicalCollection = new HistoricalCollection(properties); CollectionDescription repackedData = new CollectionDescription(id, dataset, historicalCollection); logger.LogNewInfo("Data repacked to collection description successfully"); return(repackedData); }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public void DescribeOn(IDescription description) { description.AppendText("set arg ") .AppendText(index.ToString()) .AppendText("=") .AppendValue(value); }
private bool Matches(T o, IDescription mismatchDescription) { if (o == null) { mismatchDescription.AppendText("was null"); return(false); } var failedMatchers = _matchers.Where(m => !m.Matches(o)).ToArray(); if (failedMatchers.Length == 0) { return(true); } mismatchDescription.AppendText(_mismatchPrefix) .AppendText(" ") .AppendText(typeof(T).Name); if (typeof(T) != o.GetType()) { mismatchDescription .AppendText(" {") .AppendText(o.GetType().Name) .AppendText("}"); } mismatchDescription.AppendText(" where:"); DescribeMatchers(mismatchDescription, failedMatchers, (d, m) => m.DescribeMismatch(o, d)); return(false); }
public bool Stock(IActor seller, float price, uint count, IBook book, IDescription description) { // Check if there's enough money to pay for this shipment if (Money < price * count) { return(false); } Money -= price * count; // Ensure the book is listed in the catalog if (!catalog.ContainsKey(book)) { description.Price = price + price * PROFIT_MARGIN; // Change from MSRP to actual price catalog.Add(book, description); } // Update stock count IInvoice invoice = inventory.Stock(book, price, count); // Log the delivery history.LogStock(seller, invoice); return(true); }
public override void DescribeTo(IDescription description) { var matcherArray = _matcherCollection.ToArray(); if (matcherArray.Length == 0) { description.AppendText("an empty list"); return; } description.AppendText("a list containing:"); using (description.IndentBy(4)) { description.AppendNewLine(); var first = true; foreach (var matcher in matcherArray) { if (!first) { description.AppendText(",").AppendNewLine(); } description.AppendDescriptionOf(matcher); first = false; } } }
public void PrepareTestDescription(IDescription form) { descriptionTestString = ""; string caption = testRow.Name; descriptionTestString += "<< " + caption + " >>" + "<p>"; string typeCaption = (testRow.IsPractice ? "Practice" : "Computer-Adaptive Test") + ((testRow.IsQuestionTypeIdNull()) ? ("") : (": " + BuisinessObjects.Type.GetName(typeof(BuisinessObjects.Type), testRow.QuestionTypeId))); descriptionTestString += typeCaption + "<p>"; if (navigator.TotalTime != TimeSpan.MaxValue) { descriptionTestString += "Time: " + String.Format("{0} min", navigator.TotalTime.TotalMinutes) + "<p>"; } else { descriptionTestString += "Time: " + "unlimited" + "<p>"; } descriptionTestString += "Number of questions: " + navigator.TotalNumberOfQuestions + "<p>"; descriptionTestString += testRow.Description + "<p>"; form.Caption("Description: " + testRow.Name); form.DescriptionString(descriptionTestString); }
private void AddItemToBasketGrid(IDescription itemDescription) { Grid newItemGrid = new Grid(); newItemGrid.Margin = new Thickness(5, 0, 0, 10); newItemGrid.Height = 50; var imageColumn = new ColumnDefinition(); imageColumn.Width = new GridLength(50); newItemGrid.ColumnDefinitions.Add(imageColumn); newItemGrid.ColumnDefinitions.Add(new ColumnDefinition()); ElementRenderer.VisualizeImageInPanel( newItemGrid, itemDescription.Name, App.FileManager.GetBaseDirectory(itemDescription.GetType().Name)); var textBlock = new TextBlock(); textBlock.Text = itemDescription.Name; textBlock.VerticalAlignment = System.Windows.VerticalAlignment.Center; textBlock.Margin = new Thickness(5, 0, 0, 0); textBlock.FontSize = 15; Grid.SetColumn(textBlock, 1); newItemGrid.Children.Add(textBlock); this.BasketElementsStackPanel.Children.Add(newItemGrid); }
protected override void DescribeMismatchSafely(T[] actualItems, IDescription mismatchDescription) { if (_elementMatchers.Count != actualItems.Length) { mismatchDescription.AppendText("array length was "); // ReSharper disable once HeapView.BoxingAllocation mismatchDescription.AppendValue(actualItems.Length); return; } for (var i = 0; i < _elementMatchers.Count; ++i) { if (_elementMatchers[i].Matches(actualItems[i])) { // If it matches, continue continue; } // If it doesnt match, write out why mismatchDescription.AppendText("element "); // ReSharper disable once HeapView.BoxingAllocation mismatchDescription.AppendValue(i); mismatchDescription.AppendText(" "); _elementMatchers[i].DescribeMismatch(actualItems[i], mismatchDescription); return; } }
/// <summary> /// Binds a <see cref="PerspexProperty"/> to an observable. /// </summary> /// <typeparam name="T">The type of the property.</typeparam> /// <param name="property">The property.</param> /// <param name="source">The observable.</param> /// <param name="priority">The priority of the binding.</param> /// <returns> /// A disposable which can be used to terminate the binding. /// </returns> public IDisposable Bind( PerspexProperty property, IObservable <object> source, BindingPriority priority = BindingPriority.LocalValue) { Contract.Requires <NullReferenceException>(property != null); PriorityValue v; IDescription description = source as IDescription; if (!this.values.TryGetValue(property, out v)) { v = this.CreatePriorityValue(property); this.values.Add(property, v); } this.Log().Debug( "Bound value of {0}.{1} (#{2:x8}) to {3}", this.GetType().Name, property.Name, this.GetHashCode(), description != null ? description.Description : "[Anonymous]"); if (priority == BindingPriority.LocalValue) { return(v.Replace(source, (int)priority)); } else { return(v.Add(source, (int)priority)); } }
/* * the comment function has been deprecated in One Platform public Result comment(string alias, string visibility, string comments) { string rid = getRID(alias); return comment(_CIK, rid, visibility, comments); } */ public Result create(string alias, IDescription desc) { if (desc is DataportDescription) { return doCreate("dataport", alias, desc); } return null; }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public override void DescribeOn(IDescription description) { description.AppendText("`"); Left.DescribeOn(description); description.AppendText("' and `"); Right.DescribeOn(description); description.AppendText("'"); }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public override void DescribeOn(IDescription description) { description.AppendText("["); WriteListOfMatchers(MatcherCount() - 1, description); description.AppendText("] = ("); LastMatcher().DescribeOn(description); description.AppendText(")"); }
public override void DescribeOn(IDescription description) { DescribeToCallCount++; if (ExpectedDescribeToWriter != null) { Assert.AreSame(ExpectedDescribeToWriter, description, "DescribeTo writer"); } description.AppendText(DescribeToOutput); }
/// <summary> /// Writes the description of a failed match to the specified <paramref name="description"/>. /// </summary> /// <param name="description">The <see cref="TextWriter"/> where the description is written to.</param> /// <param name="actualValue">The actual value to be written.</param> /// <param name="matcher">The matcher which is used for the expected value to be written.</param> private static void WriteDescriptionOfFailedMatch(IDescription description, object actualValue, Matcher matcher) { description.AppendNewLine() .AppendText("Expected: "); matcher.DescribeOn(description); description.AppendNewLine() .AppendText("Actual: ") .AppendValue(actualValue); }
public void DescribeOn(IDescription description) { if (Equals(AllowAny)) description.AppendText("allowed"); else if (maximum == 1 && required == 1) DescribeExpected(description, "once"); else if (maximum == int.MaxValue && required == 1) DescribeExpected(description, "atleast once", required); else if (maximum == int.MaxValue && required > 1) DescribeExpected(description, "atleast {0} times", required); else if (maximum == required && required > 1) DescribeExpected(description, "exactly {0} times", required); else if (0 == required && maximum > 0) DescribeExpected(description,"at most {0} times", maximum); else if (Equals( NeverCardinality)) DescribeExpected(description,"never"); }
public InformationAboutCatalogItem(IDescription catalogItem, Uri path) : this() { ElementRenderer.VisualizeImageInPanel(this.PictureBoxContainer, catalogItem.Name, path); this.NameText.Text = catalogItem.Name; this.GenreText.Text = string.Join(", ", catalogItem.Genres); this.YearText.Text = catalogItem.ReleaseYear; bool isInStock = (catalogItem as IStockable).IsInStock; this.IsInStockText.Text = isInStock ? "Available" : "Not Available"; this.IsInStockText.Foreground = isInStock ? Brushes.Green : Brushes.Red; Button stockButton = null; if (catalogItem is ISaleable) { this.PriceImage.Visibility = Visibility.Visible; this.SellPriceTextBlock.Text = string.Format("{0:C}", (catalogItem as ISaleable).Price); this.SellButton.Visibility = Visibility.Visible; stockButton = this.SellButton; // Set Click event to Sell Button this.SellButton.Click += (sender, args) => { Basket.PurchasedItems.Add(catalogItem as ISaleable); }; } else if (catalogItem is IRentable) { this.PricePerDayImage.Visibility = Visibility.Visible; this.RentalPricePerDayTextBlock.Text = string.Format("{0:C}", (catalogItem as IRentable).PricePerDay); this.RentButton.Visibility = Visibility.Visible; stockButton = this.RentButton; // Set Click event to Rent Button this.RentButton.Click += (sender, args) => { RentOptionScreen rentScreen = new RentOptionScreen(catalogItem as IRentable); rentScreen.OldContent = this.Content; this.Content = rentScreen.Content; this.DataContext = rentScreen.DataContext; }; } if (stockButton != null && !isInStock) { stockButton.IsEnabled = false; } this.CloseButton.Focus(); }
public void DescribeUnmetExpectationsTo(IDescription writer) { writer.AppendLine("expectations:"); foreach (IExpectation expectation in expectations) { Indent(writer, depth + 1); expectation.DescribeUnmetExpectationsTo(writer); writer.AppendNewLine(); } }
public void DescribeOn(IDescription description) { description.AppendText(name); if (string.IsNullOrEmpty(currentState)) { description.AppendText(" has no current state"); } else { description.AppendText(" is ") .AppendText(currentState); } }
/// <summary> /// Generates an description based on template's name (interface or class type name is used as a key). /// </summary> /// <param name="description"><see cref="IDescription"/>'s concrete implementation.</param> /// <param name="templateName">Template's name</param> /// <exception cref="ArgumentNullException"> /// Thrown when derived <see cref="IDescription"/> interface implementation is null or template name wasn't given. /// </exception> /// <returns>Generated template's description (a class, interface, XML-file etc.) or null.</returns> public static string GenerateDescription(IDescription description, string templateName) { if (description == null) { throw new ArgumentNullException(nameof(description)); } if (templateName == null) { throw new ArgumentNullException(nameof(templateName)); } TemplateBase template; return TemplateStorage.Instance.Templates.TryGetValue(templateName, out template) ? new ClassGenerator(template).Generate(description) : null; }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public override void DescribeOn(IDescription description) { description.AppendText("element of ["); bool separate = false; foreach (object element in collection) { if (separate) { description.AppendText(", "); } description.AppendValue(element); separate = true; } description.AppendText("]"); }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public override void DescribeOn(IDescription description) { description.AppendText("? "); if (minComparisonResult == -1) { description.AppendText("<"); } if (maxComparisonResult == 1) { description.AppendText(">"); } if (minComparisonResult == 0 || maxComparisonResult == 0) { description.AppendText("="); } description.AppendText(" ") .AppendValue(value); }
/// <summary> /// Gets the generated template text based on <see cref="IDescription"/> implementation. /// </summary> /// <param name="description"><see cref="IDescription"/> implementation.</param> /// <exception cref="ArgumentNullException">Thrown when <see cref="IDescription"/> implementation is null.</exception> /// <returns>Generated template text</returns> public string Generate(IDescription description) { if (description == null) { throw new ArgumentNullException(nameof(description)); } var classTemplateString = ClassTemplate; classTemplateString = classTemplateString.Replace(MetadataParameters.ClassName, description.Name); classTemplateString = classTemplateString.Replace(MetadataParameters.DescriptionName, description.Description); var classDescription = description as ClassDescription; if (classDescription != null) { if (classDescription.IsDataAccessClass) { classTemplateString = classTemplateString.Replace(MetadataParameters.TableNameName, classDescription.TableName); classTemplateString = classTemplateString.Replace(MetadataParameters.SelectSqlName, classDescription.BuildSqlSelect); classTemplateString = classTemplateString.Replace(MetadataParameters.InsertSqlName, classDescription.BuildSqlInsert); classTemplateString = classTemplateString.Replace(MetadataParameters.UpdateSqlName, classDescription.BuildSqlUpdate); classTemplateString = classTemplateString.Replace(MetadataParameters.ParametersName, CreateParameters(classDescription).ToString()); } classTemplateString = classTemplateString.Replace(MetadataParameters.PropertiesName, CreateProperties(classDescription).ToString()); classTemplateString = classTemplateString.Replace(MetadataParameters.SovitusParametriName, CreateColumnNameParameters(classDescription).ToString()); } return classTemplateString; }
private void DescribeTo(IDescription writer) { DescribeMethod(writer); argumentsMatcher.DescribeOn(writer); foreach (Matcher extraMatcher in extraMatchers) { writer.AppendText(", "); extraMatcher.DescribeOn(writer); } if (actions.Count > 0) { writer.AppendText(", will "); ((IAction) actions[0]).DescribeOn(writer); for (int i = 1; i < actions.Count; i++) { writer.AppendText(", "); ((IAction) actions[i]).DescribeOn(writer); } } DescribeOrderingConstraintsOn(writer); sideEffects.ForEach(sideEffect => sideEffect.DescribeOn(writer)); if (!string.IsNullOrEmpty(expectationComment)) { writer.AppendText(" Comment: ") .AppendText(expectationComment); } }
private void DescribeInvocationCount(IDescription description, int count) { if(cardinality.Equals(Cardinality.Never())) return; description.AppendText(", "); if (count == 0 ) { description.AppendText("never invoked"); } else { description.AppendText("already invoked "); description.AppendText(count.ToString()); description.AppendText(" time"); if (count != 1) { description.AppendText("s"); } } }
public override void DescribeOn(IDescription description1) { description1.AppendText(description); }
private void DescribeMethod(IDescription description) { cardinality.DescribeOn(description); DescribeInvocationCount(description, callCount); description.AppendText(": ") .AppendText(receiver.MockName) .AppendText(methodSeparator); methodMatcher.DescribeOn(description); genericMethodTypeMatcher.DescribeOn(description); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> /// <param name="other">An object to compare with this object.</param> public bool Equals(IDescription other) { throw new NotImplementedException(); }
/// <summary> /// Compares the current object with another object of the same type. /// </summary> /// <returns> /// A value that indicates the relative order of the objects being compared. The return value has the following meanings: Value Meaning Less than zero This object is less than the <paramref name="other"/> parameter.Zero This object is equal to <paramref name="other"/>. Greater than zero This object is greater than <paramref name="other"/>. /// </returns> /// <param name="other">An object to compare with this object.</param> public int CompareTo(IDescription other) { throw new NotImplementedException(); }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public override void DescribeOn(IDescription description) { description.AppendText("<"); WriteListOfMatchers(MatcherCount(), description); description.AppendText(">"); }
/// <summary> /// Writes the list of matchers to a <see cref="TextWriter"/>. /// </summary> /// <param name="listLength">Length of the list.</param> /// <param name="writer">The writer.</param> protected void WriteListOfMatchers(int listLength, IDescription writer) { for (int i = 0; i < listLength; i++) { if (i > 0) { writer.AppendText(", "); } typeMatchers[i].DescribeOn(writer); } }
public void DescribeTo(IDescription desc) { m_action.Invoke(desc); }
public void DescribeOn(IDescription description) { description.AppendText("when "); predicate.DescribeOn(description); }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public override void DescribeOn(IDescription description) { description.AppendText(methodName); }
public void DescribeTo(IDescription desc) { if (desc != this)//prevent accidental self recursion { desc.Text(ToString()); } }
private void DescribeOrderingConstraintsOn(IDescription writer) { if (!orderingConstraints.Any()) return; writer.AppendText(" "); orderingConstraints.ForEach(constraint => constraint.DescribeOn(writer)); }