コード例 #1
0
        public void DynamicToObjectMeasurement()
        {
            // Arrange
            DynamicTableEntity dynamicTableEntity = ObjectsFactory.GetCountryDynamicTableEntity();
            Stopwatch stopWatch = Stopwatch.StartNew();
            Country country = null;

            // Act
            for (int i = 0; i < IteractionsCount; i++)
            {
                country = new Country
                    {
                        Area = (double) dynamicTableEntity.Properties["Area"].DoubleValue,
                        Continent = dynamicTableEntity.PartitionKey,
                        Formed = dynamicTableEntity.Properties["Formed"].DateTimeOffsetValue.Value.DateTime,
                        Id = (Guid) dynamicTableEntity.Properties["Id"].GuidValue,
                        IsExists = (bool) dynamicTableEntity.Properties["IsExists"].BooleanValue,
                        Name = dynamicTableEntity.RowKey,
                        Population = (long) dynamicTableEntity.Properties["Population"].Int64Value,
                        PresidentsCount = (int) dynamicTableEntity["PresidentsCount"].Int32Value,
                        TopSecretKey = dynamicTableEntity["TopSecretKey"].BinaryValue
                    };
            }

            stopWatch.Stop();

            Assert.NotNull(country);

            Console.WriteLine(ResultFormat, IteractionsCount, stopWatch.ElapsedMilliseconds);
        }
コード例 #2
0
        public void ConvertToTableEntity()
        {
            // Arrange
            var converter = new TableEntityConverter<Country>();
            var country = new Country
                {
                    Area = 505992,
                    Continent = "Europe",
                    TopSecretKey = new byte[] {0xaa, 0xbb, 0xcc},
                    Formed = new DateTime(1812, 1, 1),
                    Id = Guid.NewGuid(),
                    IsExists = true,
                    Name = "Spain",
                    Population = 47190493,
                    PresidentsCount = 8
                };

            var context = new OperationContext();

            // Act
            ITableEntity tableEntity = converter.GetEntity(country);
            IDictionary<string, EntityProperty> properties = tableEntity.WriteEntity(context);

            // Assert
            Assert.Equal("*", tableEntity.ETag);
            Assert.Equal(country.Continent, tableEntity.PartitionKey);
            Assert.Equal(country.Name, tableEntity.RowKey);
            Assert.Equal(country.Area, properties["Area"].DoubleValue);
            Assert.Equal(country.TopSecretKey, properties["TopSecretKey"].BinaryValue);
            Assert.True(properties["Formed"].DateTimeOffsetValue.HasValue);
            Assert.Equal(country.Formed, properties["Formed"].DateTimeOffsetValue.Value.DateTime);
            Assert.Equal(country.Id, properties["Id"].GuidValue);
            Assert.Equal(country.IsExists, properties["IsExists"].BooleanValue);
            Assert.Equal(country.Population, properties["Population"].Int64Value);
            Assert.Equal(country.PresidentsCount, properties["PresidentsCount"].Int32Value);
        }
コード例 #3
0
        public void MeasureEvaluationTime()
        {
            // Arrange
            var evaluator = new ExpressionEvaluator();
            var country = new Country {Continent = "abc"};
            Expression<Func<string>> lambda = () => country.Continent;
            var stopwatch = new Stopwatch();

            // Act
            evaluator.Evaluate(lambda.Body);
            stopwatch.Start();
            for (int i = 0; i < 60000000; i++)
            {
                country.Continent = i.ToString(CultureInfo.InvariantCulture);
                evaluator.Evaluate(lambda.Body);
            }
            stopwatch.Stop();
        }
コード例 #4
0
        // ReSharper restore ConvertToConstant.Local

        public void ClosureOnVariableWithProperty()
        {
            // Arrange
            var evaluator = new ExpressionEvaluator();
            var country = new Country {Continent = "abc"};
            Expression<Func<string>> lambda = () => country.Continent;

            // Act
            Expression result = evaluator.Evaluate(lambda.Body);

            // Assert
            Assert.IsType<ConstantExpression>(result);
            Assert.Equal(country.Continent, ((ConstantExpression) result).Value);
        }
コード例 #5
0
        public void SerializeCountryValueTest()
        {
            // Arrange
            var value = new Country();
            ConstantExpression constant = Expression.Constant(value, value.GetType());
            string result = null;

            // Act
            Assert.Throws<NotSupportedException>(() => result = constant.Serialize());

            // Assert
            Assert.Null(result);
        }