Base solution for your next web application
Open Closed

Application Service not returning Data. #7493


User avatar
0
paul.bose created

Hi There, I'm new to ASPNET Zero

Here is my code, let me know why application service(GetCaseDetail) not returning data, However Code first migration and seed works fine. I'm okay if you want to do online meeting. Thanks

Core:

 [Table("HtrCaseDetail")]
    public class CaseDetailData : FullAuditedEntity
    {
    all properties
    }
    
  EF:  
     public class HomicideDbContext : AbpZeroDbContext<Tenant, Role, User>
    {
        /* Define an IDbSet for each entity of the application */

        public virtual IDbSet<BinaryObject> BinaryObjects { get; set; }

        public virtual IDbSet<Friendship> Friendships { get; set; }

        public virtual IDbSet<ChatMessage> ChatMessages { get; set; }

        public virtual IDbSet<CaseDetailData> CaseDetailDatas { get; set; }

        public HomicideDbContext()
            : base("Default")
        {
            
        }
}

Application:

Dto:

     [AutoMapFrom(typeof(CaseDetailData))]
    public class CasedetailListDto : FullAuditedEntityDto
    {
        All Props
    }

 public class GetCaseDetailInput
    {
        public string Filter { get; set; }
    }
    
      public interface ICaseDetailAppService : IApplicationService
    {
        ListResultDto<CasedetailListDto> GetCaseDetail(GetCaseDetailInput input);
    }
    
      class CaseDetailAppService : HomicideAppServiceBase, ICaseDetailAppService
    {

        private readonly IRepository<CaseDetailData> _caseDetailRepository;

        public CaseDetailAppService(IRepository<CaseDetailData> caseDetailRepository)
        {
            _caseDetailRepository = caseDetailRepository;
        }

        public ListResultDto<CasedetailListDto> GetCaseDetail(GetCaseDetailInput input)
        {
            var caseDetails = _caseDetailRepository
                    .GetAll().ToList();
                   

            return new ListResultDto<CasedetailListDto>(ObjectMapper.Map<List<CasedetailListDto>>(caseDetails));

            //throw new NotImplementedException();
        }
    }

Unit test:

 public class CaseDetailAppService_Tests:AppTestBase
    {
        private readonly ICaseDetailAppService _caseDetailAppService;
        public CaseDetailAppService_Tests()
        {
            _caseDetailAppService = Resolve<ICaseDetailAppService>();
        }

        [Fact]
        public void GetAllCasedetail()
        {
            //Act
           var vCaseDetails = _caseDetailAppService.GetCaseDetail(new GetCaseDetailInput());

            //Assert
            vCaseDetails.Items.Count.ShouldBe(2);

        }
    }

2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    In the unit test, did you seed the test data in the TestDataBuilder class?

    https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/test/MyCompanyName.AbpZeroTemplate.Test.Base/TestData/TestDataBuilder.cs#L17

  • User Avatar
    0
    paul.bose created

    Thank you, it works, I guess adding seed data in 'TestDatas' folder is missing MVC+Jquery Doc.