Exemplo n.º 1
0
            public async Task RetrievesData()
            {
                var expectedResponse = "{'items':[{'Process.P_Id':10002,'Process.P_Candidate':{'Person':[{'Person.P_MobileMail':'*****@*****.**','Person.P_Mail':'*****@*****.**','Person.P_Id':10001}]}}],'version':{'10002':1},'total':1}";
                var mocker           = HrbcVersion.Trunk.ToRequestMocker();

                mocker.WhenRequest(HttpRequestConstraint.HttpRequest().WithMethod(HttpMethod.Get).WithUri("generic/resource-record").WithAnyContent()).RespondWith(expectedResponse);

                mocker.WhenRequest(HttpRequestConstraint.HttpRequest(UriConstraint.Uri(Does.EndWith("generic/resource-record")), Is.EqualTo(HttpMethod.Get)))
                .RespondWith(expectedResponse);

                using (var session = mocker.Session)
                {
                    var request = ResourceRequest.GetRecords(ResourceId.Process)
                                  .WithFields(process => process.Append("Process.P_Candidate", can => can.Append("Person.P_ModileMail", "Person.P_Mail", "Person.P_Id")))
                                  .WithRecords(10002)
                                  .Build();
                    var result = await session.CallAsync(request);

                    Assert.That(result.RecordData.Count, Is.EqualTo(1));
                    Assert.That(result.RecordData.First().Version, Is.EqualTo(1));
                    Assert.That(result.RecordData.First().Count, Is.EqualTo(2));
                    Assert.That(result.RecordData.First().RecordId, Is.EqualTo(10002));
                    Assert.That(result.RecordData.First().GetValue <ulong>("Process.P_Candidate".ToField()), Is.EqualTo(10001));
                }
            }
Exemplo n.º 2
0
        public async Task DeleteMultipleRecordDifferentResource()
        {
            using (var mocker = HrbcVersion.Trunk.ToRequestMocker())
                using (var session = mocker.Session)
                {
                    mocker.WhenRequest(HttpRequestConstraint.HttpRequest()
                                       .WithUri("privateapi/generic/resource-record",
                                                "?data%5B0%5D%5Bresource%5D=9&data%5B0%5D%5Bdelete%5D%5B0%5D=15&data%5B0%5D%5Bdelete%5D%5B1%5D=20&data%5B0%5D%5Bdelete%5D%5B2%5D=24&data%5B1%5D%5Bresource%5D=5&data%5B1%5D%5Bdelete%5D%5B0%5D=5&data%5B1%5D%5Bdelete%5D%5B1%5D=10&data%5B1%5D%5Bdelete%5D%5B2%5D=14")
                                       .WithMethod(HttpMethod.Delete)
                                       .WithAnyContent())
                    .RespondWith("{'ids':[[15,20,24],[5,10,14]]}");

                    var request = DeleteRecordRequest.Builder()
                                  .Append(ResourceId.Client, 5, 10, 14)
                                  .Append(ResourceId.Recruiter, 15, 20, 24);

                    var response = await session.CallAsync(request);

                    Assert.That(response.DeletedRecords, Has.Count.EqualTo(2));
                    Assert.That(response.DeletedRecords.Keys, Does.Contain(ResourceId.Client));
                    Assert.That(response.DeletedRecords[ResourceId.Client], Has.Count.EqualTo(3));
                    Assert.That(response.DeletedRecords[ResourceId.Client], Does.Contain(5));
                    Assert.That(response.DeletedRecords[ResourceId.Client], Does.Contain(10));
                    Assert.That(response.DeletedRecords[ResourceId.Client], Does.Contain(14));
                    Assert.That(response.DeletedRecords.Keys, Does.Contain(ResourceId.Recruiter));
                    Assert.That(response.DeletedRecords[ResourceId.Recruiter], Has.Count.EqualTo(3));
                    Assert.That(response.DeletedRecords[ResourceId.Recruiter], Does.Contain(15));
                    Assert.That(response.DeletedRecords[ResourceId.Recruiter], Does.Contain(20));
                    Assert.That(response.DeletedRecords[ResourceId.Recruiter], Does.Contain(24));
                }
        }
        public async Task GetFieldPropertiesFromFullAlias()
        {
            Guid fieldGuid = HRBCClientPrivate.Util.UuidUtil.BuildFieldGuid(101, 303, ResourceId.Client);

            var expectedResponseGet    = "{'values':{'" + fieldGuid + "':{'alias':'P_TestAlias','resource':'client','properties':{'s.type':3}}}}";
            var expectedResponseSearch = "{'result':[{'id':'" + fieldGuid + "'}]}";

            using (var mocker = HrbcVersion.Trunk.ToRequestMocker())
            {
                mocker.WhenRequest(HttpRequestConstraint.HttpRequest().WithMethod(HttpMethod.Get)
                                   .WithUri(UriConstraint.Uri(Is.EqualTo("/privateapi/field/field-search"), Does.Match($".*w%5Balias%5D=P_TestAlias.*")))
                                   .WithAnyContent())
                .RespondWith(expectedResponseSearch);

                mocker.WhenRequest(HttpRequestConstraint.HttpRequest().WithMethod(HttpMethod.Get)
                                   .WithUri(UriConstraint.Uri(Is.EqualTo("/privateapi/field/field"), Does.Match($".*id%5B%5D={fieldGuid}.*").And.Match(".*s%5B%5D=properties%2Fs.type.*")))
                                   .WithAnyContent())
                .RespondWith(expectedResponseGet);

                using (var session = mocker.Session)
                {
                    // fake user login account
                    ((PrivateSession)session).Cache.Set("HrbcAccount", "303-1");

                    var response = await session.CallAsync(GetFieldPropertyRequest.Builder().Select(FieldProperty.FieldType).WhereField("Client.P_TestAlias".ToField()));

                    Assert.That(response, Has.Count.EqualTo(1));
                    Assert.That(response.Keys, Does.Contain("Client.P_TestAlias".ToField()));
                    Assert.That(response["Client.P_TestAlias".ToField()], Has.Count.EqualTo(5));
                }
            }
        }
Exemplo n.º 4
0
        public async Task DeleteWithOneGuid()
        {
            Guid deleteId = HRBCClientPrivate.Util.UuidUtil.BuildFieldGuid(101, 303, ResourceId.Client);

            var mocker = HrbcVersion.Trunk.ToRequestMocker();

            mocker.WhenRequest(HttpRequestConstraint.HttpRequest().WithMethod(HttpMethod.Delete).WithUri("/privateapi/field/field", $"?id%5B%5D={deleteId}").WithAnyContent()).RespondWith(string.Empty, System.Net.HttpStatusCode.NoContent);

            using (var session = mocker.Session)
            {
                var result = await session.CallAsync(DeleteFieldRequest.Builder().Delete(deleteId));

                Assert.That(result, Is.EqualTo(true));
            }
        }
Exemplo n.º 5
0
        public async Task SimpleInputCreatesField()
        {
            Guid expectedId = HRBCClientPrivate.Util.UuidUtil.BuildFieldGuid(101, 303, ResourceId.Client);

            var expectedResponse = "{'id':'" + expectedId.ToString() + "'}";
            var expectedRequest  = @"{""create"":{""dataType"":""number"",""resource"":""client"",""properties"":{""s.type"":3,""d.label.ja"":""test"",""d.caption.ja"":""""}}}";
            var mocker           = HrbcVersion.Trunk.ToRequestMocker();

            mocker.WhenRequest(HttpRequestConstraint.HttpRequest()
                               .WithMethod(HttpMethod.Post)
                               .WithUri("field/field")
                               .WithContent(expectedRequest))
            .RespondWith(expectedResponse);

            using (var session = mocker.Session)
            {
                var id = await session.CallAsync(CreateFieldRequest.Builder().With(ResourceId.Client, FieldType.Number, "test"));

                Assert.That(id, Is.EqualTo(expectedId));
            }
        }
Exemplo n.º 6
0
        public async Task DeleteSingleRecord()
        {
            using (var mocker = HrbcVersion.Trunk.ToRequestMocker())
                using (var session = mocker.Session)
                {
                    mocker.WhenRequest(HttpRequestConstraint.HttpRequest()
                                       .WithUri("privateapi/generic/resource-record",
                                                "?data%5B0%5D%5Bresource%5D=5&data%5B0%5D%5Bdelete%5D%5B0%5D=5")
                                       .WithMethod(HttpMethod.Delete)
                                       .WithAnyContent())
                    .RespondWith("{'ids':[[5]]}");

                    var request = DeleteRecordRequest.Builder().Append(ResourceId.Client, 5);

                    var response = await session.CallAsync(request);

                    Assert.That(response.DeletedRecords, Has.Count.EqualTo(1));
                    Assert.That(response.DeletedRecords.Keys, Does.Contain(ResourceId.Client));
                    Assert.That(response.DeletedRecords[ResourceId.Client], Has.Count.EqualTo(1));
                    Assert.That(response.DeletedRecords[ResourceId.Client], Does.Contain(5));
                }
        }
Exemplo n.º 7
0
        public void TestCreateEquivalentUserMocker()
        {
            var expectedResponse = "{'rtn':true,'id':'5000','data':''}";
            var mocker           = HrbcVersion.Trunk.ToRequestMocker();

            mocker.WhenRequest(HttpRequestConstraint.HttpRequest().WithMethod(HttpMethod.Post).WithUri("mycompany/addagent").WithAnyContent()).RespondWith(expectedResponse);

            mocker.WhenRequest(HttpRequestConstraint.HttpRequest(UriConstraint.Uri(Does.EndWith("mycompany/addagent")), Is.EqualTo(HttpMethod.Post)))
            .RespondWith(expectedResponse);

            Random rand       = new Random();
            string email      = "nam.tran" + rand.Next() + "@porters.jp";
            var    getRequest = CreateUserRequest.Builder()
                                .AddName("Nam Tran")
                                .AddTel("")
                                .AddMail(email)
                                .AddUsername("namtran12")
                                .AddMobile("")
                                .AddMobileMail("")
                                .AddApprovalFlg(false)
                                .AddTimeZone("Asia/Saigon")
                                .AddEndDate(DateTime.Now)
                                .AddNewsMailFlg(true)
                                .AddStartDate(DateTime.Now)
                                .AddDeptId(1001)
                                .AddLanguage("en_us")
                                .AddAdminNewsMailFlg(true)
                                .AddAdministrator(true);

            using (var session = mocker.Session)
            {
                Task <CreateUserResponse> task = session.CallAsync(getRequest.Build());
                TestContext.Out.WriteLine("Take the second cup of coffee in meantime!");
                task.Wait();
                CreateUserResponse result = task.Result;
                Assert.That(result.Id > 0, "Create equivalent user failed!");
            }
        }
Exemplo n.º 8
0
        public async Task DeleteWithMultipleGuid()
        {
            Guid deleteId1 = HRBCClientPrivate.Util.UuidUtil.BuildFieldGuid(101, 303, ResourceId.Client);
            Guid deleteId2 = HRBCClientPrivate.Util.UuidUtil.BuildFieldGuid(89898, 303, ResourceId.Resume);
            Guid deleteId3 = HRBCClientPrivate.Util.UuidUtil.BuildFieldGuid(12343302, 303, ResourceId.Contract);

            var mocker = HrbcVersion.Trunk.ToRequestMocker();

            mocker.WhenRequest(HttpRequestConstraint.HttpRequest()
                               .WithMethod(HttpMethod.Delete)
                               .WithUri(UriConstraint.Builder()
                                        .WithPath(Does.EndWith("field/field"))
                                        .AndQuery(Does.Match($".*id%5B%5D={deleteId1}.*").And.Match($".*id%5B%5D={deleteId2}.*").And.Match($".*id%5B%5D={deleteId3}.*")))
                               .WithAnyContent())
            .RespondWith(string.Empty, System.Net.HttpStatusCode.NoContent);

            using (var session = mocker.Session)
            {
                var result = await session.CallAsync(DeleteFieldRequest.Builder().Delete(deleteId1, deleteId2, deleteId3));

                Assert.That(result, Is.EqualTo(true));
            }
        }