public void Case1() { var poco = new SampleClass { nid = 1234, uid = 91011, FileName = "this becomes title", ExeNid = 5678, ExeVersion = "1.645.45647", PartHash = "45646-456465-4546-654654", }; var dict = D7Mapper.ToObjectDictionary(poco); dict.BaseField("type", "sample_class"); dict.BaseField("nid", poco.nid); dict.BaseField("title", poco.FileName); dict.BaseField("status", 1); dict.BaseField("uid", poco.uid); //dict.BaseField("language", "und"); dict.ContainsKey("vid").Should().BeFalse("No vid if zero"); poco.vid = 91012; dict = D7Mapper.ToObjectDictionary(poco); dict.BaseField("vid", poco.vid); }
public void Case1() { var obj = new SampleClass1(); obj.BaseProp = _fke.Text; obj.TopProp = _fke.Text; var dict = D7Mapper.ToObjectDictionary(obj); dict.ScalarField("baseProp", obj.BaseProp); dict.ScalarField("topProp", obj.TopProp); }
public void Case1() { var eraser = new Eraser { nid = 5678, Material = "rubber" }; var pencil = new Pencil { Eraser = eraser }; var dict = D7Mapper.ToObjectDictionary(pencil); dict.Should().ContainKey("field_eraser"); var field = dict["field_eraser"].As <UndContainer <TargetIdField> >(); field.und.Should().HaveCount(1); field.und[0].target_id.Should().Be(eraser.nid); }
public void Case3() { var obj = new SampleClass2(); var date1 = 27.May(1983); var date2 = 7.February(2014); obj.Date = date1; obj.NullDate = date2; var dict = D7Mapper.ToObjectDictionary(obj); dict.ScalarField("field_date", Fmt(date1)); dict.ScalarField("field_nulldate", Fmt(date2)); obj.Date = date2; obj.NullDate = null; dict = D7Mapper.ToObjectDictionary(obj); dict.ScalarField("field_date", Fmt(date2)); dict.ScalarField("field_nulldate", null); }
protected override async Task <Dictionary <string, object> > Update <T>(T node, string revisionLog = null) { var mappd = D7Mapper.ToObjectDictionary(node); if (mappd == null) { return(null); } if (!mappd.ContainsKey("nid")) { return(null); } int nid; if (!int.TryParse(mappd["nid"].ToString(), out nid)) { return(null); } if (nid < 1) { return(null); } if (!revisionLog.IsBlank()) { mappd.Add("revision", 1); mappd.Add("log", revisionLog); } var dict = await KeepTrying(() => PutAsync(mappd, $"entity_node/{nid}")); if (dict == null) { OnError(new ArgumentNullException("Wasn't expecting Dictionary<string, object> from PUT to be NULL.")); } dict.SetNodeIDs(node); return(dict); }
protected async Task <Dictionary <string, object> > Create <T>(T objectToPost, Func <Task <T> > postedNodeGetter, bool isPublished = true) { var mappd = D7Mapper.ToObjectDictionary(objectToPost); if (mappd == null) { return(null); } mappd["status"] = isPublished ? 1 : 0; var dict = await KeepTrying(async() => { Dictionary <string, object> resp = null; try { resp = await PostAsync(mappd, "entity_node"); } catch (Exception ex) { var savd = await postedNodeGetter.Invoke(); if (savd == null) { throw ex; } if (resp == null) { resp = D7Mapper.CopyNodeIDs(savd); } } return(resp); }); if (dict == null) { OnError(new ArgumentNullException("Wasn't expecting Dictionary<string, object> from POST to be NULL.")); } dict.SetNodeIDs(objectToPost); return(dict); }
public void Case2() { var obj = new SampleClass2(); obj.Bool = true; obj.NullBool = true; var dict = D7Mapper.ToObjectDictionary(obj); dict.ScalarField("field_bool", 1); dict.ScalarField("field_nullbool", 1); obj.Bool = false; obj.NullBool = false; dict = D7Mapper.ToObjectDictionary(obj); dict.ScalarField("field_bool", 0); dict.ScalarField("field_nullbool", 0); obj.NullBool = null; dict = D7Mapper.ToObjectDictionary(obj); dict.ScalarField("field_nullbool", null); }
public void Case1() { var poco = new SampleClass { nid = 1234, uid = 91011, FileName = "this becomes title", ExeNid = 5678, ExeVersion = "1.645.45647", PartHash = "45646-456465-4546-654654", }; var dict = D7Mapper.ToObjectDictionary(poco); dict.BaseField("type", "sample_class"); dict.BaseField("nid", poco.nid); dict.BaseField("title", poco.FileName); dict.BaseField("status", 1); dict.BaseField("uid", poco.uid); dict.ScalarField("field_exenid", poco.ExeNid); dict.ScalarField("field_fileversion", poco.ExeVersion); dict.ScalarField("field_filehash", poco.PartHash); }