Exemple #1
0
        public void TableServiceQueryWithRetryAPM()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableServiceContext ctx         = tableClient.GetTableServiceContext();

            for (int m = 0; m < 1000; m++)
            {
                // Insert Entity
                ComplexEntity insertEntity = new ComplexEntity("insert test", m.ToString());
                ctx.AddObject(currentTable.Name, insertEntity);

                if ((m + 1) % 100 == 0)
                {
                    ctx.SaveChangesWithRetries(SaveChangesOptions.Batch);
                }
            }

            TableServiceQuery <ComplexEntity> query = (from ent in ctx.CreateQuery <ComplexEntity>(currentTable.Name)
                                                       select ent).AsTableServiceQuery(ctx);

            TestHelper.ExecuteAPMMethodWithRetry(
                2, // 1 failure, one success
                new[] {
                //Insert upstream network delay to prevent upload to server @ 1000ms / kb
                PerformanceBehaviors.InsertDownstreamNetworkDelay(10000,
                                                                  AzureStorageSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName).Alternating(true)),
                // After 100 ms return throttle message
                DelayedActionBehaviors.ExecuteAfter(Actions.ThrottleTableRequest,
                                                    100,
                                                    AzureStorageSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName).Alternating(true))
            },
                (options, opContext, callback, state) => query.BeginExecuteSegmented(null, (TableRequestOptions)options, opContext, callback, state),
                query.EndExecuteSegmented);
        }
        public async Task TableQueryableEnumerateTwice()
        {
            var entitiesToCreate = CreateComplexTableEntities(PartitionKeyValue, 2);

            // Create the new entities.

            await CreateTestEntities(entitiesToCreate).ConfigureAwait(false);

            var results = await client.QueryAsync <ComplexEntity>(x => true).ToEnumerableAsync().ConfigureAwait(false);

            List <ComplexEntity> firstIteration  = new List <ComplexEntity>();
            List <ComplexEntity> secondIteration = new List <ComplexEntity>();

            foreach (ComplexEntity ent in results)
            {
                Assert.That(ent.PartitionKey, Is.EqualTo(PartitionKeyValue));
                firstIteration.Add(ent);
            }

            foreach (ComplexEntity ent in results)
            {
                Assert.That(ent.PartitionKey, Is.EqualTo(PartitionKeyValue));
                secondIteration.Add(ent);
            }
            Assert.That(firstIteration.Count, Is.EqualTo(secondIteration.Count));

            for (int m = 0; m < firstIteration.Count; m++)
            {
                ComplexEntity.AssertEquality(firstIteration[m], secondIteration[m]);
            }
        }
Exemple #3
0
 private static ProductModel Convert(ComplexEntity <Product, ProductCategory> obj)
 {
     return(new ProductModel()
     {
         Id = obj.Obj1.p_Id, FullName = obj.Obj2.pc_Name + " " + obj.Obj1.p_Name, Desc = obj.Obj1.p_Desc
     });
 }
Exemple #4
0
        public void TableServiceQueryEntityTypeMismatchNotRetryableSync()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableServiceContext ctx         = tableClient.GetTableServiceContext();

            for (int m = 0; m < 10; m++)
            {
                // Insert Entity
                ComplexEntity insertEntity = new ComplexEntity("insert test", m.ToString());
                ctx.AddObject(currentTable.Name, insertEntity);
            }

            ctx.SaveChangesWithRetries(SaveChangesOptions.Batch);

            OperationContext opContext = new OperationContext();

            try
            {
                //This query will throw since it is of a different type then the tracked entities in the context
                List <BaseEntity> query = (from ent in ctx.CreateQuery <BaseEntity>(currentTable.Name)
                                           select ent).AsTableServiceQuery(ctx).Execute(null, opContext).ToList();
                Assert.Fail();
            }
            catch (StorageException)
            {
                TestHelper.AssertNAttempts(opContext, 1);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
Exemple #5
0
        public void TableSaveChangesConflictDoesNotRetry()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableServiceContext ctx         = tableClient.GetTableServiceContext();

            ComplexEntity insertEntity = new ComplexEntity("insert test", "conflict");

            ctx.AddObject(currentTable.Name, insertEntity);
            ctx.SaveChangesWithRetries();


            OperationContext opContext = new OperationContext();

            try
            {
                TableServiceContext ctx2 = tableClient.GetTableServiceContext();
                ctx2.AddObject(currentTable.Name, insertEntity);
                ctx2.SaveChangesWithRetries(SaveChangesOptions.None, null, opContext);
                Assert.Fail();
            }
            catch (StorageException)
            {
                TestHelper.AssertNAttempts(opContext, 1);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
Exemple #6
0
        public void TableServiceContextSaveChangesRetryAPM()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableServiceContext ctx         = tableClient.GetTableServiceContext();

            for (int m = 0; m < 100; m++)
            {
                // Insert Entity
                ComplexEntity insertEntity = new ComplexEntity("insert test", m.ToString());
                insertEntity.Binary = new byte[20 * 1024];
                ctx.AddObject(currentTable.Name, insertEntity);
            }

            TestHelper.ExecuteAPMMethodWithRetry(3,
                                                 new[] {
                //Insert upstream network delay to prevent upload to server @ 1000ms / kb
                PerformanceBehaviors.InsertUpstreamNetworkDelay(10000,
                                                                AzureStorageSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName),
                                                                new BehaviorOptions(2)),
                // After 500 ms return throttle message
                DelayedActionBehaviors.ExecuteAfter(Actions.ThrottleTableRequest,
                                                    100,
                                                    AzureStorageSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName),
                                                    new BehaviorOptions(2))
            },
                                                 (options, opContext, callback, state) => ctx.BeginSaveChangesWithRetries(SaveChangesOptions.Batch, (TableRequestOptions)options, opContext, callback, state),
                                                 (res) => ctx.EndSaveChangesWithRetries(res));
        }
        public static UIForm ReadByComplexEntity(long roleId, String ComplexEntityName)
        {
            ComplexEntity simEnt = ComplexEntityTools.Read(roleId, ComplexEntityName);
            UIForm        result = new UIForm(simEnt);

            return(result);
        }
Exemple #8
0
        public void TrySetDeepPropertyStringValue_should_ignore_nonexistent_properties()
        {
            // Given a complex type with nested properties
            const decimal top    = 99m;
            const string  bar    = "The answer";
            const int     rain   = 42;
            ComplexEntity entity = new ComplexEntity()
            {
                Top  = top,
                Nest = new NestedEntity
                {
                    Bar  = bar,
                    Rain = rain
                }
            };

            // When I set a top level property
            bool result = entity.TryParseDeepPropertyValue("nest.wtf", "42");

            // Then SetDeepPropertyValue should return false
            result.Should().BeFalse();

            // And none of the original property values should be changed
            entity.Top.Should().Be(top);
            entity.Nest.Bar.Should().Be(bar);
            entity.Nest.Rain.Should().Be(rain);
        }
        public void BatchInsert()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableServiceContext ctx         = tableClient.GetTableServiceContext();

            // Insert Entities
            SortedDictionary <string, ComplexEntity> entities = new SortedDictionary <string, ComplexEntity>();

            for (int i = 0; i < 100; i++)
            {
                ComplexEntity insertEntity = new ComplexEntity("insert test", "foo" + i);
                entities.Add(insertEntity.RowKey, insertEntity);
                ctx.AddObject(currentTable.Name, insertEntity);
            }

            DataServiceResponse response = ctx.SaveChangesWithRetries(SaveChangesOptions.Batch);

            Assert.AreEqual((int)HttpStatusCode.Accepted, response.BatchStatusCode);

            // Retrieve Entities
            List <ComplexEntity> retrievedEntities = (from ent in ctx.CreateQuery <ComplexEntity>(currentTable.Name)
                                                      where ent.PartitionKey == entities.First().Value.PartitionKey
                                                      select ent).AsTableServiceQuery(ctx).Execute().ToList();

            Assert.AreEqual(entities.Count, retrievedEntities.Count);

            foreach (ComplexEntity retrievedEntity in retrievedEntities)
            {
                ComplexEntity.AssertEquality(entities[retrievedEntity.RowKey], retrievedEntity);
                entities.Remove(retrievedEntity.RowKey);
            }

            Assert.AreEqual(0, entities.Count);
        }
        public void GetValueFromPath_ValidCollectionIndexOnComplexObject_ReturnsValue()
        {
            //arrange
            var entity = new ComplexEntity
            {
                Norf = new List <ListEntity>
                {
                    new ListEntity {
                        Foo = new List <string> {
                            "A1", "A2", "A3"
                        }
                    },
                    new ListEntity {
                        Foo = new List <string> {
                            "B1", "B2", "B3"
                        }
                    }
                }
            };

            //act
            var value = PathHelper.GetValueFromPath(typeof(ComplexEntity), "/norf/1/foo/2", entity);

            //assert
            Assert.AreEqual("B3", value);
        }
        public void SingleEntityInsertConflict()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableServiceContext ctx         = tableClient.GetTableServiceContext();

            // Insert Entity
            ComplexEntity insertEntity = new ComplexEntity("insert test", "foo");

            ctx.AddObject(currentTable.Name, insertEntity);
            ctx.SaveChangesWithRetries();


            // Attempt Insert Conflict Entity
            TableServiceContext ctx2           = tableClient.GetTableServiceContext();
            ComplexEntity       conflictEntity = new ComplexEntity("insert test", "foo");

            ctx2.AddObject(currentTable.Name, insertEntity);
            OperationContext opContext = new OperationContext();

            try
            {
                ctx2.SaveChangesWithRetries(SaveChangesOptions.None, null, opContext);
                Assert.Fail();
            }
            catch (StorageException)
            {
                TestHelper.ValidateResponse(opContext, 1, (int)HttpStatusCode.Conflict, new string[] { "EntityAlreadyExists" }, "The specified entity already exists");
            }
        }
        public void ApplyUpdate_MoveFromPropertyToList_EntityUpdated()
        {
            //Arrange
            var patchDocument = new JsonPatchDocument <ComplexEntity>();
            var entity        = new ComplexEntity
            {
                Bar = new SimpleEntity
                {
                    Foo = "I am foo"
                },
                Norf = new List <ListEntity>
                {
                    new ListEntity
                    {
                        Foo = new List <string> {
                            "Element One", "Element Two", "Element Three"
                        }
                    }
                }
            };

            //Act
            patchDocument.Move("/Bar/Foo", "/Norf/0/Foo/1");
            patchDocument.ApplyUpdatesTo(entity);

            //Assert
            Assert.IsNull(entity.Bar.Foo);
            Assert.AreEqual(4, entity.Norf[0].Foo.Count);
            Assert.AreEqual("Element One", entity.Norf[0].Foo[0]);
            Assert.AreEqual("I am foo", entity.Norf[0].Foo[1]);
            Assert.AreEqual("Element Two", entity.Norf[0].Foo[2]);
            Assert.AreEqual("Element Three", entity.Norf[0].Foo[3]);
        }
Exemple #13
0
 public ComplexDetailPage(ComplexEntity selectedComplex)
 {
     SelectedComplex = selectedComplex;
     Title           = $"Edit \"{SelectedComplex.Name}\"";
     InitControls();
     picDuration.SelectedItem = EnumHelper.GetDescription(SelectedComplex.DurationTimePerExerciseInSeconds);
 }
        public void ReflectionBasedSerializationTest()
        {
            ComplexEntity ent       = new ComplexEntity();
            ComplexEntity secondEnt = new ComplexEntity();

            secondEnt.ReadEntity(ent.WriteEntity(null), null);
            ComplexEntity.AssertEquality(ent, secondEnt);
        }
Exemple #15
0
        public static void Update(ComplexEntity app)
        {
            DAL.tblAuthorizationComplexEntity dataItem = DAL.CurrDBContext.Get().tblAuthorizationComplexEntity.
                                                         Where(x => x.RoleId == app.RoleId && x.ComplexEntityName == app.ComplexEntityName).Single();

            dataItem.AllowMethodReadWithFilters = app.AllowMethodReadWithFilters;
            DAL.CurrDBContext.Get().SaveChanges();
        }
        public void GetValueFromPath_NullParent_ThrowsException()
        {
            //arrange
            var entity = new ComplexEntity {
            };

            //act
            PathHelper.GetValueFromPath(typeof(ComplexEntity), "/bar/foo", entity);
        }
Exemple #17
0
        public void Normal_ShowTypeOnlyRoot()
        {
            var expression    = Utils.CreateEmptyExpression();
            var serialization = Utils.GetSerialization(expression);
            var complex       = new ComplexEntity(expression, this);
            var result        = complex.ToString();

            Assert.Equal($"{this.GetType().Name}.{this.GetHashCode()}", result);
        }
        public void SetValueFromPath_NullParent_ThrowsException()
        {
            //arrange
            var entity = new ComplexEntity {
            };

            //act
            PathHelper.SetValueFromPath(typeof(ComplexEntity), "/bar/foo", entity, "New Value", JsonPatchOperationType.add);
        }
Exemple #19
0
        public void Value_Null()
        {
            var expression    = Utils.CreateEmptyExpression();
            var serialization = Utils.GetSerialization(expression);
            var complex       = new ComplexEntity(expression, null);
            var result        = complex.ToString();

            Assert.Equal("", result);
        }
Exemple #20
0
        public void ShowTypeOnlyName()
        {
            var expression    = Utils.CreateEmptyExpression();
            var serialization = Utils.GetSerialization(expression);

            serialization.ShowType = ShowTypeOptions.TypeName;
            var complex = new ComplexEntity(expression, this);
            var result  = complex.ToString();

            Assert.Equal($"SerializationComplexEntityTest.{this.GetHashCode()}", result);
        }
Exemple #21
0
        public void CanCloneEntityWithComplexTypes()
        {
            ICloneFactory testObject = TestServiceProvider.GetRequiredService <ICloneFactory>();

            ComplexEntity actual = testObject.Clone(TestComplexEntity);

            Assert.AreNotSame(TestComplexEntity, actual);
            Assert.AreEqual(TestComplexEntity.TestInt, actual.TestInt);
            Assert.AreNotSame(TestComplexEntity.TestPrimitiveEntity, actual.TestPrimitiveEntity);
            VerifyPrimitiveEntityWasCloned(actual.TestPrimitiveEntity);
        }
Exemple #22
0
        public void NotShowTypeInRoot()
        {
            var expression    = Utils.CreateEmptyExpression();
            var serialization = Utils.GetSerialization(expression);

            serialization.ShowType = ShowTypeOptions.None;
            var complex = new ComplexEntity(expression, this);
            var result  = complex.ToString();

            Assert.Equal($"{this.GetHashCode()}", result);
        }
        public void SetValueFromPath_ValidParent_SetsValue()
        {
            //arrange
            var entity = new ComplexEntity {
                Bar = new SimpleEntity()
            };

            //act
            PathHelper.SetValueFromPath(typeof(ComplexEntity), "/bar/foo", entity, "New Value", JsonPatchOperationType.add);

            //assert
            Assert.AreEqual("New Value", entity.Bar.Foo);
        }
        public void GetValueFromPath_NullCollection_ThrowsException()
        {
            //Arrange
            var entity = new ComplexEntity
            {
                Norf = new List <ListEntity> {
                    null
                }
            };

            //act
            PathHelper.GetValueFromPath(typeof(ComplexEntity), "/norf/0/foo/0", entity);
        }
        public void SetValueFromPath_AddToNestedArray_ThrowsException()
        {
            //arrange
            var entity = new ComplexEntity
            {
                Foo = new ArrayEntity
                {
                    Foo = new string[] { "Element One" }
                }
            };

            //act
            PathHelper.SetValueFromPath(typeof(ComplexEntity), "/foo/Foo/1", entity, "New Value", JsonPatchOperationType.add);
        }
        public void SetValueFromPath_AddToListItemOutOfBounds_ThrowsException()
        {
            //arrange
            var entity = new ComplexEntity
            {
                Qux = new List <SimpleEntity>
                {
                    new SimpleEntity()
                }
            };

            //act
            PathHelper.SetValueFromPath(typeof(ComplexEntity), "/Qux/1/Foo", entity, "New Value", JsonPatchOperationType.add);
        }
Exemple #27
0
        public void TrySetDeepPropertyStringValue_should_set_top_level_properties()
        {
            // Given a complex type with nested properties
            ComplexEntity entity = new ComplexEntity()
            {
                Nest = new NestedEntity()
            };

            // When I set a top level property
            entity.TryParseDeepPropertyValue("Top", "10");

            // Then the property should be set correctly
            Assert.Equal(10m, entity.Top);
        }
Exemple #28
0
        public void TrySetDeepPropertyStringValue_should_set_nested_properties()
        {
            // Given a complex type with nested properties
            ComplexEntity entity = new ComplexEntity()
            {
                Nest = new NestedEntity()
            };

            // When I set a top level property
            entity.TryParseDeepPropertyValue("Nest.Bar", "Rain");

            // Then the property should be set correctly
            Assert.Equal("Rain", entity.Nest.Bar);
        }
Exemple #29
0
        public void TrySetDeepPropertyStringValue_should_ignore_case()
        {
            // Given a complex type with nested properties
            ComplexEntity entity = new ComplexEntity()
            {
                Nest = new NestedEntity()
            };

            // When I set a top level property
            entity.TryParseDeepPropertyValue("nest.rain", "42");

            // Then the property should be set correctly
            Assert.Equal(42, entity.Nest.Rain);
        }
        public SelectedExercisesPage(ComplexEntity selectedComplex)
        {
            InitializeComponent();
            Title           = "Select Exercises";
            SelectedComplex = selectedComplex;
            var exercises = ExerciseService.GetList().Select(x => new SelectedExerciseViewModel
            {
                Id         = x.Id,
                Name       = x.Name,
                Image      = x.Image,
                IsSelected = selectedComplex.Exercise.Select(y => y.Id).Contains(x.Id)
            }).ToList();

            listExercises.ItemsSource = exercises;
        }