آگاه‌سازی‌ها
پاک‌کردن همه

بروز خطا در متد SavePerson

1 ارسال ها
2 کاربران
0 Likes
106 نمایش‌
0
شروع کننده موضوع

هنگام ارسال اطلاعات برای ذخیره شخص خطای Object refrence not set to an instance of object داریم

کد تستی ما به صورت زیر هست:

CRMPerson.PersonClient m = new CRMPerson.PersonClient();
List<CRMPerson.IdentityContactPhone> contactList= new List<CRMPerson.IdentityContactPhone>();
contactList.Add(new CRMPerson.IdentityContactPhone() { PhoneNumber = "09125970260", PhoneType = "mobile" });

List<CRMPerson.CategoryInfo> catlist = new List<CRMPerson.CategoryInfo>();
catlist.Add(new CategoryInfo() {
IdentityId =new Guid("40bb97d4-0f1c-4ab0-98cf-8a9fc11a1872"),Name="کاربران" }
);

CRMPerson.PersonInfo z = new CRMPerson.PersonInfo() {
FirstName = "کاربر",
LastName = "تست",
CreatDate = DateTime.Now,
Emails = new string[] { "test@test.com" },
PhoneContacts = contactList.ToArray(),
Categories= catlist.ToArray(),
IdentityType="حقیقی",
ModifyDate=DateTime.Now,
};

var ret =m.SavePerson(_username, _password, z);

PG-Admin PG-Admin 18 آذر 1399 6:06 ب.ظ

سلام نمونه کد تست شده سرویس person

public class PgTestClientBase : ClientBase where TChannel : class
{
protected PgTestClientBase(string svcFilePath) : base(CreateServiceEndPoint(svcFilePath))
{
}

protected static ServiceEndpoint CreateServiceEndPoint(string svcPath)
{
ContractDescription desc = ContractDescription.GetContract(typeof(TChannel));
BasicHttpBinding binding = new BasicHttpBinding
{
MaxReceivedMessageSize = int.MaxValue,
MaxBufferPoolSize = int.MaxValue,
MaxBufferSize = int.MaxValue
};
binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
binding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
binding.ReaderQuotas.MaxDepth = int.MaxValue;

if (!svcPath.StartsWith("/"))
{
svcPath = "/" + svcPath;
}

return new ServiceEndpoint(desc, binding, new EndpointAddress($"{ConfigurationManager.AppSettings["baseUrl"]}{svcPath}"));
}
}
---------------
public class PersonClient : PgTestClientBase, IPerson
{
public PersonClient() : base("/services/api/IPerson.svc")
{
}

public SaveCrmObjectResult SavePerson(string username, string password, PersonInfo person)
{
return Channel.SavePerson(username, password, person);
}
}

-----------------
public class PersonServiceTests
{
public SaveCrmObjectResult SavePerson_Services(PersonInfo personInfo)
{
PersonClient person = new PersonClient();

SaveCrmObjectResult saveResult = person.SavePerson("admin", "admin", personInfo);

string message = saveResult.Message;
if (message != null)
{
throw new NullReferenceException($"Error On Save Person Error Message Is ==> '{message}'.");
}
return saveResult;
}
}
------------test class----

var personServiceTests = new PersonServiceTests();

#region PersonModel

var personInfo = new PersonInfo();

personInfo.FirstName = "تست نام";
personInfo.LastName = "فامیلی";
personInfo.AddressContacts = new List {
new IdentityContactAddress { Address = "تهران تست", IsDefault = true ,AddressType = "شعبه",City = "تهران" ,Country = "ایران",State="تهران", Id = new Guid() },
};

personInfo.Categories = new List {
new CategoryInfo { Key = "IdentityCategoryTestCode", Id = Guid.NewGuid() }
};

personInfo.ColorName = "سبز";

personInfo.DontEmail = false;
personInfo.DontFax = false;
personInfo.DontPhoneCall = false;
personInfo.DontSms = false;
personInfo.DontSocialSms = false;
personInfo.IdentityType = "حقیقی";

personInfo.PhoneContacts = new List {
new IdentityContactPhone { PhoneType = "موبایل", PhoneNumber = "+989121581210", IsDefault = true, Id = new Guid() },
new IdentityContactPhone { PhoneType = "تلفن", PhoneNumber = "+982145583347", ContinuedNumber = "7",Extension="101", Id = new Guid() } ,
new IdentityContactPhone { PhoneType = "فکس", PhoneNumber = "+982133985705", ContinuedNumber = "7", Id = new Guid() },
new IdentityContactPhone { PhoneType = "تلفکس", PhoneNumber = "+982188660630",Id = new Guid() }
};
personInfo.Website = "test.com";

personInfo.CrmObjectTypeCode = "IdentityTestTypeCode";

#endregion PersomModel

#region SavePerson

var saveResult = personWcfServiceTests.SavePerson_Services(personInfo);
Assert.True(saveResult.Success);

اشتراک:
پیمایش به بالا