Пример #1
0
        public async Task ShouldUseLocalDateForDisplayValue()
        {
            // Arange
            await SchemaHelper.CreateSchemasIfNotExistentAsync <LocalDateTestItem>(_client).ConfigureAwait(false);

            var date = new DateTime(2012, 12, 12, 1, 1, 1).ToUniversalTime();

            var listItem1 = new LocalDateTestItem
            {
                DateTimeField = date,
                Child         = new LocalDateTestItem
                {
                    DateTimeField = new DateTime(2010, 1, 1, 12, 1, 1)
                }
            };

            var detail = await _client.ListItem.CreateFromObjectAsync(listItem1).ConfigureAwait(false);

            var details = await detail.FetchDetail(new[] { ListItemResolveBehavior.Content, ListItemResolveBehavior.InnerDisplayValueName }).ConfigureAwait(false);

            var items = details.SucceededItems;

            // Act
            var item      = items.Last();
            var dateValue = item.ConvertTo <LocalDateTestItem>().DateTimeField;

            const string quote         = "\"";
            var          shouldBeValue = $"{{{{ {quote}{dateValue:s}Z{quote} | date: {quote}%d.%m.%Y %H:%M:%S{quote} }}}}";

            // Assert
            item.DisplayValues[DisplayPatternType.Name.ToString().ToLowerCamelCase()]
            .Should().Be(shouldBeValue);

            var renderedDisplayValue    = LocalizationService.GetDateTimeLocalizedDisplayValue(shouldBeValue);
            var formattedLocalDate      = date.ToLocalTime().ToString("dd.MM.yyyy HH:mm:ss");
            var formattedChildLocalDate = listItem1.Child.DateTimeField.ToString("dd.MM.yyyy HH:mm:ss");

            renderedDisplayValue.Should().Be(formattedLocalDate);

            // Apply local time to object tree
            LocalizationService.ReplaceDateTimeLocalizedDisplayValueInObject(item);

            item.DisplayValues["name"].Should().Be(formattedLocalDate);
            ((JObject)item.Content)
            .GetValue("child")
            .Value <JToken>("displayValue")
            .Value <string>("name").Should()
            .Be(formattedChildLocalDate);
        }