public void Should_log_bsondocument() { ILog target = GetConfiguredLog(); var customProperty = new { Start = DateTime.Now, Finished = DateTime.Now, Input = new { Count = 100 }, Output = new { Count = 95 } }; ThreadContext.Properties["customProperty"] = customProperty.ToBsonDocument(); target.Info("Finished"); string customPropertyFromDbJson = _collection.FindOneAs<BsonDocument>()["customProperty"].ToJson(); customProperty.ToJson().Should().Be.EqualTo(customPropertyFromDbJson); }
public async void Should_log_bsondocument() { ILog target = GetConfiguredLog(); var customProperty = new { Start = DateTime.Now, Finished = DateTime.Now, Input = new { Count = 100 }, Output = new { Count = 95 } }; ThreadContext.Properties["customProperty"] = customProperty.ToBsonDocument(); target.Info("Finished"); var doc = await _collection.FindAsync<BsonDocument>(new BsonDocument()); await doc.ToListAsync().ContinueWith(l => { var log = l.Result.FirstOrDefault(); string customPropertyFromDbJson = log["customProperty"].ToJson(); customProperty.ToJson().Should().Be.EqualTo(customPropertyFromDbJson); }); }
public void SerializingPoco() { var poco = new {name = "bob"}; // uses BsonBinaryWriter to write to a BsonBuffer PrintBson(poco); // uses JsonWriter to write to a StringWriter Console.WriteLine(poco.ToJson()); // uses BsonDocumentWriter to write to a BsonDocument Console.WriteLine(poco.ToBsonDocument()); }
static void Main(string[] args) { MdbContext db = new MdbContext(); Dictionary<string, string> p = new Dictionary<string, string>(); p.Add("prop9", "val1"); p.Add("prop10", "val1"); object obj = new { PROP = p }; db.Categoris.InsertOne(obj.ToBsonDocument()); //Form form = new Form(); //Category cat = new Category(); //cat.Name = "Car"; //cat.Searchable = true; //for (int i = 0; i < 10; i++) //{ // CategoryFeature cf = new CategoryFeature(); // Element el = new Element(); // el.Title = "POP1-" + i.ToString(); // el.Required = true; // cf.HtmlElement = el; // cf.Name = el.Title; // cf.Searchable = true; // cat.Feature.Add(cf); //} //db.Categoris.InsertOne(cat.ToBsonDocument()); //for (int i = 0; i < 26; i++) //{ // Product pd = new Product(); // foreach (CategoryFeature cfItem in cat.Feature) // { // ProductProperty pdpro = new ProductProperty(); // pdpro.CategoryFeatureId = cfItem.Id; // pdpro.value = 1390+i.ToString(); // pd.Propertis.Add(pdpro); // } // pd.InsertTime = DateTime.UtcNow; // db.Prodocts.InsertOne(pd.ToBsonDocument()); //} }