public void TestReferenceTypeKeyDuplicate() { string[] strings = new [] {"0", "1", "1"}; Assert.Throws<ArgumentException> (() => strings.ToDictionary (keySelector: it => it)); Assert.Throws<ArgumentException> (() => strings.ToDictionary (keySelector: it => it, elementSelector: it => it)); Assert.Throws<ArgumentException> (() => strings.ToDictionary (keySelector: it => it, comparer: EqualityComparer<string>.Default)); Assert.Throws<ArgumentException> (() => strings.ToDictionary (keySelector: it => it, elementSelector: it => it, comparer: EqualityComparer<string>.Default)); }
public void should_return_dictionary_containing_types_properties() { var anonymousType = new { Jelly = "Donut", Strings = "Guitar", Watson = "Holmes", Simon = "Garfunkel" }; anonymousType.ToDictionary().ShouldContainKeyAndValue("Jelly", "Donut"); anonymousType.ToDictionary().ShouldContainKeyAndValue("Strings", "Guitar"); anonymousType.ToDictionary().ShouldContainKeyAndValue("Watson", "Holmes"); anonymousType.ToDictionary().ShouldContainKeyAndValue("Simon", "Garfunkel"); }
public void TestReferenceType_NullKeyExceptions() { string[] strings = new [] {"0", "1", "2", "3", "4", "5", "6"}; IEqualityComparer<string> comparer = EqualityComparer<string>.Default; Func<string, string> nullKeyFunc = it => null; Func<string, string> func = it => it; Assert.Throws<ArgumentNullException> (() => strings.ToDictionary<string, string> (keySelector: nullKeyFunc)); Assert.Throws<ArgumentNullException> (() => strings.ToDictionary<string, string> (keySelector: nullKeyFunc, comparer: comparer)); Assert.Throws<ArgumentNullException> (() => strings.ToDictionary<string, string, string> (keySelector: nullKeyFunc, elementSelector: func)); Assert.Throws<ArgumentNullException> (() => strings.ToDictionary<string, string, string> (keySelector: nullKeyFunc, elementSelector: func, comparer: comparer)); }
/// <summary> /// Initializes a new instance of the <see cref="RiskPanel"/>. /// </summary> public RiskPanel() { InitializeComponent(); var ruleTypes = new[] { typeof(RiskCommissionRule), typeof(RiskOrderFreqRule), typeof(RiskOrderPriceRule), typeof(RiskOrderVolumeRule), typeof(RiskPnLRule), typeof(RiskPositionSizeRule), typeof(RiskPositionTimeRule), typeof(RiskSlippageRule), typeof(RiskTradeFreqRule), typeof(RiskTradePriceRule), typeof(RiskTradeVolumeRule) }; _names.AddRange(ruleTypes.ToDictionary(t => t, t => t.GetDisplayName())); TypeCtrl.ItemsSource = _names; TypeCtrl.SelectedIndex = 0; var itemsSource = new ObservableCollectionEx<RuleItem>(); RuleGrid.ItemsSource = itemsSource; _rules = new ConvertibleObservableCollection<IRiskRule, RuleItem>(new ThreadSafeObservableCollection<RuleItem>(itemsSource), CreateItem); }
public void TableMapping_ColumnsCount_Contracts() { using (var ctx = GetContext()) { var allTypes = new[] { typeof (ContractBase), typeof (Contract), typeof (ContractFixed), typeof (ContractStock), typeof (ContractKomb1), typeof (ContractKomb2), }; var mappings = allTypes.ToDictionary(x => x, ctx.Db); using (var dataTable = DataTableHelper.Create(mappings, new ContractBase[0])) { foreach (DataColumn column in dataTable.Columns) { Console.WriteLine(column.ColumnName); } Assert.AreEqual(34, dataTable.Columns.Count); } } }
public LoanApprovalUserControl() { InitializeComponent(); var statuses = new[] { OContractStatus.Pending, OContractStatus.Validated, OContractStatus.Refused, OContractStatus.Abandoned, OContractStatus.Deleted, OContractStatus.Postponed }; var resourceManager = new ResourceManager("OpenCBS.Extensions.Resources.Extensions", GetType().Assembly); var dict = statuses.ToDictionary(x => x, x => resourceManager.GetString(x.ToString())); _statusComboBox.DisplayMember = "Value"; _statusComboBox.ValueMember = "Key"; _statusComboBox.DataSource = new BindingSource(dict, null); _statusComboBox.SelectedIndex = 0; _saveButton.Click += (sender, args) => { if (SaveLoanApproval == null) return; SaveLoanApproval(); }; this._dateTimePicker.Format = DateTimePickerFormat.Custom; this._dateTimePicker.CustomFormat = ApplicationSettings.GetInstance("").SHORT_DATE_FORMAT; }
/// <summary> /// Initializes a new instance of the <see cref="CommissionPanel"/>. /// </summary> public CommissionPanel() { InitializeComponent(); var itemsSource = new ObservableCollectionEx<RuleItem>(); RuleGrid.ItemsSource = itemsSource; _rules = new ConvertibleObservableCollection<ICommissionRule, RuleItem>(new ThreadSafeObservableCollection<RuleItem>(itemsSource), CreateItem); var ruleTypes = new[] { typeof(CommissionPerOrderCountRule), typeof(CommissionPerOrderRule), typeof(CommissionPerOrderVolumeRule), typeof(CommissionPerTradeCountRule), typeof(CommissionPerTradePriceRule), typeof(CommissionPerTradeRule), typeof(CommissionPerTradeVolumeRule), typeof(CommissionSecurityIdRule), typeof(CommissionSecurityTypeRule), typeof(CommissionTurnOverRule), typeof(CommissionBoardCodeRule) }; _names.AddRange(ruleTypes.ToDictionary(t => t, t => t.GetDisplayName())); TypeCtrl.ItemsSource = _names; TypeCtrl.SelectedIndex = 0; }
public BinaryLogicalOperator(IElementCreationContext context, BinaryLogicalOperatorType defaultType) : base(context, context.Owner.GetBooleanType()) { ParameterA = context.Owner.CreateParameter("a", context.Owner.GetBooleanType()); ParameterB = context.Owner.CreateParameter("b", context.Owner.GetBooleanType()); Parameters.Add(ParameterA); Parameters.Add(ParameterB); var services = new[] { new BinaryLogicalOperatorService(BinaryLogicalOperatorType.And, "And", (a, b) => a && b), new BinaryLogicalOperatorService(BinaryLogicalOperatorType.Or, "Or", (a, b) => a || b), }; foreach (var service in services) { AddAction(new ElementAction(service.Text, () => OperatorType = service.Type)); } _services = services.ToDictionary(s => s.Type, s => s); OperatorType = defaultType; if (!string.IsNullOrWhiteSpace(context.Data)) { var data = JsonConvert.DeserializeObject<BinaryLogicalOperatorData>(context.Data); OperatorType = data.OperatorType; } }
public static void Main(string[] args) { var parser = new Parser(); Directory.SetCurrentDirectory(@"C:\dev\oss\less.js\test\less"); var files = new[] { "colors", "comments", "css", "css-3", "lazy-eval", "mixins", "mixins-args", "operations", "parens", "rulesets", "scope", "selectors", "strings", "variables", "whitespace" } .Select(f => f + ".less"); var contents = files .ToDictionary(f => f, f => File.ReadAllText(f)); const int rounds = 150; Func<string, int> runTest = file => Enumerable .Range(0, rounds) .Select(i => { var starttime = DateTime.Now; parser.Parse(contents[file]).ToCSS(null); var duration = (DateTime.Now - starttime); return duration.Milliseconds; }) .Sum(); Console.WriteLine("Press Enter to begin benchmark"); Console.ReadLine(); Console.WriteLine("Running each test {0} times", rounds); foreach (var file in files) { var size = rounds*contents[file].Length/1024d; Console.Write("{0} : {1,7:#,##0.00} Kb ", file.PadRight(18), size); var time = runTest(file)/1000d; Console.WriteLine("{0,6:#.00} s {1,8:#,##0.00} Kb/s", time, size/time); } // Console.Read(); }
public void ToDictionaryKeyEqualityComparer_CaseInsensitiveEqualityComparer_Throws() { var instance = new[] { new KeyValuePair<string, int>("a", 1), new KeyValuePair<string, int>("b", 2), new KeyValuePair<string, int>("A", 3) }; var actual = instance.ToDictionary(StringComparer.InvariantCultureIgnoreCase); }
public void TestMethod() { var doclist = new[] { new {RelatingDocument = "Doc1", RelatedObjects = new List<string>() { "Ent1", "Ent2", "Ent3", "Ent4", "Ent5" } }, new {RelatingDocument = "Doc1", RelatedObjects = new List<string>() { "Ent1", "Ent6", "Ent7" } }, new {RelatingDocument = "Doc1", RelatedObjects = new List<string>() { "Ent8", "Ent9" } }, new {RelatingDocument = "Doc2", RelatedObjects = new List<string>() { "Ent1", "Ent6", "Ent7" } }, new {RelatingDocument = "Doc3", RelatedObjects = new List<string>() { "Ent1", "Ent6" } }, new {RelatingDocument = "Doc4", RelatedObjects = new List<string>() { "Ent1", "Ent2", "Ent7" } }, new {RelatingDocument = "Doc5", RelatedObjects = new List<string>() { "Ent1", "Ent2", "Ent3" } }, new {RelatingDocument = "Doc1", RelatedObjects = new List<string>() { "Ent10", "Ent11" } }, new {RelatingDocument = "Doc2", RelatedObjects = new List<string>() { "Ent10", "Ent11" } }, }.ToList(); Dictionary<string, List<string>> dic = null; //check for duplicates var dups = doclist.GroupBy(d => d.RelatingDocument).SelectMany(grp => grp.Skip(1)); //combine object lists to single key value, merge lists var dupsMerge = dups.GroupBy(d => d.RelatingDocument).Select(p => new { x = p.Key, y = p.SelectMany(c => c.RelatedObjects) }); if (dupsMerge.Any()) { //remove the duplicates and convert to dictionary dic = doclist.Except(dups).ToDictionary(p => p.RelatingDocument, p => p.RelatedObjects); //add the duplicate doc referenced object lists to the original doc foreach (var item in dupsMerge) { dic[item.x] = dic[item.x].Union(item.y).ToList(); } } else { //no duplicates, so just convert to dictionary dic = doclist.ToDictionary(p => p.RelatingDocument, p => p.RelatedObjects); } //reverse lookup to entity to list of documents var newDic = dic .SelectMany(pair => pair.Value .Select(val => new { Key = val, Value = pair.Key })) .GroupBy(item => item.Key) .ToDictionary(gr => gr.Key, gr => gr.Select(item => item.Value)); Assert.AreEqual(newDic["Ent1"].Count(), 5); Assert.AreEqual(newDic["Ent2"].Count(), 3); Assert.AreEqual(newDic["Ent3"].Count(), 2); Assert.AreEqual(newDic["Ent4"].Count(), 1); Assert.AreEqual(newDic["Ent5"].Count(), 1); Assert.AreEqual(newDic["Ent6"].Count(), 3); Assert.AreEqual(newDic["Ent7"].Count(), 3); Assert.AreEqual(newDic["Ent8"].Count(), 1); Assert.AreEqual(newDic["Ent9"].Count(), 1); Assert.AreEqual(newDic["Ent10"].Count(), 2); Assert.AreEqual(newDic["Ent11"].Count(), 2); }
public void Linq56() { var scoreRecords = new[] { new {Name = "Alice", Score = 50}, new {Name = "Bob" , Score = 40}, new {Name = "Cathy", Score = 45} }; var scoreRecordsDict = scoreRecords.ToDictionary(sr => sr.Name); Console.WriteLine("Bob's score: {0}", scoreRecordsDict["Bob"]); }
public void AnonToDict() { object anon = new { width = 30, length = 45 }; Dictionary<string, object> dict = anon.ToDictionary(); Assert.IsTrue(dict.ContainsKey("width")); Assert.AreEqual(30, (int)dict["width"]); Assert.IsTrue(dict.ContainsKey("length")); Assert.AreEqual(45, (int)dict["length"]); }
public void TestReferenceType_ReferenceKey() { string[] strings = new [] {"0", "1", "2", "3", "4", "5", "6"}; Dictionary<string, string> dict = strings.ToDictionary (keySelector: it => it); Assert.That (dict.Count, Is.EqualTo (strings.Length)); foreach (string element in strings) { Assert.That (dict [element], Is.EqualTo (element)); } }
public void ToDictionaryNoEqualityComparer_TwoKeysOnlyCaseDifferent_ReturnsDictionaryOfSourceLength() { var instance = new[] { new KeyValuePair<string, int>("a", 1), new KeyValuePair<string, int>("b", 2), new KeyValuePair<string, int>("A", 3) }; var expected = 3; var actual = instance.ToDictionary().Count; Assert.AreEqual(expected, actual); }
public void TestReferenceType_ReferenceKey_Comparer() { IEqualityComparer<string> comparer = EqualityComparer<string>.Default; string[] strings = new [] {"0", "1", "2", "3", "4", "5", "6"}; Dictionary<string, string> dict = strings.ToDictionary (keySelector: it => it, comparer: comparer); Assert.That (dict.Count, Is.EqualTo (strings.Length)); foreach (string element in strings) { Assert.That (dict [element], Is.EqualTo (element)); } }
public void PopulateEntityRelationStorage_OneRelationMatches () { var aPersons = new[] { new PersonA (new Identifier<int> (1), "Homer", 49, 1), new PersonA (new Identifier<int> (2), "Marge", 49, 1), // Just one of those two is allowed to match new PersonA (new Identifier<int> (4), "Marge", 49, 1), // Just one of those two is allowed to match new PersonA (new Identifier<int> (3), "Bart", 8, 1), }; var bPersons = new[] { new PersonB (new Identifier<string> ("one"), "Homerx", "49", "1"), new PersonB (new Identifier<string> ("two"), "Marge", "49", "1"), new PersonB (new Identifier<string> ("three"), "Bart", "9", "1"), }; var atypeIdEqualityComparer = new IdentifierEqualityComparer<int>(); var btypeIdEqualityComparer = new IdentifierEqualityComparer<string>(); var atypeEntityVersions = aPersons.ToDictionary (p => p.Id, p => p.Version, atypeIdEqualityComparer); var btypeEntityVersions = bPersons.ToDictionary (p => p.Id, p => p.Version, btypeIdEqualityComparer); var allAtypeEntities = aPersons.ToDictionary (p => p.Id, atypeIdEqualityComparer); var allBtypeEntities = bPersons.ToDictionary (p => p.Id, btypeIdEqualityComparer); var foundRelations = new TestInitialEntityMatcher (btypeIdEqualityComparer).FindMatchingEntities ( new PersonAPersonBRelationDataFactory(), allAtypeEntities, allBtypeEntities, atypeEntityVersions, btypeEntityVersions); Assert.That (foundRelations.Count, Is.EqualTo (1)); var relation = foundRelations[0]; Assert.That (relation.AtypeId.Value, Is.EqualTo (2).Or.EqualTo (4)); // Depends on the implementation which one matches Assert.That (relation.AtypeVersion, Is.EqualTo (1)); Assert.That (relation.BtypeId.Value, Is.EqualTo ("two")); Assert.That (relation.BtypeVersion, Is.EqualTo ("1")); }
//This sample uses ToDictionary to immediately evaluate a sequence and a //related key expression into a dictionary. // //Output: //Bob's score: 40 public static void Example() { var scoreRecords = new[] { new {Name = "Alice", Score = 50}, new {Name = "Bob", Score = 40}, new {Name = "Cathy", Score = 45} }; var scoreRecordsDict = scoreRecords.ToDictionary(sr => sr.Name); Console.WriteLine($"Bob's score: {scoreRecordsDict["Bob"].Score}"); }
private string GetJson() { var metrics = new { system = System.ToDictionary(t => t.Value.Item1, t => GetDynamicValue(t.Value.Item2)), environment = Environment.ToDictionary(t => t.Value.Item1, t => GetDynamicValue(t.Value.Item2)), counters = Counters.ToDictionary(t => t.Value.Item1, t => GetDynamicValue(t.Value.Item2)), tasks = Tasks.ToDictionary(t => t.Value.Item1, t => GetDynamicValue(t.Value.Item2)), eventLog = EventLog.ToDictionary(t => t.Value.Item1, t => GetDynamicValue(t.Value.Item2)), }; return(JsonConvert.SerializeObject(metrics, Formatting.Indented)); }
public void ToDictionary_Should_Return_5_Items_For_Test_Object() { var tester = new { thing1 = "test", thing2 = DateTime.Now, thing3 = 1, thing4 = 2.03M, thing5 = Guid.NewGuid() }; var result = tester.ToDictionary(); Assert.Equal(5, result.Count); }
void Main() { IEnumerable<Recipe> recipes = new[] { new Recipe {Id = 1, Name = "Apple Pie", Rating = 5}, new Recipe {Id = 2, Name = "Cherry Pie", Rating = 2}, new Recipe {Id = 3, Name = "Beef Pie", Rating = 3} }; Dictionary<int, Recipe> dictionaries = recipes.ToDictionary(x => x.Id); foreach (var d in dictionaries) Console.WriteLine("key = " + d.Key + ", Name = " + d.Value.Name); var digits = Enumerable.Range(10, 20).Where(x => x % 2 == 0 && x % 3 == 0); var result = digits.Aggregate(0, (currentElement, runningTotal) => runningTotal + currentElement); Console.WriteLine("result: " + result); foreach (int i in digits) Console.WriteLine(i); var someNumbers = Enumerable.Range(1, 10000000).ToArray(); var sw = new Stopwatch(); sw.Start(); someNumbers.Where(x => x.ToString().Contains("3")).ToArray(); sw.Stop(); Console.WriteLine("Non PLINQ query took {0} ms", sw.ElapsedMilliseconds); sw.Restart(); someNumbers.AsParallel().Where(x => x.ToString().Contains("3")).ToArray(); sw.Stop(); Console.WriteLine("PLINQ query took {0} ms", sw.ElapsedMilliseconds); var inputNumbers = Enumerable.Range(1, 10).ToArray(); Console.WriteLine("Input numbers"); foreach (var num in inputNumbers) { Console.Write(num + " "); } var outputNumbers = inputNumbers.AsParallel().Select(x => x); Console.WriteLine(); Console.WriteLine("Output numbers"); foreach (var num in outputNumbers) { Console.Write(num + " "); } }
public static void Main() { // return RedirectToAction("Index", "Home", new { id = 1, query = "age" }) var myClas = new MyClass { Integer = 1000 }; var obj = new { id = 1, query = "age" }; var obj2 = new { id = 1, query = "age" }; var result = obj.ToDictionary(); var result2 = obj2.ToDictionary(); }
public void BuildHeap2() { var a = new[] { "a", "b", "c", "aB", "Ab", "bB", "BB", "abc" }; Dictionary<string, int> dictionary = a.ToDictionary(s => s, s => s.GetHashCode(), StringComparer.Ordinal); var comparer = StringComparer.OrdinalIgnoreCase; var binaryHeap = BinaryHeap<string, int>.Build(dictionary, comparer); var expected = a.OrderBy(s => s, comparer).ToArray(); for (int i = 0; i < a.Length; i++) { var min = binaryHeap.ExtractMin(); Assert.Equal(expected[i], min.Key, comparer); Assert.Equal(dictionary[min.Key], min.Value); } }
public void NameRefTypePropergation() { var hogeDecl = new Declare("THoge", "hoge", null); var hageDecl = new Declare("THage", "hage", null); var decls = new[] {hogeDecl, hageDecl}; SemanticProcessor.Initialize( decls.ToDictionary(decl=>decl.Name ) ); var concat = new Concat(new List<SyntaxNode> { new NameReference("hoge"), new NameReference("hage") }); var sem = concat.ToSemanticNode(); sem.IsNotNull(); sem.Nodes[0].Type.Is( "THoge" ); sem.Nodes[1].Type.Is( "THage" ); }
public void ObjectExtensions_Object_To_Dictionary() { //Arrange var obj = new { Key1 = "value1", Key2 = "value2", Key3 = "value3" }; //Act var d = obj.ToDictionary<string>(); //Assert Assert.IsTrue(d.Keys.Contains("Key1")); Assert.IsTrue(d.Keys.Contains("Key2")); Assert.IsTrue(d.Keys.Contains("Key3")); Assert.AreEqual(d["Key1"], "value1"); Assert.AreEqual(d["Key2"], "value2"); Assert.AreEqual(d["Key3"], "value3"); }
public void InsertTest1() { var a = new[] { "bb", "a", "b", "aB", "Ab", "bB", "BB", "abc" }; Dictionary<string, int> dictionary = a.ToDictionary(s => s, s => s.GetHashCode(), StringComparer.Ordinal); var comparer = StringComparer.OrdinalIgnoreCase; var binaryHeap = new BinaryHeap<string, int>(comparer); foreach (var p in dictionary) { binaryHeap.Insert(p.Key, p.Value); } var expected = a.OrderBy(s => s, comparer).ToArray(); for (int i = 0; i < a.Length; i++) { var min = binaryHeap.ExtractMin(); Assert.Equal(expected[i], min.Key, comparer); Assert.Equal(dictionary[min.Key], min.Value); } }
public void Adds_when_model_does_not_exist_in_database() { Database.AddTestModelsToDatabase(TestModels); var newModels = new[] { new TestModel("New name 1", Guid.NewGuid()), new TestModel("New name 2", Guid.NewGuid()) }; var models = newModels.ToDictionary(m => m.Id, m => m); var addOrUpdateTask = Database.ModelCommands.AddOrUpdateManyAsync(models); addOrUpdateTask.Wait(); var getTask = Database.ModelQueries.GetManyAsync(m => models.Keys.Contains(m.Id)); getTask.Wait(); var results = getTask.Result.ToList(); AssertResults.Match(results, newModels); }
public BinaryOperator(IElementCreationContext context, BinaryOperatorType defaultOperatorType) : base(context, context.Owner.GetFloatType()) { var services = new [] { new BinaryOperatorService(BinaryOperatorType.Addition, "+", (a, b) => a + b), new BinaryOperatorService(BinaryOperatorType.Subtraction, "-", (a, b) => a - b), new BinaryOperatorService(BinaryOperatorType.Multiplication, "*", (a, b) => a * b), new BinaryOperatorService(BinaryOperatorType.Division, "/", (a, b) => a / b), new BinaryOperatorService(BinaryOperatorType.ShiftLeft, "<<", (a, b) => a << b), new BinaryOperatorService(BinaryOperatorType.ShiftRight, ">>", (a, b) => a >> b), new BinaryOperatorService(BinaryOperatorType.BitwiseAnd, "&", (a , b) => a & b), new BinaryOperatorService(BinaryOperatorType.BitwiseOr, "|", (a , b) => a | b), new BinaryOperatorService(BinaryOperatorType.Modulus, "%", (a , b) => a % b), }; foreach (var service in services) { AddAction(new ElementAction(service.Text, () => OperatorType = service.Type)); } _services = services.ToDictionary(s => s.Type, s => s); ParameterA = context.Owner.CreateParameter("a", context.Owner.GetFloatType()); ParameterB = context.Owner.CreateParameter("b", context.Owner.GetFloatType()); Parameters.Add(ParameterA); Parameters.Add(ParameterB); Service = _services[BinaryOperatorType.Addition]; OperatorType = defaultOperatorType; if (!string.IsNullOrWhiteSpace(context.Data)) { var data = JsonConvert.DeserializeObject<BinaryOperatorData>(context.Data); OperatorType = data.OperatorType; } }
/// <summary> /// 提供处理请求的对象。 /// </summary> /// <returns> /// 一个处理请求的对象。 /// </returns> /// <param name="requestContext">一个对象,封装有关请求的信息。</param> public IHttpHandler GetHttpHandler(RequestContext requestContext) { if (_mappingFiles == null) { lock (this) { if (_mappingFiles == null) { var paths = new[] { "/Modules/Rabbit.Resources/Content/font-awesome/fonts", "/Modules/Rabbit.Resources/Content/fonts" }; _mappingFiles = paths.ToDictionary(i => i, i => { var p = requestContext.HttpContext.Server.MapPath(i); return Directory.Exists(p) ? Directory.GetFiles(p) : null; }).Where(i => i.Value != null).ToDictionary(i => i.Key, i => i.Value); } } } var dataKey = "resource"; var resource = !requestContext.RouteData.Values.ContainsKey(dataKey) ? null : requestContext.RouteData.GetRequiredString(dataKey); var path = string.IsNullOrWhiteSpace(resource) ? null : MappingDictionary.GetOrAdd(resource, k => { var item = _mappingFiles.Select(i => { var file = i.Value.FirstOrDefault( z => string.Equals(Path.GetFileName(z), resource, StringComparison.OrdinalIgnoreCase)); return new KeyValuePair<string, string>(i.Key, file); }).FirstOrDefault(i => !string.IsNullOrEmpty(i.Value)); return item.Key + "/" + resource; }); return new RedirectHandler(path); }
static PinMapping() { var mapping = /* Value is not used but required for anonymous type */ new[]{ new { Processor = ProcessorPin.Pin0, Connector = ConnectorPin.P1Pin03 }}; if (GpioConnectionSettings.BoardConnectorRevision == 1) mapping = new[] { new {Processor = ProcessorPin.Pin0, Connector = ConnectorPin.P1Pin3}, new {Processor = ProcessorPin.Pin1, Connector = ConnectorPin.P1Pin5}, new {Processor = ProcessorPin.Pin4, Connector = ConnectorPin.P1Pin7}, new {Processor = ProcessorPin.Pin7, Connector = ConnectorPin.P1Pin26}, new {Processor = ProcessorPin.Pin8, Connector = ConnectorPin.P1Pin24}, new {Processor = ProcessorPin.Pin9, Connector = ConnectorPin.P1Pin21}, new {Processor = ProcessorPin.Pin10, Connector = ConnectorPin.P1Pin19}, new {Processor = ProcessorPin.Pin11, Connector = ConnectorPin.P1Pin23}, new {Processor = ProcessorPin.Pin14, Connector = ConnectorPin.P1Pin8}, new {Processor = ProcessorPin.Pin15, Connector = ConnectorPin.P1Pin10}, new {Processor = ProcessorPin.Pin17, Connector = ConnectorPin.P1Pin11}, new {Processor = ProcessorPin.Pin18, Connector = ConnectorPin.P1Pin12}, new {Processor = ProcessorPin.Pin21, Connector = ConnectorPin.P1Pin13}, new {Processor = ProcessorPin.Pin22, Connector = ConnectorPin.P1Pin15}, new {Processor = ProcessorPin.Pin23, Connector = ConnectorPin.P1Pin16}, new {Processor = ProcessorPin.Pin24, Connector = ConnectorPin.P1Pin18}, new {Processor = ProcessorPin.Pin25, Connector = ConnectorPin.P1Pin22} }; else if (GpioConnectionSettings.BoardConnectorRevision == 2) mapping = new[] { new {Processor = ProcessorPin.Pin2, Connector = ConnectorPin.P1Pin3}, new {Processor = ProcessorPin.Pin3, Connector = ConnectorPin.P1Pin5}, new {Processor = ProcessorPin.Pin4, Connector = ConnectorPin.P1Pin7}, new {Processor = ProcessorPin.Pin7, Connector = ConnectorPin.P1Pin26}, new {Processor = ProcessorPin.Pin8, Connector = ConnectorPin.P1Pin24}, new {Processor = ProcessorPin.Pin9, Connector = ConnectorPin.P1Pin21}, new {Processor = ProcessorPin.Pin10, Connector = ConnectorPin.P1Pin19}, new {Processor = ProcessorPin.Pin11, Connector = ConnectorPin.P1Pin23}, new {Processor = ProcessorPin.Pin14, Connector = ConnectorPin.P1Pin8}, new {Processor = ProcessorPin.Pin15, Connector = ConnectorPin.P1Pin10}, new {Processor = ProcessorPin.Pin17, Connector = ConnectorPin.P1Pin11}, new {Processor = ProcessorPin.Pin18, Connector = ConnectorPin.P1Pin12}, new {Processor = ProcessorPin.Pin27, Connector = ConnectorPin.P1Pin13}, new {Processor = ProcessorPin.Pin22, Connector = ConnectorPin.P1Pin15}, new {Processor = ProcessorPin.Pin23, Connector = ConnectorPin.P1Pin16}, new {Processor = ProcessorPin.Pin24, Connector = ConnectorPin.P1Pin18}, new {Processor = ProcessorPin.Pin25, Connector = ConnectorPin.P1Pin22}, new {Processor = ProcessorPin.Pin28, Connector = ConnectorPin.P5Pin3}, new {Processor = ProcessorPin.Pin29, Connector = ConnectorPin.P5Pin4}, new {Processor = ProcessorPin.Pin30, Connector = ConnectorPin.P5Pin5}, new {Processor = ProcessorPin.Pin31, Connector = ConnectorPin.P5Pin6} }; else //if (GpioConnectionSettings.BoardConnectorRevision == 3) mapping = new[] { new {Processor = ProcessorPin.Pin2, Connector = ConnectorPin.P1Pin3}, new {Processor = ProcessorPin.Pin3, Connector = ConnectorPin.P1Pin5}, new {Processor = ProcessorPin.Pin4, Connector = ConnectorPin.P1Pin7}, new {Processor = ProcessorPin.Pin5, Connector = ConnectorPin.P1Pin29}, new {Processor = ProcessorPin.Pin6, Connector = ConnectorPin.P1Pin31}, new {Processor = ProcessorPin.Pin7, Connector = ConnectorPin.P1Pin26}, new {Processor = ProcessorPin.Pin8, Connector = ConnectorPin.P1Pin24}, new {Processor = ProcessorPin.Pin9, Connector = ConnectorPin.P1Pin21}, new {Processor = ProcessorPin.Pin10, Connector = ConnectorPin.P1Pin19}, new {Processor = ProcessorPin.Pin11, Connector = ConnectorPin.P1Pin23}, new {Processor = ProcessorPin.Pin12, Connector = ConnectorPin.P1Pin32}, new {Processor = ProcessorPin.Pin13, Connector = ConnectorPin.P1Pin33}, new {Processor = ProcessorPin.Pin14, Connector = ConnectorPin.P1Pin8}, new {Processor = ProcessorPin.Pin15, Connector = ConnectorPin.P1Pin10}, new {Processor = ProcessorPin.Pin16, Connector = ConnectorPin.P1Pin36}, new {Processor = ProcessorPin.Pin17, Connector = ConnectorPin.P1Pin11}, new {Processor = ProcessorPin.Pin18, Connector = ConnectorPin.P1Pin12}, new {Processor = ProcessorPin.Pin19, Connector = ConnectorPin.P1Pin35}, new {Processor = ProcessorPin.Pin20, Connector = ConnectorPin.P1Pin38}, new {Processor = ProcessorPin.Pin21, Connector = ConnectorPin.P1Pin40}, new {Processor = ProcessorPin.Pin22, Connector = ConnectorPin.P1Pin15}, new {Processor = ProcessorPin.Pin23, Connector = ConnectorPin.P1Pin16}, new {Processor = ProcessorPin.Pin24, Connector = ConnectorPin.P1Pin18}, new {Processor = ProcessorPin.Pin25, Connector = ConnectorPin.P1Pin22}, new {Processor = ProcessorPin.Pin26, Connector = ConnectorPin.P1Pin37}, new {Processor = ProcessorPin.Pin27, Connector = ConnectorPin.P1Pin13}, }; processorMappings = mapping.ToDictionary(p => p.Connector, p => p.Processor); connectorMappings = mapping.ToDictionary(p => p.Processor, p => p.Connector); }
public void Throws_when_model_does_not_exist_in_database() { Database.AddTestModelsToDatabase(TestModels); var updatedModels = new[] { new TestModel("Updated name 1", Guid.NewGuid()), new TestModel("Updated name 2", Guid.NewGuid()) }; var models = updatedModels.ToDictionary(m => m.Id, m => m); Assert.That( () => Task.Run(() => Database.ModelCommands.UpdateManyAsync(models)).Wait(), Throws.TypeOf<AggregateException>().With.InnerException.TypeOf<DatabaseException>()); }