示例#1
0
        protected virtual Mock <IServiceProvider> GetServiceProviderMock(SalesDbContext dbContext)
        {
            var serviceProviderMock = new Mock <IServiceProvider>();

            IIdentityService identityService = new IdentityService {
                Username = "******"
            };

            GarmentPreSalesContractLogic garmentPreSalesContractLogic = new GarmentPreSalesContractLogic(identityService, dbContext);

            CostCalculationGarmentMaterialLogic costCalculationGarmentMaterialLogic = new CostCalculationGarmentMaterialLogic(serviceProviderMock.Object, identityService, dbContext);
            CostCalculationGarmentLogic         costCalculationGarmentLogic         = new CostCalculationGarmentLogic(costCalculationGarmentMaterialLogic, serviceProviderMock.Object, identityService, dbContext);
            CostCalculationByBuyer2ReportLogic  costCalculationByBuyer2ReportLogic  = new CostCalculationByBuyer2ReportLogic(identityService, dbContext);

            Mock <ICostCalculationGarment> mockCostCalculation = new Mock <ICostCalculationGarment>();

            mockCostCalculation.Setup(x => x.ReadByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(new CostCalculationGarment());

            var azureImageFacadeMock = new Mock <IAzureImageFacade>();

            azureImageFacadeMock
            .Setup(s => s.DownloadImage(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync("");

            serviceProviderMock
            .Setup(x => x.GetService(typeof(IdentityService)))
            .Returns(identityService);
            serviceProviderMock
            .Setup(x => x.GetService(typeof(CostCalculationGarmentLogic)))
            .Returns(costCalculationGarmentLogic);
            serviceProviderMock
            .Setup(x => x.GetService(typeof(GarmentPreSalesContractLogic)))
            .Returns(garmentPreSalesContractLogic);

            serviceProviderMock
            .Setup(x => x.GetService(typeof(ICostCalculationGarment)))
            .Returns(mockCostCalculation.Object);

            GarmentSalesContractItemLogic garmentSalesContractItemLogic = new GarmentSalesContractItemLogic(serviceProviderMock.Object, identityService, dbContext);
            GarmentSalesContractLogic     garmentSalesContractLogic     = new GarmentSalesContractLogic(garmentSalesContractItemLogic, serviceProviderMock.Object, identityService, dbContext);

            serviceProviderMock
            .Setup(x => x.GetService(typeof(GarmentSalesContractItemLogic)))
            .Returns(garmentSalesContractItemLogic);

            serviceProviderMock
            .Setup(x => x.GetService(typeof(GarmentSalesContractLogic)))
            .Returns(garmentSalesContractLogic);

            serviceProviderMock
            .Setup(x => x.GetService(typeof(CostCalculationByBuyer2ReportLogic)))
            .Returns(costCalculationByBuyer2ReportLogic);

            serviceProviderMock
            .Setup(x => x.GetService(typeof(IAzureImageFacade)))
            .Returns(azureImageFacadeMock.Object);

            return(serviceProviderMock);
        }
 public GarmentSalesContractFacade(IServiceProvider serviceProvider, SalesDbContext dbContext)
 {
     DbContext                 = dbContext;
     DbSet                     = DbContext.Set <GarmentSalesContract>();
     identityService           = serviceProvider.GetService <IdentityService>();
     garmentSalesContractLogic = serviceProvider.GetService <GarmentSalesContractLogic>();
     costCalGarmentLogic       = serviceProvider.GetService <ICostCalculationGarment>();
 }