示例#1
0
 /// <inheritdoc />
 public void Initialize(TargetClientConfig clientConfig)
 {
     Logger = clientConfig.Logger;
     VisitorProvider.Initialize(clientConfig.OrganizationId);
     this.targetService            = new TargetService(clientConfig);
     this.localService             = new OnDeviceDecisioningService(clientConfig, this.targetService);
     this.defaultDecisioningMethod = clientConfig.DecisioningMethod;
     this.defaultPropertyToken     = clientConfig.DefaultPropertyToken;
     Logger?.LogDebug("Initialized Target Client: " + clientConfig.OrganizationId);
 }
示例#2
0
        private void RunSuiteTest(IDictionary <string, object> suite, KeyValuePair <string, object> testEntry)
        {
            var test = (IDictionary <string, object>)testEntry.Value;

            this.output.WriteLine($"Test: {testEntry.Key} - {test["description"]}");

            var config       = (IDictionary <string, object>)(test.ContainsKey("conf") ? test["conf"] : suite["conf"]);
            var artifact     = (string)(test.ContainsKey("artifact") ? test["artifact"] : suite["artifact"]);
            var clientConfig = this.GetTargetClientConfig(config, artifact);

            VisitorProvider.Initialize(clientConfig.OrganizationId);
            var mockTargetService = new Mock <ITargetService>();
            var mockGeo           = IntegrationTestUtils.GetMockGeo(test);

            IntegrationTestUtils.SetupMockDateTime(test);
            var decisioningService = new OnDeviceDecisioningService(clientConfig, mockTargetService.Object, mockGeo?.Object);
            var targetRequest      = GetTargetDeliveryRequest(test);

            var expectedResponseObject     = test.ContainsKey("output") ? test["output"] : null;
            var expectedNotificationObject = test.ContainsKey("notificationOutput") ? test["notificationOutput"] : null;
            var response = decisioningService.ExecuteRequest(targetRequest);

            if (expectedResponseObject != null)
            {
                var expectedResponse = IntegrationTestUtils.ConvertExpectedResponse(expectedResponseObject);
                _ = response.Response.Should().BeEquivalentTo(expectedResponse, IntegrationTestUtils.RootResponseEquivalenceOptions);
            }

            if (expectedNotificationObject != null)
            {
                var expectedNotificationRequestObject = ((IDictionary <string, object>)expectedNotificationObject)["request"];
                var expectedNotification = SerializationUtils.ConvertObject <DeliveryRequest>(expectedNotificationRequestObject);
                Thread.Sleep(500);
                var notificationRequest = ((TargetDeliveryRequest)mockTargetService.Invocations.Last().Arguments.First()).DeliveryRequest;
                _ = notificationRequest.Should().BeEquivalentTo(expectedNotification, IntegrationTestUtils.RootRequestEquivalenceOptions);
            }

            TimeProvider.ResetToDefault();
        }