public static PrivateData <Dictionary <Guid, AclResponseItem> > PrepareAclFieldItem(Guid guid) { return(new PrivateData <Dictionary <Guid, AclResponseItem> >( (session, test) => { return Task.Run(() => { var handler = new AclManager(); var result = handler.ReadAclInfo(guid); PrAssume.That(result, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK), "Can not read acl field"); return result.Result[guid]; }); }, (session, test, res) => Task.Run(() => { }))); }
public static PrivateData <Dictionary <ResourceId, int> > PrepareAclFieldItem(Func <Dictionary <ResourceId, Guid> > guidProvider) { return(new PrivateData <Dictionary <ResourceId, int> >( (session, test) => { return Task.Run(() => { var guids = guidProvider(); var result = new Dictionary <ResourceId, int>(); var handler = new AclManager(); foreach (var resource in Utils.Resources().Cast <ResourceId>()) { var response = handler.ReadAclInfo(guids[resource]); PrAssume.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK), "Can not read acl field"); result.Add(resource, response.Result.First().Value.First().Value.Phases.Keys.First()); } return result; }); }, (session, test, res) => Task.Run(() => { }))); }
public void UpdateFieldsTest() { const string FieldPropertyToModify = "d.label.ja"; var resource = ResourceId.Client; var aliases = new[] { "P_Country", "P_City", "P_Prefecture" }; var resetProgrammingCacheField = "P_Memo"; var connection = PrivateApiConnection.GetConnectionForCurrentTest(); var fieldHandler = new FieldManager(); var optionHandler = new OptionManager(); var aclHandler = new AclManager(); var recordsHandler = new RecordManager(); //PHASE1: preparing test data: reading and updating fields/options/acls/records var rawFields = fieldHandler.GetFieldGuid(new[] { "P_Country", "P_Phase", "P_PhaseDate" }, new[] { Porters.TestCoreFramework.Enums.ResourceType.Client }) .Result.Result; var fields = rawFields.ToDictionary(x => $"{char.ToUpper(x.Resource[0]) + x.Resource.Substring(1)}.{x.Alias}", x => (int)UuidUtil.GetId(x.Id)); var guidFields = rawFields.ToDictionary(x => $"{char.ToUpper(x.Resource[0]) + x.Resource.Substring(1)}.{x.Alias}", x => x.Id); //fields fieldHandler.UpdateField(resetProgrammingCacheField, ResourceId.Client, new Dictionary <string, object> { ["d.label.ja"] = "MEMO" }); var originalFieldValues = aliases.ToDictionary(x => x, x => fieldHandler.GetFieldDetails($"{resource}.{x}").Result.Values.Single().Value); foreach (var alias in aliases) { fieldHandler.UpdateField(alias, ResourceId.Client, new Dictionary <string, object> { [FieldPropertyToModify] = $"UPDATE_{alias.ToUpper()}_1" }); } //options var data = optionHandler.SearchOption("Option.P_LanguageAbility"); var originalOptionValues = data.Result.Single().Children; foreach (var child in data.Result.Single().Children) { optionHandler.UpdateOption(child.Id, new Dictionary <string, object> { ["name"] = child.Alias }); } //acl var aclInfo = aclHandler.ReadAclInfo(guidFields["Client.P_Country"]); var originalAclInfo = aclInfo.Result[guidFields["Client.P_Country"]].Last().Value.Phases.ToDictionary(x => x.Key, x => new AclHandlingComponent.DataContract.AclResponseItem.PermissionItem { Permission = x.Value.Permission }); aclInfo.Result[guidFields["Client.P_Country"]].Last().Value.Phases.Select(x => x.Value.Permission = 20).ToArray(); aclHandler.SetFieldAcl(aclInfo.Result); //records var originalRecordData = recordsHandler.ReadRecords( RecordRequestComposer.ComposeReadRequest() .ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .WithIds(new[] { 10001 }) .Fields("Client.P_Country", "Client.P_Phase", "Client.P_PhaseDate") .Result); recordsHandler.UpdateRecords( RecordRequestComposer.ComposeUpdateRequest().Append(item => item.ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .Append(x => x.WithId(10001).AppendField(fields["Client.P_Country"], "TestValue") .AppendField(fields["Client.P_Phase"], originalRecordData.Result.Items.Single()["Client.P_Phase"]) .AppendField(fields["Client.P_PhaseDate"], originalRecordData.Result.Items.Single()["Client.P_PhaseDate"]))).Result); connection.DeAuthenticate(); connection.DeleteAllCookies(); //MANUAL PART: switch DB, restart memcache System.Threading.Thread.Sleep(new TimeSpan(0, 5, 5)); connection.Authenticate(); //PART3: reading from new DB, making sure that all of values are default fieldHandler.UpdateField(resetProgrammingCacheField, ResourceId.Client, new Dictionary <string, object> { ["d.label.ja"] = "MEMO" }); // fields check var updatedValues = aliases.ToDictionary(x => x, x => fieldHandler.GetFieldDetails($"{resource}.{x}").Result.Values.Single().Value); foreach (var alias in aliases) { PrAssert.That(originalFieldValues[alias].Properties[FieldPropertyToModify], PrIs.EqualTo(updatedValues[alias].Properties[FieldPropertyToModify])); } //options check data = optionHandler.SearchOption("Option.P_LanguageAbility"); foreach (var child in data.Result.Single().Children) { PrAssert.That(child.Name, Is.EqualTo(originalOptionValues.Single(x => x.Id == child.Id).Name)); } //acl check aclInfo = aclHandler.ReadAclInfo(guidFields["Client.P_Country"]); foreach (var aclItem in originalAclInfo) { PrAssert.That(aclInfo.Result[guidFields["Client.P_Country"]].Last().Value.Phases[aclItem.Key].Permission, Is.EqualTo(aclItem.Value.Permission)); } //records check var recordsData = recordsHandler.ReadRecords( RecordRequestComposer.ComposeReadRequest() .ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .WithIds(new[] { 10001 }) .Fields("Client.P_Country", "Client.P_Phase", "Client.P_PhaseDate") .Result); PrAssert.That(recordsData.Result.Items.Single()["Client.P_Country"], Is.EqualTo(originalRecordData.Result.Items.Single()["Client.P_Country"])); }