public void GetAsEnum_WithoutPropertyKey_Fails(string propertyKey)
        {
            // Arrange
            var properties = new ReadOnlyDictionary <string, LogEventPropertyValue>(
                new Dictionary <string, LogEventPropertyValue>());

            // Act / Assert
            Assert.ThrowsAny <ArgumentException>(() => properties.GetAsEnum <TelemetryType>(propertyKey));
        }
        public void GetAsEnum_WithoutEnumType_Fails()
        {
            // Arrange
            string        propertyKey   = _bogusGenerator.Random.Word();
            TelemetryType telemetryType = _bogusGenerator.Random.Enum <TelemetryType>();
            var           properties    = new ReadOnlyDictionary <string, LogEventPropertyValue>(
                new Dictionary <string, LogEventPropertyValue>
            {
                [propertyKey] = new ScalarValue(telemetryType)
            });

            // Act / Assert
            Assert.ThrowsAny <FormatException>(() => properties.GetAsEnum <TimeSpan>(propertyKey));
        }
        public void GetAsEnum_WithoutPropertyValue_ReturnsNull()
        {
            // Arrange
            string propertyKey = _bogusGenerator.Random.Word();
            var    properties  = new ReadOnlyDictionary <string, LogEventPropertyValue>(
                new Dictionary <string, LogEventPropertyValue>
            {
                [propertyKey] = null
            });

            // Act
            TelemetryType?result = properties.GetAsEnum <TelemetryType>(propertyKey);

            // Assert
            Assert.Null(result);
        }
        public void GetAsEnum_WithParsablePropertyValue_Succeeds()
        {
            // Arrange
            string        propertyKey = _bogusGenerator.Random.Word();
            TelemetryType expected    = _bogusGenerator.Random.Enum <TelemetryType>();
            var           properties  = new ReadOnlyDictionary <string, LogEventPropertyValue>(
                new Dictionary <string, LogEventPropertyValue>
            {
                [propertyKey] = new ScalarValue(expected)
            });

            // Act
            TelemetryType?actual = properties.GetAsEnum <TelemetryType>(propertyKey);

            // Assert
            Assert.Equal(expected, actual);
        }