public void MongoDbUtility_BuildPush_Can_Create_UpdateDefinition_For_Specified_Array_Field_With_Value() { var collection = _provider.GetDatabase().GetCollection <Log>(ObjectNames.Log141); AddParents(); DevKit.InitHeader(Log, LogIndexType.measureddepth); DevKit.AddAndAssert <LogList, Log>(Log); var addedLog = DevKit.GetAndAssert(Log); Assert.AreEqual(0, addedLog.LogCurveInfo.Count(l => l.Mnemonic.Value == "curve1")); var updateDefinition = MongoDbUtility.BuildPush <Log>(null, ObjectTypes.LogCurveInfo.ToPascalCase(), DevKit.CreateDoubleLogCurveInfo("curve1", "unit1")); Assert.IsNotNull(updateDefinition); collection.UpdateOne(Builders <Log> .Filter.Eq(ObjectTypes.Uid, Log.Uid), updateDefinition); var updatedLog = DevKit.GetAndAssert(Log); Assert.AreEqual(1, updatedLog.LogCurveInfo.Count(l => l.Mnemonic.Value == "curve1")); var updateDefinitionName = MongoDbUtility.BuildUpdate <Log>(null, ObjectTypes.NameProperty, Log.Name + "Updated"); Assert.AreEqual(0, addedLog.LogCurveInfo.Count(l => l.Mnemonic.Value == "curve2")); var updateDefinitionCurve2 = MongoDbUtility.BuildPush(updateDefinitionName, ObjectTypes.LogCurveInfo.ToPascalCase(), DevKit.CreateDoubleLogCurveInfo("curve2", "unit2")); Assert.IsNotNull(updateDefinitionCurve2); collection.UpdateMany(Builders <Log> .Filter.Eq(ObjectTypes.Uid, Log.Uid), updateDefinitionCurve2); var updatedLogCurve2 = DevKit.GetAndAssert(Log); Assert.AreEqual(1, updatedLogCurve2.LogCurveInfo.Count(l => l.Mnemonic.Value == "curve2")); Assert.AreEqual(Log.Name + "Updated", updatedLogCurve2.Name); }
public void MongoDbUtility_BuildUpdate_Can_Create_UpdateDefinition_For_Specified_Field() { var collection = _provider.GetDatabase().GetCollection <Well>(ObjectNames.Well141); AddParents(); var updateWellName = Well.Name + "Updated"; var updateDef = MongoDbUtility.BuildUpdate <Well>(null, ObjectTypes.NameProperty, updateWellName); Assert.IsNotNull(updateDef); collection.UpdateOne(Builders <Well> .Filter.Eq(ObjectTypes.Uid, Well.Uid), updateDef); var updatedWell = DevKit.GetAndAssert(Well); Assert.AreEqual(updateWellName, updatedWell.Name); Assert.IsNull(updatedWell.DateTimeLicense); var updateDefCombine = MongoDbUtility.BuildUpdate(updateDef, "DateTimeLicense", DateTime.UtcNow.ToString("o")); Assert.IsNotNull(updateDefCombine); collection.UpdateOne(Builders <Well> .Filter.Eq(ObjectTypes.Uid, Well.Uid), updateDefCombine); updateDefCombine = MongoDbUtility.BuildUpdate(updateDef, "DateTimeLicenseSpecified", true); Assert.IsNotNull(updateDefCombine); collection.UpdateOne(Builders <Well> .Filter.Eq(ObjectTypes.Uid, Well.Uid), updateDefCombine); updatedWell = DevKit.GetAndAssert(Well); Assert.IsNotNull(updatedWell.DateTimeLicense); Assert.AreEqual(updateWellName, updatedWell.Name); }