private object GetValueByOptionField(KeyValuePair <Guid, Json.GetSchemaOptionData> modelEntry, OptionField field) { switch (field) { case OptionField.Id: return(UuidUtil.GetId(modelEntry.Key)); case OptionField.Name: return(modelEntry.Value.Name); case OptionField.Label: return(modelEntry.Value.Label); case OptionField.ChildCount: return(modelEntry.Value.ChildCount); case OptionField.Enabled: return(modelEntry.Value.Enabled); case OptionField.Parent: return(new OptionDataCollection(new Dictionary <HrbcField, object> { { OptionField.Id.ToField(), UuidUtil.GetId(modelEntry.Value.Parent) } })); default: throw new NotSupportedException(); } }
public async Task <GetOptionResponse> Handle(PrivateSession session, GetOptionRequest request, Func <PrivateConnection> connectionFactory) { var companyId = (await session.CallAsync(MetaData.MetaDataRequest.GetAccountInfo(HrbcAccountInfoProperty.CompanyId))).CompanyId; using (var connection = connectionFactory().ApiName(ApiName).Method(PrivateConnectionMethod.Read)) { try { using (var response = await connection.SendAsync( new Json.GetSchemaOptionRequest { Ids = request.Ids.Select(id => UuidUtil.BuildOptionGuid((ulong)id, companyId)).ToList(), Select = request.Select.Select(x => x.ToString().ToLower()).ToList() })) { var responseData = await response.ReadAsync <Json.GetSchemaOptionResponse>(); var optionCollection = responseData.Values.Select( optionModelEntry => new OptionDataCollection( request.Select.Append(OptionField.Id).ToDictionary( optionField => optionField.ToField(), optionField => GetValueByOptionField(optionModelEntry, optionField)))); return(new GetOptionResponse(optionCollection)); } } catch (ConnectionResponseException e) { throw e.ToRequestException("Could not get options", request); } } }
public void TestUpdateValidSpecialProperties(ResourceId resource, FieldTypes fType, Properties.PropertyName propName) { var guid = GuidsForUpdate[resource].Values.First(); var handler = new DefaultManager(); var props = GenerateExceptedProperties(Defines.FieldTypeApi, propName.GetEnumStringValue(), SpecialMappingValue[propName]); if (propName != Properties.PropertyName.Field) { props[Properties.PropertyName.Field.GetEnumStringValue()] = UuidUtil.GetId(FieldsCreator.Data[$"{Defines.ReferenceResource[resource].First()}-{FieldType.Mail.ToString()}-2"].Guid); } var request = GenerateUpdateRequest(resource, guid.ToString(), props); var response = handler.Send <object>(FieldManager.FieldHandlingRelativeUrl, JsonConvert.SerializeObject(request), TestCoreFramework.Enums.HttpMethod.PUT); PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.NoContent)); var result = (new FieldManager()).GetFieldDetails(guid); if (propName == Properties.PropertyName.Enabled) { PrAssert.That(result.Result.Values.SingleOrDefault().Key.ToString(), PrIs.Not.EqualTo(propName.GetEnumStringValue())); } else { PrAssert.That(result.Result.Values.SingleOrDefault().Value.Properties[propName.GetEnumStringValue()], PrIs.Not.EqualTo(SpecialMappingValue[propName])); } }
/// <summary> /// Get a UUID string /// <return>uuid</return> /// </summary> public static Guid GetUuid(string alias, bool currentPartition) { var optionhandler = new OptionManager(); int id = 0; var uuid = new Guid(); var partition = String.Empty; if (optionhandler.GetOptionId(alias) != null) { id = optionhandler.GetOptionId(alias).Value; } var listCompany = AuthenticationInfoProvider.Current.Manager.GetAllAvailableCompanies(new CompanySpecBuilder()); if (listCompany.Count != 0 && currentPartition) { partition = listCompany[0].Partition; } else { partition = listCompany[1].Partition; } uuid = UuidUtil.BuildOptionGuid(Convert.ToUInt32(id), Convert.ToUInt32(partition)); return(uuid); }
public void TestCreateRequireParameterValid(ResourceId resource, Properties.Label label, TextHelpers.FieldTypes fType, ResourceId refResource) { var guid = TextHelpers.Guid[fType](refResource, FieldsCreator, HRBCClientPrivate.API.Field.FieldType.Mail, TextHelpers.ApplicationFieldNames[HRBCClientPrivate.API.Field.FieldType.Mail]().First()); var id = UuidUtil.GetId(guid); var handler = new FieldManager(); var response = handler.CreateField(resource, new Dictionary <string, object> { [Properties.PropertyName.SType.GetEnumStringValue()] = Defines.FieldTypeApi, [Properties.PropertyName.Label.GetEnumStringValue()] = CommonMapperValue.LabelMapperValue[label], [Properties.PropertyName.Field.GetEnumStringValue()] = id }); PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK)); PrAssert.That(response.Result.Id, PrIs.Not.Null.Or.Not.Empty); var result = handler.GetFieldDetails(response.Result.Id); //Clearn up CommonHelpers.DeleteField(new List <Guid> { response.Result.Id }); //Verify PrAssert.That(result.Result.Values.SingleOrDefault().Value.Id, PrIs.EqualTo(response.Result.Id)); PrAssert.That(result.Result.Values.First().Value.Properties[Properties.PropertyName.SType.GetEnumStringValue()], PrIs.EqualTo(((int)Defines.FieldTypeApi).ToString()), "Not as expected s.type"); PrAssert.That(result.Result.Values.First().Value.Properties[Properties.PropertyName.Label.GetEnumStringValue()], PrIs.EqualTo(CommonMapperValue.LabelMapperValue[label]), "Not as expected d.label.ja"); PrAssert.That(result.Result.Values.First().Value.Properties[Properties.PropertyName.Field.GetEnumStringValue()], PrIs.EqualTo(id.ToString()), "Not as expected s.l.field"); }
public void JavaUUIDToCSharpGuid() { long mostSigBits = 4822678189205111; long leastSigBits = -8603657889541918977; Assert.AreEqual(new Guid("00112233-4455-6677-8899-aabbccddeeff"), UuidUtil.JavaUUIDToCSharpGuid(mostSigBits, leastSigBits)); }
public void InvalidUpdateSystemField(FieldType fieldType, string fieldName, CreateUpdateTestData.InvalidProperty invalidValue) { var fieldHandler = new FieldManager(); var fieldResponse = fieldHandler.GetFieldDetails(fieldName); PrAssume.That(fieldResponse, PrIs.SuccessfulResponse(), $"Cannot read field {fieldName}"); var properties = new Dictionary <string, object>(); var deletedField = UuidUtil.GetId(PreparedDeletedFieldId.Data[CommonHelpers.Resources.FirstOrDefault()]); var deletedOption = PreparedDeletedOptionId.Data; CreateUpdateTestData.InvalidPropertyValueMapper[invalidValue](properties, deletedField, deletedOption); var updateParam = new Dictionary <string, object> { [Properties.Parameters.Resource.GetEnumStringValue()] = fieldName.Split('.')[0].ToLower(), [Properties.Parameters.Properties.GetEnumStringValue()] = properties }; var request = NumberHelpers.GenerateRequestUpdate(fieldResponse.Result.Values.Keys.First().ToString(), updateParam); var handler = new DefaultManager(); var response = handler.Send <object>(FieldManager.FieldHandlingRelativeUrl, request.ToJson(), HttpMethod.PUT); if (fieldType == FieldType.Telephone && invalidValue == CreateUpdateTestData.InvalidProperty.TelWithString) { PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.NoContent), "Not able update Field"); } else if (fieldType == FieldType.Mail && (invalidValue == CreateUpdateTestData.InvalidProperty.MailWithout || invalidValue == CreateUpdateTestData.InvalidProperty.MailWithoutDomain || invalidValue == CreateUpdateTestData.InvalidProperty.MailWithoutDot || invalidValue == CreateUpdateTestData.InvalidProperty.MailWithoutName || invalidValue == CreateUpdateTestData.InvalidProperty.LeadingDot)) { PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.NoContent), "Not able update Field"); } else { PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest), "Still able update Field"); } }
private static SignalServiceDataMessage.SignalServiceQuote?CreateQuote(DataMessage content) { if (content.Quote == null) { return(null); } var attachments = new List <SignalServiceDataMessage.SignalServiceQuotedAttachment>(); foreach (var attachment in content.Quote.Attachments) { attachments.Add(new SignalServiceDataMessage.SignalServiceQuotedAttachment(attachment.ContentType, attachment.FileName, attachment.Thumbnail != null ? CreateAttachmentPointer(attachment.Thumbnail) : null)); } if (SignalServiceAddress.IsValidAddress(content.Quote.AuthorUuid, content.Quote.Author)) { SignalServiceAddress address = new SignalServiceAddress(UuidUtil.ParseOrNull(content.Quote.AuthorUuid), content.Quote.Author); return(new SignalServiceDataMessage.SignalServiceQuote((long)content.Quote.Id, address, content.Quote.Text, attachments)); } else { logger.LogWarning("Quote was missing an author! Returning null."); return(null); } }
public void TestCreateReferenceSystemFieldValid(ResourceId resource, string alias) { var handler = new FieldManager(); var guid = handler.GetFieldDetails(alias).Result.Values.First().Value.Id; var id = UuidUtil.GetId(guid); var response = handler.CreateField(resource, new Dictionary <string, object> { [Properties.PropertyName.SType.GetEnumStringValue()] = Defines.FieldTypeApi, [Properties.PropertyName.Label.GetEnumStringValue()] = CommonMapperValue.LabelMapperValue[Properties.Label.Min], [Properties.PropertyName.Field.GetEnumStringValue()] = id }); PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK)); PrAssert.That(response.Result.Id, PrIs.Not.Null.Or.Not.Empty); var result = handler.GetFieldDetails(response.Result.Id); //Clearn up CommonHelpers.DeleteField(new List <Guid> { response.Result.Id }); //Verify PrAssert.That(result.Result.Values.SingleOrDefault().Value.Id, PrIs.EqualTo(response.Result.Id)); PrAssert.That(result.Result.Values.First().Value.Properties[Properties.PropertyName.SType.GetEnumStringValue()], PrIs.EqualTo(((int)Defines.FieldTypeApi).ToString()), "Not as expected s.type"); PrAssert.That(result.Result.Values.First().Value.Properties[Properties.PropertyName.Label.GetEnumStringValue()], PrIs.EqualTo(CommonMapperValue.LabelMapperValue[Properties.Label.Min]), "Not as expected d.label.ja"); PrAssert.That(result.Result.Values.First().Value.Properties[Properties.PropertyName.Field.GetEnumStringValue()], PrIs.EqualTo(id.ToString()), "Not as expected s.l.field"); }
public void ToByteArray_AlternativeValues() { Guid uuid = new Guid("b70df6ac-3b21-4b39-a514-613561f51e2a"); byte[] serialized = UuidUtil.ToByteArray(uuid); CollectionAssert.AreEqual(Hex.FromStringCondensed("b70df6ac3b214b39a514613561f51e2a"), serialized); }
public void ParseOrThrow_From_ByteArray() { byte[] bytes = Hex.FromStringCondensed("3dc48790568b49c19bd6ab6604a5bc32"); Guid uuid = UuidUtil.ParseOrThrow(bytes); Assert.AreEqual("3dc48790-568b-49c1-9bd6-ab6604a5bc32", uuid.ToString()); }
public void ParseOrThrow_From_ByteArray_AlternativeValues() { byte[] bytes = Hex.FromStringCondensed("b83dfb0b67f141aa992e030c167cd011"); Guid uuid = UuidUtil.ParseOrThrow(bytes); Assert.AreEqual("b83dfb0b-67f1-41aa-992e-030c167cd011", uuid.ToString()); }
public void ToByteArray() { Guid uuid = new Guid("67dfd496-ea02-4720-b13d-83a462168b1d"); byte[] serialized = UuidUtil.ToByteArray(uuid); CollectionAssert.AreEqual(Hex.FromStringCondensed("67dfd496ea024720b13d83a462168b1d"), serialized); }
public static SignalServiceAddress FromProtobuf(AddressProto addressProto) { Guid? uuid = addressProto.HasUuid ? UuidUtil.ParseOrThrow(addressProto.Uuid.ToByteArray()) : (Guid?)null; string?number = addressProto.HasE164 ? addressProto.E164 : null; string?relay = addressProto.HasRelay ? addressProto.Relay : null; return(new SignalServiceAddress(uuid, number, relay)); }
public static SignalServiceAddress?FromRaw(string?rawUuid, string?e164) { if (IsValidAddress(rawUuid, e164)) { return(new SignalServiceAddress(UuidUtil.ParseOrNull(rawUuid), e164)); } else { return(null); } }
public void TestCreateInvalidSpecialWithDeletedSchemaField(ResourceId resource) { var handler = new FieldManager(); var response = handler.CreateField(resource, new Dictionary <string, object> { [Properties.PropertyName.SType.GetEnumStringValue()] = Defines.FieldTypeApi, [Properties.PropertyName.Label.GetEnumStringValue()] = CommonMapperValue.LabelMapperValue[Properties.Label.Min], [Properties.PropertyName.Field.GetEnumStringValue()] = UuidUtil.GetId(GuidsForDelete[resource].Values.First()) }); PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest)); }
private static Guid GetUuid(int id) { var optionhandler = new OptionManager(); var uuid = new Guid(); var listCompany = AuthenticationInfoProvider.Current.Manager.GetAllAvailableCompanies(new CompanySpecBuilder()); if (listCompany.Count != 0) { var partition = listCompany[0].Partition; uuid = UuidUtil.BuildOptionGuid(Convert.ToUInt32(id.ToString()), Convert.ToUInt32(partition)); } return(uuid); }
public async Task <Dictionary <string, Guid> > GetRegisteredUsersAsync(IList <string> e164numbers, string mrenclave, CancellationToken?token = null) { if (token == null) { token = CancellationToken.None; } try { string authorization = await pushServiceSocket.GetContactDiscoveryAuthorizationAsync(token); Dictionary <string, RemoteAttestation> attestations = await RemoteAttestationUtil.GetAndVerifyMultiRemoteAttestation(pushServiceSocket, PushServiceSocket.ClientSet.ContactDiscovery, mrenclave, mrenclave, authorization); List <string> addressBook = new List <string>(e164numbers.Count); foreach (string e164number in e164numbers) { addressBook.Add(e164number.Substring(1)); } IList <string> cookies = attestations.Values.ToList()[0].Cookies; DiscoveryRequest request = ContactDiscoveryCipher.CreateDiscoveryRequest(addressBook, attestations); DiscoveryResponse response = await pushServiceSocket.GetContactDiscoveryRegisteredUsersAsync(authorization, request, cookies, mrenclave); byte[] data = ContactDiscoveryCipher.GetDiscoveryResponseData(response, attestations.Values); Dictionary <string, Guid> results = new Dictionary <string, Guid>(addressBook.Count); BeBinaryReader uuidInputStream = new BeBinaryReader(new MemoryStream(data)); foreach (string candidate in addressBook) { long candidateUuidHigh = uuidInputStream.ReadInt64(); long candidateUuidLow = uuidInputStream.ReadInt64(); if (candidateUuidHigh != 0 || candidateUuidLow != 0) { results.Add($"+{candidate}", UuidUtil.JavaUUIDToCSharpGuid(candidateUuidHigh, candidateUuidLow)); } } return(results); } catch (InvalidCiphertextException ex) { throw new UnauthenticatedResponseException(ex); } }
/// <summary> /// /// </summary> /// <returns></returns> /// <exception cref="IOException"></exception> public DeviceGroup?Read() { int detailsLength = ReadRawVarint32(); if (detailsLength == -1) { return(null); } byte[] detailsSerialized = new byte[detailsLength]; Util.ReadFully(inputStream, detailsSerialized); GroupDetails details = GroupDetails.Parser.ParseFrom(detailsSerialized); if (!details.HasId) { throw new IOException("ID missing on group record!"); } byte[] id = details.Id.ToByteArray(); string?name = details.HasName ? details.Name : null; List <GroupDetails.Types.Member> members = details.Members.ToList(); SignalServiceAttachmentStream? avatar = null; bool active = details.Active; uint? expirationTimer = null; string?color = details.HasColor ? details.Color : null; bool blocked = details.Blocked; if (details.Avatar != null) { long avatarLength = details.Avatar.Length; Stream avatarStream = new LimitedInputStream(inputStream, avatarLength); string avatarContentType = details.Avatar.ContentType; avatar = new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, null, false, null); } if (details.HasExpireTimer && details.ExpireTimer > 0) { expirationTimer = details.ExpireTimer; } List <SignalServiceAddress> addressMembers = new List <SignalServiceAddress>(members.Count); foreach (GroupDetails.Types.Member member in members) { addressMembers.Add(new SignalServiceAddress(UuidUtil.ParseOrNull(member.Uuid), member.E164)); } return(new DeviceGroup(id, name, addressMembers, avatar, active, expirationTimer, color, blocked)); }
public static AddressProto ToProtobuf(SignalServiceAddress signalServiceAddress) { AddressProto builder = new AddressProto(); if (signalServiceAddress.GetNumber() != null) { builder.E164 = signalServiceAddress.E164; } if (signalServiceAddress.Uuid.HasValue) { builder.Uuid = ByteString.CopyFrom(UuidUtil.ToByteArray(signalServiceAddress.Uuid.Value)); } if (signalServiceAddress.Relay != null) { builder.Relay = signalServiceAddress.Relay; } return(builder); }
public void TestUpdateOptionalParameterValid(ResourceId resource, TextHelpers.FieldTypes fType, Properties.Caption caption, Properties.Search search, Properties.Match match, Properties.Web web, Properties.Highlight highlight, Properties.Require require) { var guid = GuidsForUpdate[resource].Values.First(); var id = UuidUtil.GetId(FieldsCreator.Data[$"{Defines.ReferenceResource[resource].First()}-{HRBCClientPrivate.API.Field.FieldType.SingleLineText.ToString()}-2"].Guid); var handler = new DefaultManager(); var props = TextHelpers.GeneratePropertiesWithoutRequired(Defines.FieldTypeApi, caption, search, match, web, highlight, require); props[Properties.PropertyName.Field.GetEnumStringValue()] = id; var request = TextHelpers.GenerateUpdateRequest(resource, guid.ToString(), props); var response = handler.Send <object>(FieldManager.FieldHandlingRelativeUrl, JsonConvert.SerializeObject(request), HttpMethod.PUT); PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.NoContent)); //Verify var result = (new FieldManager()).GetFieldDetails(guid); TextHelpers.VerifyProperties(result.Result.Values.SingleOrDefault().Value.Properties, props); }
public async Task <List <SignalServiceEnvelope> > RetrieveMessagesAsync(IMessagePipeCallback callback, CancellationToken?token = null) { if (token == null) { token = CancellationToken.None; } List <SignalServiceEnvelope> results = new List <SignalServiceEnvelope>(); List <SignalServiceEnvelopeEntity> entities = await socket.GetMessagesAsync(token); foreach (SignalServiceEnvelopeEntity entity in entities) { SignalServiceEnvelope envelope; if (entity.HasSource() && entity.SourceDevice > 0) { SignalServiceAddress address = new SignalServiceAddress(UuidUtil.ParseOrNull(entity.SourceUuid), entity.SourceE164); envelope = new SignalServiceEnvelope((int)entity.Type, address, (int)entity.SourceDevice, (int)entity.Timestamp, entity.Message, entity.Content, entity.ServerTimestamp, entity.ServerUuid); } else { envelope = new SignalServiceEnvelope((int)entity.Type, (int)entity.Timestamp, entity.Message, entity.Content, entity.ServerTimestamp, entity.ServerUuid); } await callback.OnMessageAsync(envelope); results.Add(envelope); if (envelope.HasUuid()) { await socket.AcknowledgeMessageAsync(envelope.GetUuid(), token); } else { await socket.AcknowledgeMessageAsync(entity.SourceE164 !, entity.Timestamp, token); } } return(results); }
public void TestUpdateReferenceSystemFieldValid(ResourceId resource, string alias) { var handler = new FieldManager(); var guid = GuidsForUpdate[resource].Values.First(); var id = UuidUtil.GetId(handler.GetFieldDetails(alias).Result.Values.First().Value.Id); var props = new Dictionary <string, object> { [Properties.PropertyName.Field.GetEnumStringValue()] = id }; var request = GenerateUpdateRequest(resource, guid.ToString(), props); var response = (new DefaultManager()).Send <object>(FieldManager.FieldHandlingRelativeUrl, JsonConvert.SerializeObject(request), HttpMethod.PUT); PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.NoContent)); var result = handler.GetFieldDetails(guid); //Verify PrAssert.That(result.Result.Values.SingleOrDefault().Value.Id, PrIs.EqualTo(guid)); PrAssert.That(result.Result.Values.First().Value.Properties[Properties.PropertyName.Field.GetEnumStringValue()], PrIs.EqualTo(id.ToString()), "Not as expected s.l.field"); }
public static HrbcFieldCreator InitUserFieldReference(ResourceId resource, ResourceId refRes) { // create request for reference field var fieldReferenceRequestBuilder = FieldRequest.CreateFields(); var fieldBuilder = FieldRequest.CreateFields(); fieldBuilder.Append(refRes, FieldType.Mail, $"{FieldType.Mail}", content => content.Searchable(true).Copy(false).Required(false), $"{refRes}-{FieldType.Mail.ToString()}"); IEnumerable <FieldProperty> select = new List <FieldProperty> { FieldProperty.Id, FieldProperty.Name, FieldProperty.Resource }; var customFields = new HrbcFieldCreator(((CreateFieldsRequest.IBuilderWithRecord)fieldBuilder).Build().Content, select); var id = UuidUtil.GetId(customFields.Data[$"{refRes}-{FieldType.Mail.ToString()}"].Guid); fieldReferenceRequestBuilder.Append((ResourceId)(int)resource, FieldType.Reference, "Reference Field", builder => builder.LinkedField(id.ToString()).Searchable(true).Required(false), $"referenceField"); return(new HrbcFieldCreator(((CreateFieldsRequest.IBuilderWithRecord)fieldReferenceRequestBuilder).Build().Content, select)); }
public void TestUpdateRequireParameterValid(ResourceId resource, TextHelpers.FieldTypes fType, Properties.Label label, ResourceId refResource, TextHelpers.FieldTypes resFieldType) { var guid = TextHelpers.Guid[resFieldType](refResource, FieldsCreator, HRBCClientPrivate.API.Field.FieldType.Mail, TextHelpers.ApplicationFieldNames[HRBCClientPrivate.API.Field.FieldType.Mail]().First()); var id = UuidUtil.GetId(guid); var handler = new DefaultManager(); var props = new Dictionary <string, object> { [Properties.PropertyName.Label.GetEnumStringValue()] = CommonMapperValue.LabelMapperValue[label], [Properties.PropertyName.Field.GetEnumStringValue()] = id }; var request = TextHelpers.GenerateUpdateRequest(resource, GuidsForUpdate[resource][refResource].ToString(), props); var response = handler.Send <object>(FieldManager.FieldHandlingRelativeUrl, JsonConvert.SerializeObject(request), HttpMethod.PUT); PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.NoContent)); //Verify var result = (new FieldManager()).GetFieldDetails(GuidsForUpdate[resource][refResource]); PrAssert.That(result.Result.Values.SingleOrDefault().Value.Properties[Properties.PropertyName.SType.GetEnumStringValue()], PrIs.EqualTo(((int)Defines.FieldTypeApi).ToString()), "Not as expected s.type"); PrAssert.That(result.Result.Values.SingleOrDefault().Value.Properties[Properties.PropertyName.Label.GetEnumStringValue()], PrIs.EqualTo(CommonMapperValue.LabelMapperValue[label]), "Not as expected d.label.ja"); PrAssert.That(result.Result.Values.First().Value.Properties[Properties.PropertyName.Field.GetEnumStringValue()], PrIs.EqualTo(id.ToString()), "Not as expected s.l.field"); }
public void TestCreateOptionalParameterValid(ResourceId resource, Properties.Alias alias, Properties.Caption caption, Properties.Search search, Properties.Match match, Properties.Web web, Properties.Highlight highlight, Properties.Require require) { var id = UuidUtil.GetId(FieldsCreator.Data[$"{Defines.ReferenceResource[resource].First()}-{HRBCClientPrivate.API.Field.FieldType.Mail.ToString()}-0"].Guid); var handler = new DefaultManager(); var properties = TextHelpers.GenerateWithRequireProperties(Defines.FieldTypeApi, caption, search, match, web, highlight, require); properties[Properties.PropertyName.Field.GetEnumStringValue()] = id; var request = TextHelpers.GenerateCreateRequest(resource, alias, properties); var response = handler.Send <FieldCreateResponse>(FieldManager.FieldHandlingRelativeUrl, JsonConvert.SerializeObject(request), HttpMethod.POST); PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK)); PrAssert.That(response.Result.Id, PrIs.Not.Null.Or.Not.Empty); var result = (new FieldManager()).GetFieldDetails(response.Result.Id); //Clearn up CommonHelpers.DeleteField(new List <Guid> { response.Result.Id }); //Verify PrAssert.That(result.Result.Values.SingleOrDefault().Value.Id, PrIs.EqualTo(response.Result.Id)); TextHelpers.VerifyProperties(result.Result.Values.SingleOrDefault().Value.Properties, properties); }
private CreateFieldsRequest PrepareReferenceFields() { var request = FieldRequest.CreateFields(); foreach (var masterResource in ResourceToPossibleReferenceResourcesMap) { foreach (var dependentResource in masterResource.Value) { foreach (var dependentField in FieldReader.Data.Where(pair => pair.Key.Resource == dependentResource)) { request.Append(CreateFieldRequest.Builder().With(masterResource.Key, FieldType.Reference, $"{masterResource.Key}_{dependentField.Key.ToAlias()}") .Searchable(true) .LinkedField(UuidUtil.GetId(Guid.Parse(dependentField.Value[FieldProperty.Id].ToString())).ToString()).Build().Content, new ReferenceInfo { MasterResource = masterResource.Key, DependentResource = dependentResource, TargetFieldName = dependentField.Key.Name, TargetFieldType = (TestCoreFramework.Enums.FieldType)Convert.ToInt32(dependentField.Value[FieldProperty.FieldType]) }); } foreach (var createdField in ReferenceTargetFieldCreator.Data.Where(pair => (ResourceId)pair.Value[FieldProperty.Resource] == dependentResource)) { request.Append(CreateFieldRequest.Builder().With(masterResource.Key, FieldType.Reference, $"{masterResource.Key}_{dependentResource}.{createdField.Value[FieldProperty.Name]}") .Searchable(true) .LinkedField(UuidUtil.GetId(Guid.Parse(createdField.Value[FieldProperty.Id].ToString())).ToString()).Build().Content, new ReferenceInfo { MasterResource = masterResource.Key, DependentResource = dependentResource, TargetFieldName = createdField.Value.Name, TargetFieldType = (TestCoreFramework.Enums.FieldType)Convert.ToInt32(createdField.Value[FieldProperty.FieldType]) }); } } } return(((CreateFieldsRequest.IBuilderWithRecord)request).Build().Content); }
public IBuilder Ids(params Guid[] optionIds) { ids.AddRange(optionIds.Select(guidId => UuidUtil.GetId(guidId))); return(this); }
public IBuilder Ids(IEnumerable <Guid> optionIds) { ids.AddRange(optionIds.Select(guidId => UuidUtil.GetId(guidId))); return(this); }
public void DetaultCrudTest() { var fieldHandler = new FieldManager(); var fields = fieldHandler.GetFieldGuid(new[] { "P_Name", "P_Owner", "A_TestSingleLineText" }, new[] { Porters.TestCoreFramework.Enums.ResourceType.Client }) .Result.Result.ToDictionary(x => $"{char.ToUpper(x.Resource[0]) + x.Resource.Substring(1)}.{x.Alias}", x => (int)UuidUtil.GetId(x.Id)); //create var recordHandler = new RecordManager(); var request = RecordRequestComposer.ComposeCreateRequest() // creating a request object, using custom handlers .Append(item => item.ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .WithField(fields["Client.P_Name"], "TestName -- CLIENT1") .WithField(fields["Client.P_Owner"], 1) .WithField(fields["Client.A_TestSingleLineText"], "TEST VALUE 1") .WithFieldSet(new Dictionary <int, object> { [fields["Client.P_Name"]] = "TestName -- CLIENT 5", [fields["Client.P_Owner"]] = 1, [fields["Client.A_TestSingleLineText"]] = "TEST VALUE 5" })) .Append(Porters.TestCoreFramework.Enums.ResourceType.Client, new Dictionary <int, object> { [fields["Client.P_Name"]] = "TestName -- CLIENT2", [fields["Client.P_Owner"]] = 1, [fields["Client.A_TestSingleLineText"]] = "TEST VALUE 2" }) .AppendMany(Porters.TestCoreFramework.Enums.ResourceType.Client, new Dictionary <int, object> { [fields["Client.P_Name"]] = "TestName -- CLIENT3", [fields["Client.P_Owner"]] = 1, [fields["Client.A_TestSingleLineText"]] = "TEST VALUE 3" }, new Dictionary <int, object> { [fields["Client.P_Name"]] = "TestName -- CLIENT4", [fields["Client.P_Owner"]] = 1, [fields["Client.A_TestSingleLineText"]] = "TEST VALUE 4" }) .Result; var response = recordHandler.WriteRecords(request); PrAssert.That(response, PrIs.SuccessfulResponse()); //read var res = recordHandler.ReadRecords( RecordRequestComposer.ComposeReadRequest() .ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .WithIds(response.Result.Ids.SelectMany(x => x).ToArray()) .Fields("Client.P_Name", "Client.P_Id", "Client.A_TestSingleLineText") .Result); PrAssert.That(res.Result.Total, Is.EqualTo(5)); PrAssert.That(res.Result.Items, Is.All.Matches <Dictionary <string, object> >(x => !string.IsNullOrEmpty(x["Client.A_TestSingleLineText"].ToString()))); //update recordHandler.UpdateRecords( RecordRequestComposer.ComposeUpdateRequest().Append(item => item.ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .Append(x => x.WithId(response.Result.Ids[0][0]).AppendField(fields["Client.A_TestSingleLineText"], "NewTestValue 1")) .Append(x => x.WithId(response.Result.Ids[1][0]).AppendFields(new Dictionary <int, object> { [fields["Client.A_TestSingleLineText"]] = "NewTestValue 2" }))).Result); LogHelper.LoggerForCurrentTest.Info("Records are updated without exceptions."); // example of how to access log //delete recordHandler.DeleteRecords( RecordRequestComposer.ComposeDeleteRequest(Porters.TestCoreFramework.Enums.ResourceType.Client, response.Result.Ids.SelectMany(x => x))); }