public async Task <CredentialViewModel> Assemble(CredentialRecord credentialRecord) { if (credentialRecord == null) { return(null); } var context = await _agentContextProvider.GetContextAsync(); CredentialViewModel credential = _scope.Resolve <CredentialViewModel>(new NamedParameter("credential", credentialRecord)); var credentialDefinitionId = CredentialDefinitionId.Parse(credentialRecord.CredentialDefinitionId); credential.CredentialName = credentialDefinitionId.Tag; var connectionRecord = await _connectionService.GetAsync(context, credentialRecord.ConnectionId); credential.CredentialSubtitle = connectionRecord.Alias.Name; credential.IssuedAt = connectionRecord.CreatedAtUtc.HasValue ? connectionRecord.CreatedAtUtc.Value.ToLocalTime() : (DateTime?)null; if (credentialRecord.State == CredentialState.Offered) { var attributes = new List <CredentialAttribute>(); credential.Attributes = attributes; foreach (var credentialPreviewAttribute in credentialRecord.CredentialAttributesValues) { var attribute = new CredentialAttribute { Name = credentialPreviewAttribute.Name, Value = credentialPreviewAttribute.Value.ToString(), Type = "Text" }; attribute.Type = attribute.Value != null && (attribute.Value.ToString().StartsWith("data:image/jpeg;base64") || attribute.Value.ToString().StartsWith("data:image/png;base64")) ? "Image" : "Text"; attribute.Image = attribute.Value != null && (attribute.Value.ToString().StartsWith("data:image/jpeg;base64") || attribute.Value.ToString().StartsWith("data:image/png;base64")) ? ImageSource.FromStream(() => new MemoryStream(Convert.FromBase64String(attribute.Value.ToString().Replace("data:image/jpeg;base64,", "").Replace("data:image/png;base64,", "")))) : null; attributes.Add(attribute); } } return(credential); }
public void NewVariableEntryCreatedWithSingleAttributeShouldHaveSingleAttribute() { var value = new Object(); var attribute = new CredentialAttribute(); var entry = new SessionStateVariableEntry("name", value, "description", ScopedItemOptions.Constant, attribute); Assert.AreEqual(1, entry.Attributes.Count); Assert.AreEqual(attribute, entry.Attributes[0]); Assert.AreEqual(value, entry.Value); Assert.AreEqual("name", entry.Name); Assert.AreEqual("description", entry.Description); Assert.AreEqual(ScopedItemOptions.Constant, entry.Options); }