public void ChangeTracking_RejectChanges_Test() { var resource = new SDataResource {{"FirstName", "Joe"}, {"LastName", "Bloggs"}}; resource.AcceptChanges(); Assert.That(resource.IsChanged, Is.False); Assert.That(resource.GetChanges(), Is.Null); resource.Remove("LastName"); resource["FirstName"] = "Jill"; resource.Add("Age", 33); Assert.That(resource.IsChanged, Is.True); Assert.That(resource.GetChanges(), Is.Not.Null); resource.RejectChanges(); Assert.That(resource.IsChanged, Is.False); Assert.That(resource.GetChanges(), Is.Null); }
public void ChangeTracking_RejectChanges_Test() { var resource = new SDataResource { { "FirstName", "Joe" }, { "LastName", "Bloggs" } }; resource.AcceptChanges(); Assert.That(resource.IsChanged, Is.False); Assert.That(resource.GetChanges(), Is.Null); resource.Remove("LastName"); resource["FirstName"] = "Jill"; resource.Add("Age", 33); Assert.That(resource.IsChanged, Is.True); Assert.That(resource.GetChanges(), Is.Not.Null); resource.RejectChanges(); Assert.That(resource.IsChanged, Is.False); Assert.That(resource.GetChanges(), Is.Null); }
public void ChangeTracking_Test() { var resource = new SDataResource { { "FirstName", "Joe" }, { "LastName", "Bloggs" } }; resource.AcceptChanges(); Assert.That(resource.IsChanged, Is.False); Assert.That(resource.GetChanges(), Is.Null); resource["FirstName"] = "Jill"; Assert.That(resource.IsChanged, Is.True); Assert.That(resource.GetChanges(), Is.EqualTo(new Dictionary <string, object> { { "FirstName", "Jill" } })); resource.Add("Age", 33); Assert.That(resource.IsChanged, Is.True); Assert.That(resource.GetChanges(), Is.EqualTo(new Dictionary <string, object> { { "FirstName", "Jill" }, { "Age", 33 } })); }
public void ChangeTracking_Nested_Test() { var nested = new SDataResource { { "Country", "Australia" }, { "City", "Melbourne" } }; var resource = new SDataResource { { "Address", nested } }; resource.AcceptChanges(); Assert.That(nested.IsChanged, Is.False); Assert.That(nested.GetChanges(), Is.Null); Assert.That(resource.IsChanged, Is.False); Assert.That(resource.GetChanges(), Is.Null); nested["City"] = "Sydney"; Assert.That(nested.IsChanged, Is.True); Assert.That(nested.GetChanges(), Is.EqualTo(new Dictionary <string, object> { { "City", "Sydney" } })); Assert.That(resource.IsChanged, Is.True); var changes = (IDictionary <string, object>)resource.GetChanges(); Assert.That(changes.Count, Is.EqualTo(1)); Assert.That(changes["Address"], Is.EqualTo(new Dictionary <string, object> { { "City", "Sydney" } })); nested.Add("State", "VIC"); Assert.That(nested.IsChanged, Is.True); Assert.That(nested.GetChanges(), Is.EqualTo(new Dictionary <string, object> { { "City", "Sydney" }, { "State", "VIC" } })); Assert.That(resource.IsChanged, Is.True); changes = (IDictionary <string, object>)resource.GetChanges(); Assert.That(changes.Count, Is.EqualTo(1)); Assert.That(changes["Address"], Is.EqualTo(new Dictionary <string, object> { { "City", "Sydney" }, { "State", "VIC" } })); }
public void ChangeTracking_Nested_Test() { var nested = new SDataResource {{"Country", "Australia"}, {"City", "Melbourne"}}; var resource = new SDataResource {{"Address", nested}}; resource.AcceptChanges(); Assert.That(nested.IsChanged, Is.False); Assert.That(nested.GetChanges(), Is.Null); Assert.That(resource.IsChanged, Is.False); Assert.That(resource.GetChanges(), Is.Null); nested["City"] = "Sydney"; Assert.That(nested.IsChanged, Is.True); Assert.That(nested.GetChanges(), Is.EqualTo(new Dictionary<string, object> {{"City", "Sydney"}})); Assert.That(resource.IsChanged, Is.True); var changes = (IDictionary<string, object>) resource.GetChanges(); Assert.That(changes.Count, Is.EqualTo(1)); Assert.That(changes["Address"], Is.EqualTo(new Dictionary<string, object> {{"City", "Sydney"}})); nested.Add("State", "VIC"); Assert.That(nested.IsChanged, Is.True); Assert.That(nested.GetChanges(), Is.EqualTo(new Dictionary<string, object> {{"City", "Sydney"}, {"State", "VIC"}})); Assert.That(resource.IsChanged, Is.True); changes = (IDictionary<string, object>) resource.GetChanges(); Assert.That(changes.Count, Is.EqualTo(1)); Assert.That(changes["Address"], Is.EqualTo(new Dictionary<string, object> {{"City", "Sydney"}, {"State", "VIC"}})); }
public void ChangeTracking_Test() { var resource = new SDataResource {{"FirstName", "Joe"}, {"LastName", "Bloggs"}}; resource.AcceptChanges(); Assert.That(resource.IsChanged, Is.False); Assert.That(resource.GetChanges(), Is.Null); resource["FirstName"] = "Jill"; Assert.That(resource.IsChanged, Is.True); Assert.That(resource.GetChanges(), Is.EqualTo(new Dictionary<string, object> {{"FirstName", "Jill"}})); resource.Add("Age", 33); Assert.That(resource.IsChanged, Is.True); Assert.That(resource.GetChanges(), Is.EqualTo(new Dictionary<string, object> {{"FirstName", "Jill"}, {"Age", 33}})); }
private static SDataResource ReadResource(XElement payload, XContainer entry) { var resource = new SDataResource(); if (payload != null) { resource.XmlLocalName = payload.Name.LocalName; resource.XmlNamespace = payload.Name.NamespaceName; resource.Key = ReadAttributeValue <string>(payload, _sDataNs + "key"); resource.Url = ReadAttributeValue <Uri>(payload, _sDataNs + "uri"); resource.Uuid = ReadAttributeValue <Guid?>(payload, _sDataNs + "uuid"); resource.Lookup = ReadAttributeValue <string>(payload, _sDataNs + "lookup"); resource.Descriptor = ReadAttributeValue <string>(payload, _sDataNs + "descriptor"); resource.IsDeleted = ReadAttributeValue <bool?>(payload, _sDataNs + "isDeleted"); foreach (var group in payload.Elements().GroupBy(item => item.Name)) { object value; if (group.Count() > 1) { value = ReadResourceCollection(payload, group); } else { var item = group.First(); switch (InferItemType(item)) { case ItemType.Property: { var nilAttr = item.Attribute(_xsiNs + "nil"); value = nilAttr != null && XmlConvert.ToBoolean(nilAttr.Value) ? null : item.Value; break; } case ItemType.Object: { value = ReadResource(item, null); break; } case ItemType.PayloadCollection: { value = ReadResourceCollection(item, null); break; } case ItemType.SimpleCollection: { value = ReadSimpleCollection(item); break; } default: continue; } } resource.Add(group.Key.LocalName, value); } } if (entry != null) { resource.Id = ReadElementValue <string>(entry, _atomNs + "id"); resource.Title = ReadElementValue <string>(entry, _atomNs + "title"); resource.Updated = ReadElementValue <DateTimeOffset?>(entry, _atomNs + "updated"); resource.Schema = ReadElementValue <string>(entry, _sDataNs + "schema"); resource.Links = ReadLinks(entry); resource.HttpMethod = ReadElementValue <HttpMethod?>(entry, _httpNs + "httpMethod", true); resource.HttpStatus = (HttpStatusCode?)ReadElementValue <int?>(entry, _httpNs + "httpStatus"); resource.HttpMessage = ReadElementValue <string>(entry, _httpNs + "httpMessage"); resource.Location = ReadElementValue <string>(entry, _httpNs + "location"); resource.ETag = ReadElementValue <string>(entry, _httpNs + "etag"); resource.IfMatch = ReadElementValue <string>(entry, _httpNs + "ifMatch"); var diagnoses = entry.Element(_sDataNs + "diagnoses"); if (diagnoses != null) { resource.Diagnoses = DeserializeObject <Diagnoses>(diagnoses); } foreach (var diagnosis in entry.Elements(_sDataNs + "diagnosis")) { resource.Diagnoses.Add(DeserializeObject <Diagnosis>(diagnosis)); } var syncState = entry.Element(_syncNs + "syncState"); if (syncState != null) { resource.SyncState = DeserializeObject <SyncState>(syncState); } } return(resource); }