private async Task <OrderingFlatDetailItem> GetOrderingDetailItemInternal(int id, bool nichtSichtbarEinsehen = false)
        {
            var ctx      = new ViaducContext(WebHelper.Settings["sqlConnectionString"]);
            var flatItem = ctx.OrderingFlatItem.FirstOrDefault(i => i.ItemId == id);

            if (flatItem == null)
            {
                return(null);
            }

            var item = new OrderingFlatDetailItem();

            item.FromFlatItem(flatItem);

            if (flatItem.VeId.HasValue)
            {
                var elasticItem = await GetElasticArchiveRecord(flatItem.VeId.Value.ToString());

                if (elasticItem != null)
                {
                    var ancestors = GetAncestors(elasticItem);
                    item.ArchivplanKontext = ancestors;

                    if (nichtSichtbarEinsehen)
                    {
                        var snapshot = OrderHelper.GetOrderingIndexSnapshot(elasticItem);
                        OrderHelper.ApplySnapshotToDetailItem(snapshot, item.Item);
                    }
                }
                else
                {
                    Log.Warning("elasticRecord nicht gefunden ");
                }

                var orderHistory = (await orderManagerClient.GetOrderingHistoryForVe(flatItem.VeId.Value)).ToList();
                item.OrderingHistory        = orderHistory.Take(3);
                item.HasMoreOrderingHistory = orderHistory.Count > 3;
            }

            var statusHistory = await orderManagerClient.GetStatusHistoryForOrderItem(flatItem.ItemId);

            item.StatusHistory = statusHistory;
            return(item);
        }
        public void When_Applying_An_ElasticSnapshot_To_Detailitem_It_Should_Replace_Unknown_Texts_With_Real_Data()
        {
            // arrange
            var detailItem = new OrderingFlatItem();
            var snapshot   = new OrderingIndexSnapshot();

            foreach (var prop in detailItem.GetType().GetProperties().Where(p => p.PropertyType == typeof(string)))
            {
                var isElasticProperty = typeof(OrderingIndexSnapshot).GetProperty(prop.Name) != null;
                if (!isElasticProperty)
                {
                    continue;
                }

                prop.SetValue(detailItem, "HIDDEN");
            }

            detailItem.BehaeltnisNummer = "HIDDEN";
            SetAllStringPropertiesWithThisText(snapshot, "SECRET");

            // act
            OrderHelper.ApplySnapshotToDetailItem(snapshot, detailItem);

            // assert
            foreach (var prop in typeof(OrderingFlatItem)
                     .GetProperties()
                     .Where(p => p.PropertyType == typeof(string)))
            {
                var value = prop.GetValue(detailItem) as string;
                if (value == null || string.IsNullOrEmpty(value))
                {
                    continue;
                }

                value.Should().Be("SECRET", $"Field {prop.Name} must have the value of the snapshot");
            }
        }