Example #1
0
        public async Task Should_Set_Primary_Key_On_InsertOrUpdate()
        {
            var person = Fakers.CreateFakedPerson().Generate();

            person.AccountId = Guid.NewGuid().ToString();
            var tableEntity = EntityTableClient.Create <PersonEntity>(_optionsAction, c =>
            {
                c.SetPartitionKey(p => p.AccountId);
                c.SetPrimaryKey(p => p.PersonId);
            });

            await tableEntity.InsertOrReplaceAsync(person);

            var created = await tableEntity.GetByIdAsync(person.AccountId, person.PersonId);

            created.Should().BeEquivalentTo(person);
        }
Example #2
0
        public async Task Should_Handle_Extented_Values_Wit_hBindable_Entity()
        {
            var partitionName = Guid.NewGuid().ToString();
            var person        = Fakers.CreateFakedPerson().Generate();

            //decimal
            person.Altitude = 1.6666666666666666666666666667M;
            //float
            person.BankAmount = 2.00000024F;
            //enum
            person.Situation = Situation.Divorced;

            var tableEntity  = new TableEntityBinder <PersonEntity>(person, partitionName, person.PersonId.ToString());
            var entityResult = await UpSertAndRetrieve(tableEntity);

            entityResult.Entity.Altitude.Should().Be(person.Altitude);
            entityResult.Entity.BankAmount.Should().Be(person.BankAmount);
            entityResult.Entity.Situation.Should().Be(person.Situation);
        }
Example #3
0
        public async Task Should_InsertOrMerge_Bindable_Entity()
        {
            var partitionName = Guid.NewGuid().ToString();

            var person      = Fakers.CreateFakedPerson().Generate();
            var tableEntity = new TableEntityBinder <PersonEntity>(person, partitionName, person.PersonId.ToString());

            _ = await UpSertAndRetrieve(tableEntity);

            tableEntity = new TableEntityBinder <PersonEntity>(new PersonEntity()
            {
                PersonId  = person.PersonId,
                FirstName = "John Do",
                BirthDate = DateTime.UtcNow.AddYears(-25)
            }, partitionName, person.PersonId.ToString());

            var entityResult = await MergeAndRetrieve(tableEntity);

            //Only Nullable value and reference types are preserved in merge operation
            entityResult.Entity.LastName.Should().Be(person.LastName);
            entityResult.Entity.Latitude.Should().Be(default);
Example #4
0
        public async Task Should_Gey_By_Indexed_Prop_With_Filter()
        {
            var partitionName = Guid.NewGuid().ToString();
            var persons       = Fakers.CreateFakedPerson().Generate(50);

            persons.ForEach(p => p.AccountId = partitionName);
            IEntityTableClient <PersonEntity> tableEntity = EntityTableClient.Create <PersonEntity>(_optionsAction
                                                                                                    ,
                                                                                                    c =>
            {
                c
                .SetPartitionKey(p => p.AccountId)
                .SetPrimaryKey(p => p.PersonId)
                .AddIndex(p => p.LastName)
                .AddIndex(p => p.Created);
            });
            await tableEntity.InsertOrReplaceAsync(persons);

            var person = persons.First();
            //get all entities both primary and projected
            var result = await tableEntity.GetByAsync(person.AccountId, p => p.Created, person.Created, filter : p => p.Where(p => p.Rank).Equal(person.Rank));

            result.Should().BeEquivalentTo(person);
        }