public override bool TryGetMember(GetMemberBinder binder, out object result) { if (_data.ContainsKey(binder.Name)) { result = _data[binder.Name]; var converted = ConvertResult(result); if (!ReferenceEquals(result, converted)) _data[binder.Name] = result = converted; return true; } if (_tableName == null) { result = null; return false; } var relatedAdapter = _database.Adapter as IAdapterWithRelation; if (relatedAdapter != null && relatedAdapter.IsValidRelation(_tableName, binder.Name)) { var relatedRows = relatedAdapter.FindRelated(_tableName, _data, binder.Name); if (relatedRows.Count() == 1 && !binder.Name.IsPlural()) { result = new SimpleRecord(relatedRows.Single(), binder.Name, _database); } else { result = new SimpleResultSet(relatedRows.Select(dict => new SimpleRecord(dict, binder.Name, _database))); } return true; } return base.TryGetMember(binder, out result); }
public void DynamicCastTest() { dynamic target = new SimpleRecord(); target.Name = "Bob"; target.Age = 42; User user = target; Assert.AreEqual("Bob", user.Name); Assert.AreEqual(42, user.Age); }
public void DynamicCastShouldReturnSameObjectOnSubsequentCalls() { dynamic target = new SimpleRecord(); target.Name = "Bob"; target.Age = 42; User user1 = target; User user2 = target; Assert.AreSame(user1, user2); }
public void DynamicRecordDictionaryConstructorTest() { IDictionary<string, object> data = new Dictionary<string, object> { { "Name", "Bob" }, { "Age", 42 } }; dynamic target = new SimpleRecord(data); Assert.AreEqual("Bob", target.Name); Assert.AreEqual(42, target.Age); }
public ActionResult Edit(int id, FormCollection collection) { dynamic record = new SimpleRecord(); record.Id = id; record.Duration = Convert.ToInt32(collection["Duration"]); record.Title = collection["Title"].Trim(); record.Content = collection["Content"].TrimEnd(); Database.Open().ChallengeTemplates.Update(record); return RedirectToAction("Index"); }
public void GivenIHaveTheFollowingEventsInTheDatabase(Table table) { dynamic db = GetTheDatabase(); var eventStoreRecords = table.CreateSet<EventStore>(); foreach (var record in eventStoreRecords) { dynamic recordToAdd = new SimpleRecord(); recordToAdd.Data = record.Data; recordToAdd.Sequence = record.Sequence; recordToAdd.EventDate = record.EventDate; recordToAdd.AggregateRootId = record.AggregateRootId; recordToAdd.EventType = record.EventType; db.EventStore.Insert(recordToAdd); } }
public override bool TryGetMember(GetMemberBinder binder, out object result) { if (_data.ContainsKey(binder.Name)) { result = _data[binder.Name]; var converted = ConvertResult(result); if (!ReferenceEquals(result, converted)) { _data[binder.Name] = result = converted; } return(true); } if (_tableName == null) { result = null; return(false); } var relatedAdapter = _database.Adapter as IAdapterWithRelation; if (relatedAdapter != null && relatedAdapter.IsValidRelation(_tableName, binder.Name)) { var relatedRows = relatedAdapter.FindRelated(_tableName, _data, binder.Name); if (relatedRows.Count() == 1 && !binder.Name.IsPlural()) { result = new SimpleRecord(relatedRows.Single(), binder.Name, _database); } else { result = new SimpleResultSet(relatedRows.Select(dict => new SimpleRecord(dict, binder.Name, _database))); } return(true); } return(base.TryGetMember(binder, out result)); }
public ActionResult Submit(int id, FormCollection collection) { if (IsAuthorized(id)) { dynamic db = Database.Open(); dynamic challenge = new SimpleRecord(); challenge.Id = id; challenge.Response = collection["Response"].Trim(); challenge.Submitted = DateTime.UtcNow; db.Challenges.Update(challenge); string challengeUrl = Url.Action("Index", "Challenge", new {id}, Request.Url.Scheme); Task.Factory.StartNew( () => EmailSender.SendChallengeCompletedEmail(ChallengeViewModel.FromId(id), challengeUrl)); } return RedirectToAction("Index", new {id}); }
public void DynamicRecordSetterTest() { dynamic target = new SimpleRecord(); target.Name = "Bob"; Assert.AreEqual("Bob", target.Name); }
private void UpdateAggregatesVersion(CommitAttempt attempt) { var aggregatesVersion = attempt.Events.GroupBy(x => x.AggregateId, x => x.AggregateVersion) .Select(x => new { AggregateId = x.Key, ActualVersion = x.Max() }); foreach (var aggregateVersion in aggregatesVersion) { dynamic record = new SimpleRecord(); record.AggregateId = aggregateVersion.AggregateId; record.Version = aggregateVersion.ActualVersion; this._db.Aggregates.Update(record); } }
public void DynamicRecordIndexerTest() { dynamic target = new SimpleRecord(); target.Name = "Bob"; Assert.AreEqual("Bob", target["Name"]); }