public void Trajectory141DataAdapter_ChangeLog_Tracks_Partial_Delete_Trajectory_Header()
        {
            AddParents();

            // Add trajectory without stations, add change history with objectGrowingState set to false
            Trajectory.GridConUsed = new PlaneAngleMeasure {
                Uom = PlaneAngleUom.dega, Value = 90
            };
            Trajectory.MagDeclUsed = new PlaneAngleMeasure {
                Uom = PlaneAngleUom.dega, Value = 90
            };
            DevKit.AddAndAssert(Trajectory);

            var result = DevKit.GetAndAssert(Trajectory);

            Assert.IsNotNull(result.GridConUsed);
            DevKit.AssertChangeLog(result, 1, ChangeInfoType.add);
            Assert.IsFalse(result.ObjectGrowing.GetValueOrDefault());

            // Delete trajectory header element, add change history with updatedHeader set to true
            var deleteXml = string.Format(BasicXMLTemplate, Trajectory.UidWell, Trajectory.UidWellbore, Trajectory.Uid, "<gridConUsed />");

            DevKit.DeleteAndAssert(ObjectTypes.Trajectory, deleteXml);

            result = DevKit.GetAndAssert(Trajectory);
            var changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();

            DevKit.AssertChangeLog(result, 2, ChangeInfoType.update);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, false);
            Assert.IsNull(changeHistory.StartIndex);
            Assert.IsNull(changeHistory.EndIndex);

            // Add new station when object is not growing, add change history with objectGrowingState set to true with start and end index
            Trajectory.TrajectoryStation = DevKit.TrajectoryStations(1, 4);
            DevKit.UpdateAndAssert(Trajectory);

            result        = DevKit.GetAndAssert(Trajectory);
            changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();

            Assert.AreEqual(1, result.TrajectoryStation.Count);
            DevKit.AssertChangeLog(result, 3, ChangeInfoType.update);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, true);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 4, 4);

            // Delete trajectory header element when object is growing, no entry to change log
            deleteXml = string.Format(BasicXMLTemplate, Trajectory.UidWell, Trajectory.UidWellbore, Trajectory.Uid, "<magDeclUsed />");
            DevKit.DeleteAndAssert(ObjectTypes.Trajectory, deleteXml);

            result = DevKit.GetAndAssert(Trajectory);
            var changeHistoryList = DevKit.GetAndAssertChangeLogHistory(result.GetUri(), false);

            changeHistory = changeHistoryList.Last();

            // No changes to changelog
            Assert.AreEqual(3, changeHistoryList.Count);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, true);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 4, 4);
        }
        public void Trajectory141DataAdapter_ChangeLog_Tracks_Update_To_Trajectory_Header()
        {
            // Add well and wellbore
            AddParents();

            // Add trajectory without stations, add change history with objectGrowingState set to false
            DevKit.AddAndAssert(Trajectory);

            // Get trajectory
            var result = DevKit.GetAndAssert(Trajectory);

            Assert.AreEqual(Trajectory.ServiceCompany, result.ServiceCompany);
            DevKit.AssertChangeLog(result, 1, ChangeInfoType.add);
            Assert.IsFalse(result.ObjectGrowing.GetValueOrDefault());

            // Update header info, add change history with updatedHeader set to true
            Trajectory.ServiceCompany    = "Test Company";
            Trajectory.TrajectoryStation = null;
            DevKit.UpdateAndAssert <TrajectoryList, Trajectory>(Trajectory);

            result = DevKit.GetAndAssert(Trajectory);
            var changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();

            Assert.AreEqual(Trajectory.ServiceCompany, result.ServiceCompany);
            DevKit.AssertChangeLog(result, 2, ChangeInfoType.update);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, false);

            // Update trajectory with stations, add change history with objectGrowingState and updateHeader set to true
            var stations = DevKit.TrajectoryStations(3, 6);

            Trajectory.TrajectoryStation = stations;
            DevKit.UpdateAndAssert(Trajectory);

            result        = DevKit.GetAndAssert(Trajectory);
            changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();

            DevKit.AssertChangeLog(result, 3, ChangeInfoType.update);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, true);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 6, 8);

            // Update header info again when object is growing, no entry to change log
            Trajectory.ServiceCompany    = "Testing Company again";
            Trajectory.TrajectoryStation = null;
            DevKit.UpdateAndAssert(Trajectory);

            result = DevKit.GetAndAssert(Trajectory);
            var changeHistoryList = DevKit.GetAndAssertChangeLogHistory(result.GetUri(), false);

            // No changes to changelog
            Assert.AreEqual(3, changeHistoryList.Count);
            Assert.AreEqual(Trajectory.ServiceCompany, result.ServiceCompany);
            changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();
            DevKit.AssertChangeHistoryFlags(changeHistory, true, true);
        }
        public void Trajectory141DataAdapter_ChangeLog_Tracks_Update_To_Trajectory_Header_And_Stations()
        {
            // Add well and wellbore
            AddParents();

            // Add trajectory without stations, add change history with objectGrowingState set to false
            DevKit.AddAndAssert(Trajectory);

            // Get trajectory
            var result = DevKit.GetAndAssert(Trajectory);

            Assert.AreEqual(Trajectory.ServiceCompany, result.ServiceCompany);
            DevKit.AssertChangeLog(result, 1, ChangeInfoType.add);
            Assert.IsFalse(result.ObjectGrowing.GetValueOrDefault());

            // Update header info and add stations, add change history with updatedHeader set to true and object growing to true with start/end index
            Trajectory.ServiceCompany    = "Test Company";
            Trajectory.TrajectoryStation = DevKit.TrajectoryGenerator.GenerationStations(2, 4);
            DevKit.UpdateAndAssert <TrajectoryList, Trajectory>(Trajectory);

            result = DevKit.GetAndAssert(Trajectory);
            var changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();

            Assert.AreEqual(Trajectory.ServiceCompany, result.ServiceCompany);
            DevKit.AssertChangeLog(result, 2, ChangeInfoType.update);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, true);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 4, 5);

            // Update header and add trajectory with station with object growing, no entry to change log
            Trajectory.ServiceCompany = "Testing Company";
            var station = DevKit.TrajectoryStations(1, 6);

            station.First().Uid = "Sta-3";
            Trajectory.TrajectoryStation = station;
            DevKit.UpdateAndAssert(Trajectory);

            result = DevKit.GetAndAssert(Trajectory);
            var changeHistoryList = DevKit.GetAndAssertChangeLogHistory(result.GetUri(), false);

            changeHistory = changeHistoryList.Last();

            // No changes to changelog
            Assert.AreEqual(3, result.TrajectoryStation.Count);
            Assert.AreEqual(2, changeHistoryList.Count);
            Assert.AreEqual(Trajectory.ServiceCompany, result.ServiceCompany);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, true);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 4, 5);
        }
        public void Trajectory141DataAdapter_ChangeLog_Tracks_Append_To_Trajectory_Stations()
        {
            // Add well and wellbore
            AddParents();

            // Add trajectory without stations, add change history with objectGrowingState set to false
            DevKit.AddAndAssert(Trajectory);

            var result = DevKit.GetAndAssert(Trajectory);

            DevKit.AssertChangeLog(result, 1, ChangeInfoType.add);
            Assert.IsFalse(result.ObjectGrowing.GetValueOrDefault());

            // Update trajectory with stations, add change history with objectGrowingState and updatedHeader set to true with start and end index
            var stations = DevKit.TrajectoryStations(3, 6);

            Trajectory.TrajectoryStation = stations;
            DevKit.UpdateAndAssert(Trajectory);

            result = DevKit.GetAndAssert(Trajectory);
            var changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();

            DevKit.AssertChangeLog(result, 2, ChangeInfoType.update);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, true);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 6, 8);

            // Add new station when object is growing, no entry to change log
            Trajectory.TrajectoryStation = DevKit.TrajectoryStations(1, 4);
            Trajectory.TrajectoryStation.First().Uid = "Sta-4";
            DevKit.UpdateAndAssert(Trajectory);

            result = DevKit.GetAndAssert(Trajectory);
            var changeHistoryList = DevKit.GetAndAssertChangeLogHistory(result.GetUri(), false);

            changeHistory = changeHistoryList.Last();

            // No changes to changelog
            Assert.AreEqual(2, changeHistoryList.Count);
            Assert.AreEqual(4, result.TrajectoryStation.Count);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, true);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 6, 8);
        }
        public void Trajectory141DataAdapter_ChangeLog_Tracks_Update_To_Trajectory_Stations()
        {
            // Add well and wellbore
            AddParents();

            // Add trajectory with stations, add change history with objectGrowingState set to false
            var stations = DevKit.TrajectoryStations(3, 6);

            Trajectory.TrajectoryStation = stations;
            DevKit.AddAndAssert(Trajectory);

            var result = DevKit.GetAndAssert(Trajectory);

            DevKit.AssertChangeLog(result, 1, ChangeInfoType.add);
            Assert.IsFalse(result.ObjectGrowing.GetValueOrDefault());

            // Update trajectory station, add change history with objectGrowingState set to false and updateHeader set to true with start and end index
            var stationUpdate = Trajectory.TrajectoryStation.First();

            stationUpdate.MD.Value       = 6.5;
            Trajectory.TrajectoryStation = new List <TrajectoryStation> {
                stationUpdate
            };
            DevKit.UpdateAndAssert(Trajectory);

            result = DevKit.GetAndAssert(Trajectory);
            var changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();

            DevKit.AssertChangeLog(result, 2, ChangeInfoType.update);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, false);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 6.5, 6.5);

            // Update trajectory station again with index change, add change history with objectGrowingState set to false and updateHeader set to true with start and end index
            stationUpdate                = Trajectory.TrajectoryStation.First();
            stationUpdate.MD.Value       = 10;
            stationUpdate.Azi            = new PlaneAngleMeasure(10, PlaneAngleUom.dega);
            Trajectory.TrajectoryStation = new List <TrajectoryStation> {
                stationUpdate
            };
            DevKit.UpdateAndAssert(Trajectory);

            result        = DevKit.GetAndAssert(Trajectory);
            changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();

            DevKit.AssertChangeLog(result, 3, ChangeInfoType.update);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, false);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 10, 10);

            // Add new station when object is not growing, add change history with objectGrowingState and updateHeader set to true with start and end index
            Trajectory.TrajectoryStation = DevKit.TrajectoryStations(1, 4);
            var firstStation = Trajectory.TrajectoryStation.First();

            firstStation.Uid      = "Sta-4";
            firstStation.MD.Value = 3;
            DevKit.UpdateAndAssert(Trajectory);

            result        = DevKit.GetAndAssert(Trajectory);
            changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();

            DevKit.AssertChangeLog(result, 4, ChangeInfoType.update);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, true);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 3, 3);

            // Update station, no entry to change log
            Trajectory.TrajectoryStation = DevKit.TrajectoryStations(1, 4);
            firstStation          = Trajectory.TrajectoryStation.First();
            firstStation.Uid      = "Sta-4";
            firstStation.MD.Value = 20;
            DevKit.UpdateAndAssert(Trajectory);

            result = DevKit.GetAndAssert(Trajectory);
            var changeHistoryList = DevKit.GetAndAssertChangeLogHistory(result.GetUri(), false);

            changeHistory = changeHistoryList.Last();

            // No changes to changelog
            Assert.AreEqual(4, changeHistoryList.Count);
            Assert.AreEqual(4, result.TrajectoryStation.Count);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, true);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 3, 3);
        }
        public void Trajectory141DataAdapter_ChangeLog_Tracks_Partial_Delete_Trajectory_Stations()
        {
            // Add well and wellbore
            AddParents();

            // Add trajectory with stations, add change history with objectGrowingState set to false
            var stations = DevKit.TrajectoryStations(3, 6);

            Trajectory.TrajectoryStation = stations;
            DevKit.AddAndAssert(Trajectory);

            var result        = DevKit.GetAndAssert(Trajectory);
            var changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();

            DevKit.AssertChangeLog(result, 1, ChangeInfoType.add);

            Assert.IsFalse(result.ObjectGrowing.GetValueOrDefault());
            Assert.IsNull(changeHistory.StartIndex);
            Assert.IsNull(changeHistory.EndIndex);

            // Delete trajectory station when object not growing, add change history with objectGrowingState set to false with start and end index
            var stationToDelete = Trajectory.TrajectoryStation.First();
            var delete          = @"<trajectoryStation uid=""" + stationToDelete.Uid + @"""></trajectoryStation>";
            var queryXml        = string.Format(BasicXMLTemplate, Trajectory.UidWell, Trajectory.UidWellbore, Trajectory.Uid, delete);

            DevKit.DeleteAndAssert(ObjectTypes.Trajectory, queryXml);

            result        = DevKit.GetAndAssert(Trajectory);
            changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();

            Assert.AreEqual(2, result.TrajectoryStation.Count);
            DevKit.AssertChangeLog(result, 2, ChangeInfoType.update);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, false);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 6, 6);

            // Add new station when object is not growing, add change history with objectGrowingState set to true with start and end index
            Trajectory.TrajectoryStation = DevKit.TrajectoryStations(1, 4);
            var firstStation = Trajectory.TrajectoryStation.First();

            firstStation.Uid      = "Sta-4";
            firstStation.MD.Value = 3;
            DevKit.UpdateAndAssert(Trajectory);

            result        = DevKit.GetAndAssert(Trajectory);
            changeHistory = DevKit.GetAndAssertChangeLogHistory(result.GetUri()).First();

            Assert.AreEqual(3, result.TrajectoryStation.Count);
            DevKit.AssertChangeLog(result, 3, ChangeInfoType.update);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, true);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 3, 3);

            // Delete stations when object is growing, no entry to change log
            stationToDelete = Trajectory.TrajectoryStation.First();
            delete          = @"<trajectoryStation uid=""" + stationToDelete.Uid + @"""></trajectoryStation>";
            queryXml        = string.Format(BasicXMLTemplate, Trajectory.UidWell, Trajectory.UidWellbore, Trajectory.Uid, delete);
            DevKit.DeleteAndAssert(ObjectTypes.Trajectory, queryXml);

            result = DevKit.GetAndAssert(Trajectory);
            var changeHistoryList = DevKit.GetAndAssertChangeLogHistory(result.GetUri(), false);

            changeHistory = changeHistoryList.Last();

            // No changes to changelog
            Assert.AreEqual(3, changeHistoryList.Count);
            Assert.AreEqual(2, result.TrajectoryStation.Count);
            DevKit.AssertChangeHistoryFlags(changeHistory, true, true);
            DevKit.AssertChangeHistoryIndexRange(changeHistory, 3, 3);
        }