Hey there I am Testing one of my Method in I am facing an issue that It Return me AID Null I think that there is Issue with Bearer Token that i using But in that Bearer Token when i tried on jwt.io returning me AID 06.Through this null AID it returns all of my object Null. That is the Method which i am testing.
public async Task<ActionResult> Get()
{
List<Earning> earnings = await _earningRepository.GetProducerEarnings(AId);
List<Plan> plans = await _planRepository.GetAllAsync();
List<Promotion> promotions = await _promotionRepository.GetAll();
//pending refer a friend
List<MemberInfo> members = await _agentRepository.GetMembers(AId);
List<EarningResponse> earningResponses = new List<EarningResponse>();
foreach (var member in members)
{
var memberPlan = plans.FirstOrDefault(x => x.Id == member.SubscriptionId);
if (memberPlan != null)
member.Subscription = memberPlan;
var e = earnings.Where(x => x.MemberId == member.Id).ToList();
if (e.Count > 0)
earningResponses.Add(new EarningResponse(member, e, promotions));
}
ReportResponse reportResponses = new ReportResponse(earningResponses);
return new JsonContentResult { StatusCode = (int)HttpStatusCode.OK, Content = JsonSerializer.SerializeObject(reportResponses) };
}
Here is my Test Method.
[TestMethod]
public async Task Get()
{
using (var context = new AgencyPortalDbContext(builder.Options))
{
//Arrange
_earningRepository = new Mock<EarningRepository>(context).Object;
_planRepository = new Mock<PlanRepository>(context).Object;
_agentRepository = new Mock<AgentRepository>(context).Object;
_promotionRepository = new Mock<PromotionRepository>(context).Object;
var httpContext = new DefaultHttpContext();
httpContext.Request.Headers.Add("token", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJybWFnZW5jeUBvYnRhaW5jYXJlLmNvbSIsImp0aSI6ImUyMmQwNjJhLWUyNTUtNDlkZS04MmUxLTc1MjgxMTFlOTE1MiIsImlhdCI6MTU2ODgxODQwMCwicm9sIjoiYXBpX2FjY2VzcyIsImVyb2wiOiJTdXBlckFkbWluIiwiaWQiOiI2ODdmMGZjMy1lZjI5LTQ4MGItYTc2Mi0zMGVkZjBlMTkzMWUiLCJBSWQiOiI2IiwibmJmIjoxNTY4ODE4Mzk5LCJleHAiOjE1Njg4MjU1OTksImlzcyI6IndlYkFwaSIsImF1ZCI6Imh0dHBzOi8vZGV2LWFnZW5jeS1hcGktZG90LW9wdGltdW0tb2N0YW5lLTIwMjcxOC5hcHBzcG90LmNvbS8ifQ.lfdMvENhjiSl5ipFXRAw_7aOR6eLT4yLCtbzYu2aZNE"); //Set header
var controllerContext = new ControllerContext()
{
HttpContext = httpContext,
};
_earningController = new EarningController(_earningRepository, _planRepository, _agentRepository, _promotionRepository) { ControllerContext = controllerContext };
//var Earning = new Earning()
//{
// Id = 1,
// Agent = 1,
//};
var Earning = new List<Earning>()
{
new Earning{
Agent = new Agent{
Address1 = "London",
AccountNumber = "1234567765432",
AgencyId = 1,
Address2="RWP",
IdentityId="q",
Gender="Male",
Id = 1,
City = "Rwp",
ContactNumber = "5555344",
LastName = "Khan",
Email = "arslanKhanrwp@gmail.com",
FirstName = "Arslan",
Agency = new Agency
{
AgencyId=1,
Id=1,
AgencyName="RM",
AgencyAgent= new List< AgencyAgent>
{
new AgencyAgent{
AgencyId =1,Id=1,
AgentId=1,
IsActive=true,
} }
}
},
Id=1,
ProducerId=1,
Type=1,
CommissionId=1,
Amount=2000,
MemberInfo= new MemberInfo(){
Id=1,
AgencyId=1,
FirstName="Arslan",
PhoneNumber="1233123",
City="RWO",
ProducerId=1,
Email="arslan@gmail.com",
},
} };
var MemberInfo = new MemberInfo()
{
AgencyId = 1,
Address1 = "RWP",
City = "Rawalpindi",
Email = "arslanKhanrwp@gmail.com",
Id = 1,
FirstName = "Arslan khan",
ProducerId = 1,
LastName = "Khan",
};
var Plan = new Plan()
{
Id = 1,
BaseAmount = 12,
Name = "Arslan",
Type = 1,
};
var Promotion = new Promotion()
{
Id = 1,
IsActive = true,
Validity = 1,
StartDate = DateTime.Now,
};
var EarningResponse = new EarningResponse()
{
AgencyName = "abc",
MemberId = 1,
AgentEmail = "arslanKhanrwp@gmail.com",
TotalEarning = 1200,
MemberName = "ArslanKhan"
};
context.Plans.AddRange();
context.Earnings.AddRange();
context.Earnings.AddRange();
context.SaveChanges();
await _earningRepository.GetProducerEarnings(1);
JsonContentResult result = (JsonContentResult)await _earningController.Get();
//Assert
Assert.AreEqual(0, await context.Contacts.CountAsync());
}
}
}
Aucun commentaire:
Enregistrer un commentaire