Esempio n. 1
0
 public SmartSpotPriceService(SmartSpotPriceConfig config, LoadshopDataContext context, IMapper mapper,
                              HttpClient httpClient,
                              IUserContext userContext,
                              IRecaptchaService recaptchaService,
                              IMileageService mileageService,
                              ISecurityService securityService,
                              ILoadCarrierGroupService loadCarrierGroupService,
                              IShippingService shippingService)
 {
     _config                  = config;
     _db                      = context;
     _mapper                  = mapper;
     _httpClient              = httpClient;
     _userContext             = userContext;
     _recaptchaService        = recaptchaService;
     _mileageService          = mileageService;
     _securityService         = securityService;
     _loadCarrierGroupService = loadCarrierGroupService;
     _shippingService         = shippingService;
 }
            public GetSmartSpotQuote(TestFixture fixture)
            {
                _config = new SmartSpotPriceConfig
                {
                    ApiUrl          = URL,
                    AccessKeyId     = "access-key-id",
                    SecretAccessKey = "secret-access-key",
                    Service         = "service-name",
                    Region          = "us-east-1"
                };
                _db = new MockDbBuilder()
                      .Build();
                _mapper      = fixture.Mapper;
                _httpHandler = new Mock <HttpMessageHandler>();

                var expectedResponse = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new AWSSmartSpotPriceResponse {
                        Results = new List <decimal> {
                            EXPECTED_SPOT_PRICE_0
                        }
                    }))
                };

                _httpHandler.SetupRequest(HttpMethod.Post, URL)
                .ReturnsAsync(expectedResponse);

                _userContext = new Mock <IUserContext>();
                _userContext.SetupGet(_ => _.UserId).Returns(USER_ID);
                _userContext.SetupGet(_ => _.UserName).Returns(USER_NAME);

                _recaptchaService = new Mock <IRecaptchaService>();

                _mileageService = new Mock <IMileageService>();
                _mileageService.Setup(_ => _.GetDirectMiles(It.IsAny <MileageRequestData>())).Returns(100);

                _securityService = new Mock <ISecurityService>();
                _securityService.Setup(_ => _.GetContractedCarriersByPrimaryCustomerIdAsync()).ReturnsAsync(CARRIERS.AsReadOnly());
                _shippingService         = new Mock <IShippingService>();
                _loadCarrierGroupService = new Mock <ILoadCarrierGroupService>();

                InitService();

                _request = new RecaptchaRequest <LoadshopSmartSpotQuoteRequest>
                {
                    Token = "RECAPTCHA_TOKEN",
                    Data  = new LoadshopSmartSpotQuoteRequest
                    {
                        OriginCity            = "Mosinee",
                        OriginState           = "WI",
                        OriginPostalCode      = "54455",
                        OriginCountry         = "USA",
                        DestinationCity       = "Stevens Point",
                        DestinationState      = "WI",
                        DestinationPostalCode = "54481",
                        DestinationCountry    = "USA",
                        EquipmentId           = "53TF102",
                        Weight     = 1000,
                        PickupDate = new DateTime(2020, 02, 01)
                    }
                };
            }
            public GetSmartSpotPrice(TestFixture fixture)
            {
                _config = new SmartSpotPriceConfig
                {
                    ApiUrl          = URL,
                    AccessKeyId     = "access-key-id",
                    SecretAccessKey = "secret-access-key",
                    Service         = "service-name",
                    Region          = "us-east-1"
                };
                _db = new MockDbBuilder()
                      .WithLoad(LOAD_0)
                      .WithLoad(LOAD_1)
                      .WithCarrierScacs(CARRIER_SCACS)
                      .Build();
                _db.SetupSequence(x => x.GetDATGuardRate(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>()))
                .Returns(EXPECTED_GUARD_RATE_0)
                .Returns(EXPECTED_GUARD_RATE_1);

                _mapper = fixture.Mapper;
                var expectedResponse = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new AWSSmartSpotPriceResponse {
                        Results = new List <decimal> {
                            EXPECTED_SPOT_PRICE_0, EXPECTED_SPOT_PRICE_1
                        }
                    }))
                };

                _httpHandler = new Mock <HttpMessageHandler>();
                _httpHandler.SetupRequest(HttpMethod.Post, URL)
                .ReturnsAsync(expectedResponse);

                _userContext      = new Mock <IUserContext>();
                _recaptchaService = new Mock <IRecaptchaService>();

                _mileageService          = new Mock <IMileageService>();
                _securityService         = new Mock <ISecurityService>();
                _shippingService         = new Mock <IShippingService>();
                _loadCarrierGroupService = new Mock <ILoadCarrierGroupService>();

                InitService();

                _requests = new List <LoadshopSmartSpotPriceRequest>
                {
                    new LoadshopSmartSpotPriceRequest
                    {
                        LoadId      = LOAD_ID_0,
                        Weight      = 1,
                        Commodity   = "Beer",
                        EquipmentId = "Equipment",
                        CarrierIds  = new List <string> {
                            "1800PACKRAT", "CARRIER2"
                        }
                    },
                    new LoadshopSmartSpotPriceRequest
                    {
                        LoadId      = LOAD_ID_1,
                        Weight      = 1000,
                        Commodity   = "Beer",
                        EquipmentId = "Equipment",
                        CarrierIds  = new List <string> {
                            "1800PACKRAT"
                        }
                    }
                };

                _awsRequests = new List <AWSSmartSpotPriceRequest>
                {
                    new AWSSmartSpotPriceRequest
                    {
                        LoadId                 = Guid.Empty,
                        TransactionCreate      = DateTime.Now,
                        TransactionTypeId      = "New",
                        LoadShopMiles          = 1,
                        DirectMiles            = 1,
                        Stops                  = 2,
                        Weight                 = 1,
                        EquipmentId            = "Equipment",
                        PkupDate               = DateTime.Now.AddDays(2),
                        OrigState              = "WI",
                        OriginZip              = "54130",
                        O3Zip                  = "541",
                        DestState              = "IL",
                        DestZip                = "60611",
                        D3Zip                  = "606",
                        NbrSCACsRequest        = 1,
                        NbrCarriersRequest     = 1,
                        NbrSCACsPosted         = 0,
                        NbrContractSCACsPosted = 0,
                        NbrSCACsHidden         = 0
                    }
                };
            }