Example #1
0
 public static PrivateData <List <int> > PrepareProcessRecords(int numberOfRecords, int firstRef, int secondeRef, PrivateData <List <int> > processPhaseOption, PrivateData <int> endFlagId, HrbcRecordCreator refRecordsCreator)
 {
     return(new PrivateData <List <int> >(
                (session, test) =>
     {
         return Task.Run(() =>
         {
             var result = new List <int>();
             var fieldHandler = new FieldManager();
             var fields = fieldHandler.GetFieldGuid(ResourceFields.RequireFields[TestCoreFramework.Enums.ResourceType.Process].Append("P_Close"), new[] { TestCoreFramework.Enums.ResourceType.Process })
                          .Result.Result.ToDictionary(x => $"{char.ToUpper(x.Resource[0]) + x.Resource.Substring(1)}.{x.Alias}", x => (int)UuidUtil.GetId(x.Id));
             var recordHandler = new RecordManager();
             var request = RecordRequestComposer.ComposeCreateRequest();
             for (int i = 0; i < numberOfRecords; i++)
             {
                 request = request.Append(TestCoreFramework.Enums.ResourceType.Process, CreateResourceRequiredFieldData(fields, ((i % 3) == 0), endFlagId.Data, 1, ((i % 3) == 1) ? processPhaseOption.Data.Last() : processPhaseOption.Data.First(), i, ((i % 2) == 0) ? firstRef : secondeRef, refRecordsCreator));
             }
             var response = recordHandler.WriteRecords(request.Result);
             PrAssume.That(response, PrIs.SuccessfulResponse());
             PrAssume.That(response.Result, PrIs.Not.Null);
             PrAssume.That(response.Result.Ids[0][0], PrIs.Not.Null);
             result = response.Result.Ids.Select(id => id[0]).ToList();
             return result;
         });
     },
                (session, test, res) => Task.Run(() =>
     {
         var recordHandler = new RecordManager();
         recordHandler.DeleteRecords(
             RecordRequestComposer.ComposeDeleteRequest(TestCoreFramework.Enums.ResourceType.Process, res));
     })));
 }
Example #2
0
        public void ReadRecordForDeletedResourceTest()
        {
            PrivateApiResponse <RecordsHandlingComponent.DataContract.RecordsCreateOrDeleteResponseItem> recordResponse = null;
            var recordHandler = new RecordManager();

            var fieldHandler = new FieldManager();
            var fields       = fieldHandler.GetFieldGuid(new[] { "P_Name", "P_Owner" }, 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));

            var request = RecordRequestComposer.ComposeCreateRequest()
                          .Append(item =>
                                  item.ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client)
                                  .WithField(fields["Client.P_Name"], "TestName")
                                  .WithField(fields["Client.P_Owner"], 1));

            recordResponse = recordHandler.WriteRecords(request.Result);
            PrAssume.That(recordResponse, PrIs.SuccessfulResponse());


            var fileHandler = new FileStorageManager();

            var fileRecordUploadResponse = fileHandler.Upload(GenerateUploadFileRequest(recordId: recordResponse.Result.Ids[0][0].ToString()));

            PrAssume.That(fileRecordUploadResponse, PrIs.SuccessfulResponse());

            var recordDeleteResponse = recordHandler.DeleteRecords(RecordRequestComposer.ComposeDeleteRequest(Porters.TestCoreFramework.Enums.ResourceType.Client, recordResponse.Result.Ids.SelectMany(x => x)));

            PrAssume.That(recordDeleteResponse, PrIs.SuccessfulResponse());

            var fileRecordReadResponse = fileHandler.Read(fileRecordUploadResponse.Result.Id);

            PrAssert.That(fileRecordReadResponse, PrIs.ErrorResponse());
        }
Example #3
0
        public static PrivateData <Dictionary <ResourceId, RecordsCreateOrDeleteResponseItem> > GetCreateDeletedRecordCustomFixture()
        {
            return(new PrivateData <Dictionary <ResourceId, RecordsCreateOrDeleteResponseItem> >(
                       (session, test) =>
            {
                return Task.Run(() =>
                {
                    var fields = GetFieldsId(new[] { "P_Name", "P_Owner" }, new[] { Porters.TestCoreFramework.Enums.ResourceType.Client });

                    //create
                    var recordHandler = new RecordManager();
                    var request = RecordRequestComposer.ComposeCreateRequest() // creating a request object, using custom handlers
                                  .Append(item =>
                                          item.ForResource(TestCoreFramework.Enums.ResourceType.Client)
                                          .WithField(fields["Client.P_Name"], "Deleted CLIENT1")
                                          .WithField(fields["Client.P_Owner"], 1))
                                  .Append(item =>
                                          item.ForResource(TestCoreFramework.Enums.ResourceType.Client)
                                          .WithField(fields["Client.P_Name"], "Deleted CLIENT2")
                                          .WithField(fields["Client.P_Owner"], 1))
                                  .Result;
                    var clientCreateResponse = recordHandler.WriteRecords(request);
                    fields = GetFieldsId(new[] { "P_Name", "P_Owner", "P_Client" }, new[] { Porters.TestCoreFramework.Enums.ResourceType.Recruiter });
                    request = RecordRequestComposer.ComposeCreateRequest() // creating a request object, using custom handlers
                              .Append(item =>
                                      item.ForResource(TestCoreFramework.Enums.ResourceType.Recruiter)
                                      .WithField(fields["Recruiter.P_Name"], "Deleted RECRUITER1")
                                      .WithField(fields["Recruiter.P_Client"], clientCreateResponse.Result.Ids[0][0])
                                      .WithField(fields["Recruiter.P_Owner"], 1))
                              .Append(item =>
                                      item.ForResource(TestCoreFramework.Enums.ResourceType.Recruiter)
                                      .WithField(fields["Recruiter.P_Name"], "Deleted RECRUITER2")
                                      .WithField(fields["Recruiter.P_Client"], clientCreateResponse.Result.Ids[1][0])
                                      .WithField(fields["Recruiter.P_Owner"], 1))
                              .Result;
                    var recruiterCreateResponse = recordHandler.WriteRecords(request);
                    Dictionary <ResourceId, RecordsCreateOrDeleteResponseItem> result = new Dictionary <ResourceId, RecordsCreateOrDeleteResponseItem>()
                    {
                        [ResourceId.Client] = clientCreateResponse.Result,
                        [ResourceId.Recruiter] = recruiterCreateResponse.Result,
                        [ResourceId.Resume] = recruiterCreateResponse.Result,
                    };
                    recordHandler.DeleteRecords(
                        RecordRequestComposer.ComposeDeleteRequest(TestCoreFramework.Enums.ResourceType.Recruiter,
                                                                   new[] { recruiterCreateResponse.Result.Ids[0][0], recruiterCreateResponse.Result.Ids[1][0] }));
                    recordHandler.DeleteRecords(
                        RecordRequestComposer.ComposeDeleteRequest(TestCoreFramework.Enums.ResourceType.Client,
                                                                   new[] { clientCreateResponse.Result.Ids[0][0], clientCreateResponse.Result.Ids[1][0] }));
                    return result;
                });
            },
                       (session, test, res) => Task.Run(() =>
            {
                return Task.CompletedTask;
            })));
        }
        public void InsertInvalidPhaseDateRecordTest(TestCoreFramework.Enums.ResourceType resourceId, int ownerId, ResourceFields.ValidPhase phase, ResourceFields.InvalidDateTime time)
        {
            var fieldHandler = new FieldManager();
            var fields       = fieldHandler.GetFieldGuid(ResourceFields.RequireFields[resourceId], new[] { resourceId })
                               .Result.Result.ToDictionary(x => $"{char.ToUpper(x.Resource[0]) + x.Resource.Substring(1)}.{x.Alias}", x => (int)UuidUtil.GetId(x.Id));

            var recordHandler = new RecordManager();
            var request       = RecordRequestComposer.ComposeCreateRequest()
                                .Append(resourceId, CreateResourceRequiredFieldData(fields, resourceId, ownerId, phase, time))
                                .Result;

            var response = recordHandler.WriteRecords(request);

            PrAssert.That(response, PrIs.ErrorResponse());
        }
        public void InsertValidRecordWithOptionFieldsTest(TestCoreFramework.Enums.ResourceType resourceId, string field)
        {
            var fieldHandler = new FieldManager();
            var fields       = fieldHandler.GetFieldGuid(ResourceFields.RequireFields[resourceId].Append(field.Split('.')[1]), new[] { resourceId })
                               .Result.Result.ToDictionary(x => $"{char.ToUpper(x.Resource[0]) + x.Resource.Substring(1)}.{x.Alias}", x => (int)UuidUtil.GetId(x.Id));

            var recordHandler = new RecordManager();
            var request       = RecordRequestComposer.ComposeCreateRequest()
                                .Append(resourceId, CreateResourceOptionalFieldData(fields, resourceId, 1, ResourceFields.ValidPhase.Root, ResourceFields.ValidDateTime.Now, field))
                                .Result;

            var response = recordHandler.WriteRecords(request);

            PrAssert.That(response, PrIs.SuccessfulResponse());
            PrAssert.That(response.Result, PrIs.Not.Null);
            PrAssert.That(response.Result.Ids[0][0], PrIs.Not.Null);
            cleaner.Delete(resourceId.ToPrivateApiResource(), response.Result.Ids[0][0].ToString());
        }
Example #6
0
        public void PhaseFlowSortTest()
        {
            var fieldHandler = new FieldManager();
            var fields       = fieldHandler.GetFieldGuid(new[] { "P_Name", "P_Owner", "P_Phase" }, 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));
            var firstPhaseId  = PhaseCreater.Data.Children.ElementAtOrDefault(1).Id;
            var secondPhaseId = PhaseCreater.Data.Children.ElementAtOrDefault(2).Id;
            var thirdPhaseId  = PhaseCreater.Data.Children.ElementAtOrDefault(0).Id;
            //create
            var recordHandler = new RecordManager();
            var request       = RecordRequestComposer.ComposeCreateRequest()
                                .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.P_Phase"], firstPhaseId))
                                .Result;

            var response = recordHandler.WriteRecords(request);

            PrAssert.That(response, PrIs.SuccessfulResponse(), "Can not create record successfully");
            //update
            var updateResponse = recordHandler.UpdateRecords(
                RecordRequestComposer.ComposeUpdateRequest().Append(item =>
                                                                    item.ForResource(TestCoreFramework.Enums.ResourceType.Client)
                                                                    .Append(x => x.WithId(response.Result.Ids[0][0]).AppendField(fields["Client.P_Phase"], secondPhaseId))
                                                                    ).Result);

            PrAssert.That(updateResponse, PrIs.SuccessfulResponse(), "Can not update record successfully");
            updateResponse = recordHandler.UpdateRecords(
                RecordRequestComposer.ComposeUpdateRequest().Append(item =>
                                                                    item.ForResource(TestCoreFramework.Enums.ResourceType.Client)
                                                                    .Append(x => x.WithId(response.Result.Ids[0][0]).AppendField(fields["Client.P_Phase"], thirdPhaseId))
                                                                    ).Result);
            PrAssert.That(updateResponse, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest).And.ErrorCode((int)ResultCode.UnRecentlyPhase), "Phase is updated with smaller sort!");
        }
Example #7
0
        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)));
        }