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));
                }
            }
        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));
                }
            }
        }
示例#3
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!");
            }
        }