Beispiel #1
0
        private static void Main()
        {
            var storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
            var tableClient    = storageAccount.CreateCloudTableClient();
            var table          = tableClient.GetTableReference("orders");

            table.CreateIfNotExists();

            var op = TableOperation.Insert(new DynamicTableEntity("orders", Guid.NewGuid().ToString(), "*",
                                                                  new Dictionary <string, EntityProperty>
            {
                { "Created", EntityProperty.GeneratePropertyForDateTimeOffset(DateTimeOffset.Now) },
                { "CustomerId", EntityProperty.GeneratePropertyForString("Customer-001") }
            }));

            table.Execute(op);

            var query  = new TableQuery();
            var result = table.ExecuteQuery(query);

            foreach (var entity in result)
            {
                Console.WriteLine($"{entity.PartitionKey}|{entity.RowKey}|{entity.Timestamp}|{entity["Created"].DateTimeOffsetValue}|{entity["CustomerId"].StringValue}");
            }

            var query2 =
                new TableQuery().Where(
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "orders"));

            Console.ReadLine();
        }
Beispiel #2
0
        public IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext)
        {
            //Storage client uses this when it needs to transform this entity to a writeable instance
            var result = new Dictionary <string, EntityProperty>();

            foreach (var cell in this.value)
            {
                if (cell.Value == null || cell.Key.EqualsAny(this.ignoreProperties))
                {
                    continue;
                }

                EntityProperty property;
                var            type = cell.Value.GetType();

                if (!PropertyMap.TryGetValue(type, out var factoryMethod))
                {
                    property = EntityProperty.GeneratePropertyForString(cell.Value.ToString());
                }
                else
                {
                    property = factoryMethod(cell.Value);
                }

                result[cell.Key] = property;
            }

            return(result);
        }
Beispiel #3
0
        /// <inheritdoc />
        public override IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext)
        {
            var result = new Dictionary <string, EntityProperty>();

            foreach (var prop in Fields)
            {
                var name = prop.Key;
                var val  = prop.Value;
                switch (val)
                {
                case string str:
                    result.Add(name, EntityProperty.GeneratePropertyForString(str));
                    break;

                case bool bl:
                    result.Add(name, EntityProperty.GeneratePropertyForBool(bl));
                    break;

                case DateTimeOffset dt:
                    result.Add(name, EntityProperty.GeneratePropertyForDateTimeOffset(dt));
                    break;

                case DateTime dt:
                    result.Add(name, EntityProperty.GeneratePropertyForDateTimeOffset(new DateTimeOffset(dt)));
                    break;

                case float db:
                    result.Add(name, EntityProperty.GeneratePropertyForDouble(db));
                    break;

                case double db:
                    result.Add(name, EntityProperty.GeneratePropertyForDouble(db));
                    break;

                case Guid gd:
                    result.Add(name, EntityProperty.GeneratePropertyForGuid(gd));
                    break;

                case int it:
                    result.Add(name, EntityProperty.GeneratePropertyForInt(it));
                    break;

                case short it:
                    result.Add(name, EntityProperty.GeneratePropertyForInt(it));
                    break;

                case long lg:
                    result.Add(name, EntityProperty.GeneratePropertyForLong(lg));
                    break;

                case null:
                    break;

                default:
                    throw new NotSupportedException("Field is not supported: " + val.GetType());
                }
            }

            return(result);
        }
        public void TableEntityPropertyGenerator()
        {
            string pk = Guid.NewGuid().ToString();
            string rk = Guid.NewGuid().ToString();
            Dictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty>();
            EntityProperty boolEntity = EntityProperty.GeneratePropertyForBool(true);

            properties.Add("boolEntity", boolEntity);
            EntityProperty timeEntity = EntityProperty.GeneratePropertyForDateTimeOffset(DateTimeOffset.UtcNow);

            properties.Add("timeEntity", timeEntity);
            EntityProperty doubleEntity = EntityProperty.GeneratePropertyForDouble(0.1);

            properties.Add("doubleEntity", doubleEntity);
            EntityProperty guidEntity = EntityProperty.GeneratePropertyForGuid(Guid.NewGuid());

            properties.Add("guidEntity", guidEntity);
            EntityProperty intEntity = EntityProperty.GeneratePropertyForInt(1);

            properties.Add("intEntity", intEntity);
            EntityProperty longEntity = EntityProperty.GeneratePropertyForLong(1);

            properties.Add("longEntity", longEntity);
            EntityProperty stringEntity = EntityProperty.GeneratePropertyForString("string");

            properties.Add("stringEntity", stringEntity);

            DynamicReplicatedTableEntity ent = new DynamicReplicatedTableEntity(pk, rk, "*", properties);

            this.repTable.Execute(TableOperation.Insert(ent));
        }
Beispiel #5
0
        public async Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages)
        {
            var batch = new TableBatchOperation();

            foreach (var msg in messages)
            {
                var snap = await JsonConvert.DeserializeObjectAsync <BusSnapshotInfo>(Encoding.UTF8.GetString(msg.GetBytes()));

                var entity = new DynamicTableEntity(snap.RouteShortName, snap.VehicleId.ToString());

                entity.Properties.Add("RouteShortName", EntityProperty.GeneratePropertyForString(snap.RouteShortName));
                entity.Properties.Add("VehicleId", EntityProperty.GeneratePropertyForInt(snap.VehicleId));
                entity.Properties.Add("TripId", EntityProperty.GeneratePropertyForInt(snap.TripId));
                entity.Properties.Add("Latitude", EntityProperty.GeneratePropertyForDouble(snap.Latitude));
                entity.Properties.Add("Longitude", EntityProperty.GeneratePropertyForDouble(snap.Longitude));
                entity.Properties.Add("DirectionOfTravel", EntityProperty.GeneratePropertyForString(snap.DirectionOfTravel.ToString()));
                entity.Properties.Add("NextStopId", EntityProperty.GeneratePropertyForInt(snap.NextStopId));
                entity.Properties.Add("Timeliness", EntityProperty.GeneratePropertyForString(snap.Timeliness.ToString()));
                entity.Properties.Add("TimelinessOffset", EntityProperty.GeneratePropertyForInt(snap.TimelinessOffset));
                entity.Properties.Add("Timestamp", EntityProperty.GeneratePropertyForDateTimeOffset(snap.Timestamp));

                batch.Add(TableOperation.InsertOrReplace(entity));
            }

            var tableClient = _account.CreateCloudTableClient();

            var table = tableClient.GetTableReference("snapshots");

            await table.CreateIfNotExistsAsync();

            await table.ExecuteBatchAsync(batch);

            await context.CheckpointAsync();
        }
 static EntityPropertyResolvers()
 {
     // ReSharper disable PossibleInvalidOperationException
     DefaultInternal = new Dictionary <Type, IEntityPropertyResolver>
     {
         { typeof(bool), new EntityPropertyResolver <bool>(member => EntityProperty.GeneratePropertyForBool(member), entityProperty => entityProperty.BooleanValue.Value) },
         { typeof(bool?), new EntityPropertyResolver <bool?>(EntityProperty.GeneratePropertyForBool, entityProperty => entityProperty.BooleanValue) },
         { typeof(int), new EntityPropertyResolver <int>(member => EntityProperty.GeneratePropertyForInt(member), entityProperty => entityProperty.Int32Value.Value) },
         { typeof(int?), new EntityPropertyResolver <int?>(EntityProperty.GeneratePropertyForInt, entityProperty => entityProperty.Int32Value) },
         { typeof(long), new EntityPropertyResolver <long>(member => EntityProperty.GeneratePropertyForLong(member), entityProperty => entityProperty.Int64Value.Value) },
         { typeof(long?), new EntityPropertyResolver <long?>(EntityProperty.GeneratePropertyForLong, entityProperty => entityProperty.Int64Value) },
         { typeof(double), new EntityPropertyResolver <double>(member => EntityProperty.GeneratePropertyForDouble(member), entityProperty => entityProperty.DoubleValue.Value) },
         { typeof(double?), new EntityPropertyResolver <double?>(EntityProperty.GeneratePropertyForDouble, entityProperty => entityProperty.DoubleValue) },
         { typeof(decimal), new EntityPropertyResolver <decimal>(member => EntityProperty.GeneratePropertyForString(member.ToString(CultureInfo.InvariantCulture)), entityProperty => decimal.Parse(entityProperty.StringValue)) },
         { typeof(decimal?), new EntityPropertyResolver <decimal?>(member => EntityProperty.GeneratePropertyForString(member?.ToString(CultureInfo.InvariantCulture)), entityProperty => entityProperty.StringValue == null ? (decimal?)null : decimal.Parse(entityProperty.StringValue)) },
         { typeof(Guid), new EntityPropertyResolver <Guid>(member => EntityProperty.GeneratePropertyForGuid(member), entityProperty => entityProperty.GuidValue.Value) },
         { typeof(Guid?), new EntityPropertyResolver <Guid?>(EntityProperty.GeneratePropertyForGuid, entityProperty => entityProperty.GuidValue) },
         { typeof(DateTime), new EntityPropertyResolver <DateTime>(member => EntityProperty.GeneratePropertyForDateTimeOffset(member), entityProperty => entityProperty.DateTime.Value) },
         { typeof(DateTime?), new EntityPropertyResolver <DateTime?>(member => EntityProperty.GeneratePropertyForDateTimeOffset(member), entityProperty => entityProperty.DateTime) },
         { typeof(DateTimeOffset), new EntityPropertyResolver <DateTimeOffset>(member => EntityProperty.GeneratePropertyForDateTimeOffset(member), entityProperty => entityProperty.DateTimeOffsetValue.Value) },
         { typeof(DateTimeOffset?), new EntityPropertyResolver <DateTimeOffset?>(EntityProperty.GeneratePropertyForDateTimeOffset, entityProperty => entityProperty.DateTimeOffsetValue) },
         { typeof(string), new EntityPropertyResolver <string>(EntityProperty.GeneratePropertyForString, entityProperty => entityProperty.StringValue) },
         { typeof(byte[]), new EntityPropertyResolver <byte[]>(EntityProperty.GeneratePropertyForByteArray, entityProperty => entityProperty.BinaryValue) },
         { typeof(Uri), new EntityPropertyResolver <Uri>(member => EntityProperty.GeneratePropertyForString(member?.ToString()), entityProperty => entityProperty.StringValue == null ? null : new Uri(entityProperty.StringValue)) }
     };
     // ReSharper restore PossibleInvalidOperationException
 }
Beispiel #7
0
        private EntityProperty CreateEntityPropertyWithNullValue(EdmType edmType)
        {
            switch (edmType)
            {
            case EdmType.String:
                return(EntityProperty.GeneratePropertyForString(null));

            case EdmType.Binary:
                return(EntityProperty.GeneratePropertyForByteArray(null));

            case EdmType.Boolean:
                return(EntityProperty.GeneratePropertyForBool(null));

            case EdmType.DateTime:
                return(EntityProperty.GeneratePropertyForDateTimeOffset(null));

            case EdmType.Double:
                return(EntityProperty.GeneratePropertyForDouble(null));

            case EdmType.Guid:
                return(EntityProperty.GeneratePropertyForGuid(null));

            case EdmType.Int32:
                return(EntityProperty.GeneratePropertyForInt(null));

            case EdmType.Int64:
                return(EntityProperty.GeneratePropertyForLong(null));

            default:
                throw new InvalidOperationException("Unexpected EdmType");
            }
        }
Beispiel #8
0
        public IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext)
        {
            //Azure Lib calls this when it wants to transform this entity to a writeable one

            var dic = new Dictionary <string, EntityProperty>();

            foreach (KeyValuePair <string, object> cell in _row)
            {
                if (cell.Value == null)
                {
                    continue;
                }

                EntityProperty ep;
                Type           t = cell.Value.GetType();

                if (!TypeToEntityPropertyFunc.TryGetValue(t, out Func <object, EntityProperty> factoryMethod))
                {
                    ep = EntityProperty.GeneratePropertyForString(cell.Value.ToString());
                }
                else
                {
                    ep = factoryMethod(cell.Value);
                }

                dic[cell.Key] = ep;
            }
            return(dic);
        }
Beispiel #9
0
        private async Task <DynamicTableEntity> TryInsertTableEntityAsync(CloudTableClient client, DynamicTableEntity entity, int index, bool addProperty = false)
        {
            try
            {
                DynamicTableEntity clonedEntity = Helpers.Clone(entity);
                if (addProperty)
                {
                    clonedEntity.Properties["regionId"] = EntityProperty.GeneratePropertyForInt(index);
                    clonedEntity.Properties["region"]   = EntityProperty.GeneratePropertyForString(client.ConnectionPolicy.PreferredLocations[0]);
                }

                Console.WriteLine("\tInserting entity with Partition Key :{0}, Row Key: {1} to region: {2}", entity.PartitionKey, entity.RowKey, client.ConnectionPolicy.PreferredLocations[0]);
                TableResult result = await client.GetTableReference(this.tableName).ExecuteAsync(TableOperation.Insert(clonedEntity));

                return(entity);
            }
            catch (StorageException exception)
            {
                if (exception.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict)
                {
                    return(null);
                }

                throw;
            }
        }
Beispiel #10
0
 private static void FillDynaConfig()
 {
     dynaConfig.Properties.Add("SrcAccountConnectionString",
                               EntityProperty.GeneratePropertyForString(conf.SrcAccountConnectionString));
     dynaConfig.Properties.Add("SrcContainerName",
                               EntityProperty.GeneratePropertyForString(conf.SrcContainerName));
     dynaConfig.Properties.Add("DestAccountConnectionString",
                               EntityProperty.GeneratePropertyForString(conf.DestAccountConnectionString));
     dynaConfig.Properties.Add("DestContainerName",
                               EntityProperty.GeneratePropertyForString(conf.DestContainerName));
     dynaConfig.Properties.Add("SrcBlobName",
                               EntityProperty.GeneratePropertyForString(conf.SrcPattern)); //* for all the blobs in the container
     dynaConfig.Properties.Add("DeleteFromSource",
                               EntityProperty.GeneratePropertyForBool(conf.DeleteFromSource));
     dynaConfig.Properties.Add("SafeDeleteFromSource",
                               EntityProperty.GeneratePropertyForBool(conf.SafeDeleteFromSource));
     dynaConfig.Properties.Add("DestTier",
                               EntityProperty.GeneratePropertyForString(conf.DestTier));
     dynaConfig.Properties.Add("LocalTempPath",
                               EntityProperty.GeneratePropertyForString(conf.LocalTempPath));
     dynaConfig.Properties.Add("DeleteFromLocalTemp",
                               EntityProperty.GeneratePropertyForBool(conf.DeleteFromLocalTemp));
     dynaConfig.Properties.Add("AzCopyPath",
                               EntityProperty.GeneratePropertyForString(conf.AzCopyPath));
     dynaConfig.Properties.Add("CustomerId",
                               EntityProperty.GeneratePropertyForString(conf.CustomerId));
     dynaConfig.Properties.Add("OverwriteIfExists",
                               EntityProperty.GeneratePropertyForBool(conf.OverwriteIfExists));
 }
        private static EntityProperty GeneratePropertyForClaims(IEnumerable <UserClaim> claims)
        {
            if (!claims.Any())
            {
                return(EntityProperty.GeneratePropertyForString(null));
            }

            var result = new StringBuilder();

            foreach (var claim in claims)
            {
                var value = claim.Value ?? String.Empty;

                if (value.StartsWith(ClaimValueEncodedPrefix, StringComparison.Ordinal) || value.Contains(ClaimSeparator))
                {
                    value = ClaimValueEncodedPrefix + value.ToBase64();
                }

                result.Append(claim.Type);
                result.Append(ClaimNameValueSeparator);
                result.Append(value);
                result.Append(ClaimSeparator);
            }

            return(EntityProperty.GeneratePropertyForString(result.ToString()));
        }
        public void Test_that_converter_is_used_while_not_null_value_setting()
        {
            // Arrange
            var isConvertedFromStorageEverCalled = false;
            var converter = new StorageValueConverterMock(
                v =>
            {
                isConvertedFromStorageEverCalled = true;

                return(v);
            },
                v => v);
            var accessor = new EntityPropertyAccessor(
                nameof(TestEntity.Property),
                false,
                e => null,
                (e, v) => ((TestEntity)e).Property = (string)v,
                converter);
            var entity = new TestEntity();
            var value  = "Some value";

            // Act
            accessor.SetProperty(entity, EntityProperty.GeneratePropertyForString(value));

            // Assert
            Assert.AreEqual(value, entity.Property);
            Assert.IsTrue(isConvertedFromStorageEverCalled);
        }
Beispiel #13
0
        public static async Task UpdateAccountStatus(Account status)
        {
            var entity = new DynamicTableEntity(status.Name, String.Empty);

            entity[StatusFieldMessage] = EntityProperty.GeneratePropertyForString(status.Message);
            entity[StatusFieldState]   = EntityProperty.GeneratePropertyForString(status.State.ToString());
            await ExecuteAsync(TableOperation.InsertOrReplace(entity));
        }
            public override IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext)
            {
                var properties = base.WriteEntity(operationContext);

                properties[nameof(CompetitionEntity.WinnerAadObjectIds)] = EntityProperty.GeneratePropertyForString(JsonConvert.SerializeObject(WinnerAadObjectIds));
                properties[nameof(CompetitionEntity.Competitors)]        = EntityProperty.GeneratePropertyForString(JsonConvert.SerializeObject(Competitors));
                return(properties);
            }
        public void Create_NullableEnum_CanConvertNullValue()
        {
            // Act
            IConverter <EntityProperty, AnEnum?> converter = EntityPropertyToTConverterFactory.Create <AnEnum?>();

            // Assert
            AssertCanConvertNullValue(converter, EntityProperty.GeneratePropertyForString(null));
        }
        public EntityProperty Convert(TEnum?input)
        {
            if (!input.HasValue)
            {
                return(EntityProperty.GeneratePropertyForString(null));
            }

            return(new EntityProperty(input.Value.ToString()));
        }
Beispiel #17
0
        public override IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext)
        {
            // Serialising List entities into fields is a tricksy business
            // so We make it a custom thang.
            var leDic = base.WriteEntity(operationContext);

            leDic.Add("Tags", EntityProperty.GeneratePropertyForString(JsonConvert.SerializeObject(this.Tags)));
            return(leDic);
        }
        private static EntityProperty CreateEntityProperty(JsonSerializer serializer, JProperty property)
        {
            if (property != null)
            {
                return(null !);
            }

            var            list    = JObject.Parse(property !.Value.ToString()).Properties().ToList();
            var            edmType = (EdmType)Enum.Parse(typeof(EdmType), list[1].Value.ToString(), true);
            EntityProperty entityProperty;

            switch ((int)edmType)
            {
            case 0:
                entityProperty =
                    EntityProperty.GeneratePropertyForString(list[0].Value.ToObject <string>(serializer));
                break;

            case 1:
                entityProperty =
                    EntityProperty.GeneratePropertyForByteArray(list[0].Value.ToObject <byte[]>(serializer));
                break;

            case 2:
                entityProperty = EntityProperty.GeneratePropertyForBool(list[0].Value.ToObject <bool>(serializer));
                break;

            case 3:
                entityProperty =
                    EntityProperty.GeneratePropertyForDateTimeOffset(list[0].Value
                                                                     .ToObject <DateTimeOffset>(serializer));
                break;

            case 4:
                entityProperty =
                    EntityProperty.GeneratePropertyForDouble(list[0].Value.ToObject <double>(serializer));
                break;

            case 5:
                entityProperty = EntityProperty.GeneratePropertyForGuid(list[0].Value.ToObject <Guid>(serializer));
                break;

            case 6:
                entityProperty = EntityProperty.GeneratePropertyForInt(list[0].Value.ToObject <int>(serializer));
                break;

            case 7:
                entityProperty = EntityProperty.GeneratePropertyForLong(list[0].Value.ToObject <long>(serializer));
                break;

            default:
                throw new NotSupportedException($"Unsupported EntityProperty.PropertyType:{edmType} detected during deserialization");
            }

            return(entityProperty);
        }
Beispiel #19
0
        public IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext)
        {
            IDictionary <string, EntityProperty> ret = new Dictionary <string, EntityProperty>();

            // Add the custom properties here
            ret.Add(nameof(DomainName), EntityProperty.GeneratePropertyForString(DomainName));
            ret.Add(nameof(EntityTypeName), EntityProperty.GeneratePropertyForString(EntityTypeName));
            ret.Add(nameof(InstanceKey), EntityProperty.GeneratePropertyForString(InstanceKey));
            return(ret);
        }
Beispiel #20
0
        private static void UpdateJobInfo(string status = "")
        {
            if (!String.IsNullOrEmpty(status))
            {
                jobInfo.Properties["Status"] = EntityProperty.GeneratePropertyForString(status);
            }
            TableOperation operation =
                TableOperation.InsertOrMerge(jobInfo);

            jobsTable.ExecuteAsync(operation);
        }
                public async Task WhenCalled_ReturnData()
                {
                    var store = EntityStore();

                    store.Retrieve_Output !.Properties.Add(nameof(DataModel.Id),
                                                           EntityProperty.GeneratePropertyForString("id"));

                    var result = await CrudStore(store).Retrieve(key: 1);

                    Assert.Equal("id", result !.Id);
                }
Beispiel #22
0
            public void SetErrMessgae(string data, string mess)
            {
                CloudTable _table0 = GetTable(0);

                var key = DateTimeOffset.Now.UtcDateTime.ToString("DyyyyMMddHHmmssfff");
                DynamicTableEntity tdsPropEntity = new DynamicTableEntity("Error", key);

                tdsPropEntity.Properties.Add("N001", EntityProperty.GeneratePropertyForString(data));
                tdsPropEntity.Properties.Add("N002", EntityProperty.GeneratePropertyForString(mess));
                _table0.ExecuteAsync(TableOperation.InsertOrMerge(tdsPropEntity)).Wait();
            }
Beispiel #23
0
 public IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext) =>
 new Dictionary <string, EntityProperty>
 {
     [nameof(Id)]           = EntityProperty.GeneratePropertyForLong(Id),
     [nameof(Name)]         = EntityProperty.GeneratePropertyForString(Name),
     [nameof(IsRunning)]    = EntityProperty.GeneratePropertyForBool(IsRunning),
     [nameof(PartitionKey)] = EntityProperty.GeneratePropertyForString(PartitionKey),
     [nameof(RowKey)]       = EntityProperty.GeneratePropertyForString(RowKey),
     [nameof(Timestamp)]    = EntityProperty.GeneratePropertyForDateTimeOffset(Timestamp),
     [nameof(ETag)]         = EntityProperty.GeneratePropertyForString(ETag)
 };
Beispiel #24
0
        public IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext)
        {
            var dict = new Dictionary <string, EntityProperty>
            {
                [PayloadKeyName]  = EntityProperty.GeneratePropertyForByteArray(Payload),
                [ManifestKeyName] = EntityProperty.GeneratePropertyForString(Manifest),
                [SeqNoKeyName]    = EntityProperty.GeneratePropertyForLong(SeqNo)
            };

            return(dict);
        }
        /// <summary>
        /// Updates the specified weather data.
        /// </summary>
        /// <param name="weatherData">The weather data.</param>
        /// <param name="partitionKey">The partition key to store the data under. This should be the city name.</param>
        /// <returns>Task.</returns>
        public static async Task Update(string partitionKey, JObject weatherData)
        {
            DynamicTableEntity tableEntity =
                new DynamicTableEntity(partitionKey, DateTimeOffset.UtcNow.Ticks.ToString())
            {
                Properties = { ["data"] = EntityProperty.GeneratePropertyForString(weatherData.ToString()) }
            };

            TableOperation operation = TableOperation.InsertOrReplace(tableEntity);
            await CloudTable.ExecuteAsync(operation);
        }
Beispiel #26
0
        public IDictionary <string, EntityProperty> WriteEntity(
            OperationContext operationContext)
        {
            var dict =
                new Dictionary <string, EntityProperty>
            {
                [ManifestKeyName] = EntityProperty.GeneratePropertyForString(Manifest),
            };

            return(dict);
        }
        public IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext)
        {
            var result = new Dictionary <string, EntityProperty>
            {
                { "Id", EntityProperty.GeneratePropertyForGuid(this.ID) },
                { nameof(this.Tenant), EntityProperty.GeneratePropertyForString(this.Tenant) },
                { nameof(this.Username), EntityProperty.GeneratePropertyForString(this.Username) },
                { nameof(this.Email), EntityProperty.GeneratePropertyForString(this.Email) },
                { nameof(this.Created), EntityProperty.GeneratePropertyForDateTimeOffset(this.Created) },
                { nameof(this.LastUpdated), EntityProperty.GeneratePropertyForDateTimeOffset(this.LastUpdated) },
                { nameof(this.IsAccountClosed), EntityProperty.GeneratePropertyForBool(this.IsAccountClosed) },
                { nameof(this.AccountClosed), EntityProperty.GeneratePropertyForDateTimeOffset(this.AccountClosed) },
                { nameof(this.IsLoginAllowed), EntityProperty.GeneratePropertyForBool(this.IsLoginAllowed) },
                { nameof(this.LastLogin), EntityProperty.GeneratePropertyForDateTimeOffset(this.LastLogin) },
                { nameof(this.LastFailedLogin), EntityProperty.GeneratePropertyForDateTimeOffset(this.LastFailedLogin) },
                { nameof(this.FailedLoginCount), EntityProperty.GeneratePropertyForInt(this.FailedLoginCount) },
                { nameof(this.PasswordChanged), EntityProperty.GeneratePropertyForDateTimeOffset(this.PasswordChanged) },
                { nameof(this.RequiresPasswordReset), EntityProperty.GeneratePropertyForBool(this.RequiresPasswordReset) },
                { nameof(this.IsAccountVerified), EntityProperty.GeneratePropertyForBool(this.IsAccountVerified) },
                { nameof(this.LastFailedPasswordReset), EntityProperty.GeneratePropertyForDateTimeOffset(this.LastFailedPasswordReset) },
                { nameof(this.FailedPasswordResetCount), EntityProperty.GeneratePropertyForInt(this.FailedPasswordResetCount) },

                { nameof(this.MobileCode), EntityProperty.GeneratePropertyForString(this.MobileCode) },
                { nameof(this.MobileCodeSent), EntityProperty.GeneratePropertyForDateTimeOffset(this.MobileCodeSent) },
                { nameof(this.MobilePhoneNumber), EntityProperty.GeneratePropertyForString(this.MobilePhoneNumber) },
                { nameof(this.MobilePhoneNumberChanged), EntityProperty.GeneratePropertyForDateTimeOffset(this.MobilePhoneNumberChanged) },

                { nameof(this.AccountTwoFactorAuthMode), EntityProperty.GeneratePropertyForString(this.AccountTwoFactorAuthMode.ToString()) },
                { nameof(this.CurrentTwoFactorAuthStatus), EntityProperty.GeneratePropertyForString(this.CurrentTwoFactorAuthStatus.ToString()) },
                { nameof(this.VerificationKey), EntityProperty.GeneratePropertyForString(this.VerificationKey) },
                { nameof(this.VerificationPurpose), EntityProperty.GeneratePropertyForString(this.VerificationPurpose?.ToString()) },
                { nameof(this.VerificationKeySent), EntityProperty.GeneratePropertyForDateTimeOffset(this.VerificationKeySent) },
                { nameof(this.VerificationStorage), EntityProperty.GeneratePropertyForString(this.VerificationStorage) },
                { nameof(this.HashedPassword), EntityProperty.GeneratePropertyForString(this.HashedPassword) },
                { nameof(this.Claims), GeneratePropertyForClaims(this.Claims) },
                { nameof(this.LinkedAccounts), GeneratePropertyForLinkedAccounts(this.LinkedAccounts) },
                { nameof(this.LinkedAccountClaims), GeneratePropertyForLinkedAccountClaims(this.LinkedAccountClaims) },
                //{ nameof(this.Certificates), GeneratePropertyForCertificates(this.Certificates) },
                //{ nameof(this.TwoFactorAuthTokens), GeneratePropertyForTwoFactorAuthTokens(this.TwoFactorAuthTokens) },
                { nameof(this.PasswordResetSecrets), GeneratePropertyForPasswordResetSecrets(this.PasswordResetSecrets) },
            };

            this.WriteProperties(result);

            // Ideally, we'd only update these values when we were certain the entity was
            // persisted to storage.
            this.OriginalUserName        = this.Username;
            this.OriginalEmail           = this.Email;
            this.OriginalPhoneNumber     = this.MobilePhoneNumber;
            this.OriginalVerificationKey = this.VerificationKey;

            return(result);
        }
        public void Create_NullableEnum_ConvertThrowsIfNonMemberValue()
        {
            // Act
            IConverter <EntityProperty, AnEnum?> converter = EntityPropertyToTConverterFactory.Create <AnEnum?>();

            // Assert
            Assert.NotNull(converter);
            EntityProperty property = EntityProperty.GeneratePropertyForString("D");

            ExceptionAssert.ThrowsArgument(() => converter.Convert(property), null,
                                           "Requested value 'D' was not found.");
        }
        public void Create_OtherType_ConvertThrowsIfNullStringValue()
        {
            // Act
            IConverter <EntityProperty, Poco> converter = EntityPropertyToTConverterFactory.Create <Poco>();

            // Assert
            Assert.NotNull(converter);
            EntityProperty property = EntityProperty.GeneratePropertyForString(null);

            ExceptionAssert.ThrowsInvalidOperation(() => converter.Convert(property),
                                                   "The String property must not be null for JSON objects.");
        }
        public void Create_Enum_ConvertThrowsIfNullValue()
        {
            // Act
            IConverter <EntityProperty, AnEnum> converter = EntityPropertyToTConverterFactory.Create <AnEnum>();

            // Assert
            Assert.NotNull(converter);
            EntityProperty property = EntityProperty.GeneratePropertyForString(null);

            ExceptionAssert.ThrowsInvalidOperation(() => converter.Convert(property),
                                                   "Enum property value must not be null.");
        }