public void GetAll_ValidArguments_ShouldReturnRoutingRules()
        {
            //Arrange
            var mockFacilityKey = Utility.ParseStringToGuid(_executionContextAccessor.Current.Facility.FacilityKey);
            var mockGuid        = Guid.Parse("E767B738-3944-4896-93A0-6F074BA16890");
            var fakeSchedule    = new ScheduleResponse
            {
                Key = mockGuid
            };
            var scheduleList = new List <ScheduleResponse>();

            scheduleList.Add(fakeSchedule);
            _mockScheduleBusiness.Setup(x => x.GetSchedules(It.IsAny <Guid>())).ReturnsAsync(scheduleList);

            var mockRoutingRuleGuid = new Guid();
            var fakeRoutingRule     = new RoutingRule
            {
                FacilityKey     = mockFacilityKey,
                RoutingRuleKey  = mockRoutingRuleGuid,
                RoutingRuleName = "test",
            };
            var routingList = new List <RoutingRule>();

            routingList.Add(fakeRoutingRule);
            routingList.AsEnumerable();
            _mockRoutingRuleRepository.Setup(x => x.GetRoutingRules(mockFacilityKey, 0, 0, "")).ReturnsAsync(routingList);
            //Act
            var response = _routingRuleManager.GetAllRoutingRule();

            //Assert
            Assert.Equal(mockRoutingRuleGuid, response.First().RoutingRuleKey);
        }
        public void GetAll_ValidArguments_NoRecord_Exist()
        {
            //Arrange
            var mockGuid     = Guid.Parse("E767B738-3944-4896-93A0-6F074BA16890");
            var fakeSchedule = new Schedule
            {
                Key = mockGuid
            };
            var scheduleList = new List <Schedule>();

            scheduleList.Add(fakeSchedule);
            _mockScheduleBusiness.Setup(x => x.GetSchedules(It.IsAny <Guid>())).ReturnsAsync(scheduleList);

            var mockRoutingRuleGuid = new Guid();
            var fakeRoutingRule     = new RoutingRule
            {
                FacilityKey     = mockGuid,
                RoutingRuleKey  = mockRoutingRuleGuid,
                RoutingRuleName = "test",
            };
            var routingList = new List <RoutingRule>();

            routingList.Add(fakeRoutingRule);
            routingList.AsEnumerable();
            _mockRoutingRuleRepository.Setup(x => x.GetRoutingRules(mockGuid, 0, 0, "")).ReturnsAsync(routingList);
            //Act
            var response = _routingRuleManager.GetAllRoutingRule(mockRoutingRuleGuid);

            //Assert
            Assert.Null(response);
        }
Exemplo n.º 3
0
        public void FetchTests()
        {
            List <RoutingRule> oRules;
            var res = RoutingRule.GetRoutingRules(_connectionServer, out oRules, 1, 10, null);

            Assert.IsTrue(res.Success, "Fetching routing rules failed:" + res);
            Assert.IsTrue(oRules.Count > 0, "No rules returned in fetch:" + res);

            RoutingRule oRule = oRules[0];

            Console.WriteLine(oRule.ToString());
            Console.WriteLine(oRule.DumpAllProps("--->"));

            RoutingRule oTest;

            res = RoutingRule.GetRoutingRule(out oTest, _connectionServer, oRule.ObjectId);
            Assert.IsTrue(res.Success, "Failed to create routing rule with valid ObjectId:" + res);
            Assert.IsTrue(oTest.ObjectId.Equals(oRule.ObjectId), "Fetched routing rule does not match objectId");

            res = RoutingRule.GetRoutingRule(out oTest, _connectionServer, "", oRule.DisplayName);
            Assert.IsTrue(res.Success, "Failed to create routing rule with valid display name:" + res);
            Assert.IsTrue(oTest.ObjectId.Equals(oRule.ObjectId), "Fetched routing rule does not match objectId");

            res = oTest.RefetchRoutingRuleData();
            Assert.IsTrue(res.Success, "Failed to refetch routing rule data");

            res = RoutingRule.GetRoutingRules(_connectionServer, out oRules, 1, 10, "query=(ObjectId is Bogus)");
            Assert.IsTrue(res.Success, "fetching rules with invalid query should not fail:" + res);
            Assert.IsTrue(oRules.Count == 0, "Invalid query string should return an empty rule list:" + oRules.Count);
        }
Exemplo n.º 4
0
        public async Task Request_WithAnonymousUser_ReturnsUnauthorized()
        {
            // Arrange
            var builder = new WebHostBuilder()
                          .ConfigureServices(services =>
            {
                services.AddPorthor()
                .AddAuthenticationValidation();
            })
                          .Configure(app =>
            {
                var routingRule = new RoutingRule
                {
                    HttpMethod   = HttpMethod.Get,
                    FrontendPath = "api/values",
                    BackendUrl   = "http://example.org/api/values"
                };

                app.UsePorthor(new[] { routingRule });
            });
            var server = new TestServer(builder);

            // Act
            var requestMessage  = new HttpRequestMessage(HttpMethod.Get, "api/values");
            var responseMessage = await server.CreateClient().SendAsync(requestMessage);

            // Assert
            Assert.Equal(HttpStatusCode.Unauthorized, responseMessage.StatusCode);
        }
Exemplo n.º 5
0
        public void GetRoutingRules_NullConnectionServer_Failure()
        {
            List <RoutingRule> oRules;
            var res = RoutingRule.GetRoutingRules(null, out oRules);

            Assert.IsFalse(res.Success, "Calling GetRoutingRules with null ConnectionServerRest should fail");
        }
Exemplo n.º 6
0
        public void GetRoutingRule_EmptyObjectIdAndDisplayName_Failure()
        {
            RoutingRule oRule;
            var         res = RoutingRule.GetRoutingRule(out oRule, _mockServer, "", "");

            Assert.IsFalse(res.Success, "Calling GetRoutingRule with empty objectId and display name should fail");
        }
Exemplo n.º 7
0
        public void UpdateRoutingRule_EmptyProperties_Failure()
        {
            ConnectionPropertyList oProps = new ConnectionPropertyList();
            var res = RoutingRule.UpdateRoutingRule(_mockServer, "objectid", oProps);

            Assert.IsFalse(res.Success, "Calling UpdateRoutingRule with empty properties should fail");
        }
Exemplo n.º 8
0
        public void GetRoutingRule_NullConnectionServer_Failure()
        {
            RoutingRule oRule;
            var         res = RoutingRule.GetRoutingRule(out oRule, null, "objectId", "displayname");

            Assert.IsFalse(res.Success, "Calling GetRoutingRule with null ConnectionServerRest should fail");
        }
Exemplo n.º 9
0
        private static void SetBucketWebsite()
        {
            try
            {
                SetBucketWebsiteRequest request = new SetBucketWebsiteRequest();
                request.BucketName    = bucketName;
                request.Configuration = new WebsiteConfiguration();

                request.Configuration.IndexDocument = "index.html";

                request.Configuration.ErrorDocument = "error.html";

                RoutingRule routingRule = new RoutingRule();
                routingRule.Redirect                              = new Redirect();
                routingRule.Redirect.HostName                     = "www.example.com";
                routingRule.Redirect.HttpRedirectCode             = "305";
                routingRule.Redirect.Protocol                     = ProtocolEnum.Http;
                routingRule.Redirect.ReplaceKeyPrefixWith         = "replacekeyprefix";
                routingRule.Condition                             = new Condition();
                routingRule.Condition.HttpErrorCodeReturnedEquals = "404";
                routingRule.Condition.KeyPrefixEquals             = "keyprefix";
                request.Configuration.RoutingRules                = new List <RoutingRule>();
                request.Configuration.RoutingRules.Add(routingRule);

                SetBucketWebsiteResponse response = client.SetBucketWebsiteConfiguration(request);
                Console.WriteLine("Set bucket website response: {0}", response.StatusCode);
            }
            catch (ObsException ex)
            {
                Console.WriteLine("Exception errorcode: {0}, when set bucket website.", ex.ErrorCode);
                Console.WriteLine("Exception errormessage: {0}", ex.ErrorMessage);
            }
        }
Exemplo n.º 10
0
        public void GetRoutingRule_InvalidObjectId_Failure()
        {
            RoutingRule oRule;
            var         res = RoutingRule.GetRoutingRule(out oRule, _connectionServer, "objectId");

            Assert.IsFalse(res.Success, "Calling GetRoutingRule with invalid objectId should fail");
        }
Exemplo n.º 11
0
        public void RoutingRule_Constructor_EmptyObjectIdAndDisplayName_Success()
        {
            RoutingRule oTemp = new RoutingRule(_mockServer, "");

            Console.WriteLine(oTemp.SelectionDisplayString);
            Console.WriteLine(oTemp.UniqueIdentifier);
        }
Exemplo n.º 12
0
        public void RoutingRule_Constructor_ObjectId_Success()
        {
            Reset();
            RoutingRule oTemp = new RoutingRule(_mockServer, "ObjectId");

            Console.WriteLine(oTemp);
        }
Exemplo n.º 13
0
        public void AddRoutingRule_EmptyDisplayName_Failure()
        {
            RoutingRule oRoutingRule;
            var         res = RoutingRule.AddRoutingRule(_mockServer, "", null, out oRoutingRule);

            Assert.IsFalse(res.Success, "Calling AddRoutingRule with empty display name should fail");
        }
Exemplo n.º 14
0
        public async Task Request_WithForbiddenQueryParameter_ReturnsBadRequest()
        {
            // Arrange
            var builder = new WebHostBuilder()
                          .ConfigureServices(services =>
            {
                services.AddPorthor()
                .AddQueryStringValidation();
            })
                          .Configure(app =>
            {
                var routingRule = new RoutingRule
                {
                    HttpMethod   = HttpMethod.Get,
                    FrontendPath = "api/values",
                    BackendUrl   = "http://example.org/api/values"
                };

                app.UsePorthor(new[] { routingRule });
            });
            var server = new TestServer(builder);

            // Act
            var requestMessage  = new HttpRequestMessage(HttpMethod.Get, "api/values?query=test");
            var responseMessage = await server.CreateClient().SendAsync(requestMessage);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, responseMessage.StatusCode);
        }
Exemplo n.º 15
0
        public void RoutingRule_Constructor_Default_Success()
        {
            RoutingRule oTemp = new RoutingRule();

            Console.WriteLine(oTemp.ToString());
            Console.WriteLine(oTemp.DumpAllProps());
        }
Exemplo n.º 16
0
        public void GetRoutingRule_InvalidDisplayName_Failure()
        {
            RoutingRule oRule;
            var         res = RoutingRule.GetRoutingRule(out oRule, _connectionServer, "", "bogus");

            Assert.IsFalse(res.Success, "Calling GetRoutingRule with invalid dispaly name should fail");
        }
        public void AddRoutingRule_ValidArguments_ShouldAddRoutingRules()
        {
            //Arrange
            var mockTenantGuid                  = Guid.Parse("E767B738-3944-4896-93A0-6F074BA16890");
            var mockFacilityGuid                = Guid.Parse("6DD7B978-2BAE-4C0B-9ED2-0A79FB689A46");
            var mockRoutingRuleGuid             = Utility.GetNewGuid();
            Dictionary <string, string> headers = new Dictionary <string, string>();

            var mockScheduleGuid = Guid.Parse("E767B738-3944-4896-93A0-6F074BA16890");
            var fakeSchedule     = new RequestRoutingRuleSchedule
            {
                ScheduleId = mockScheduleGuid
            };
            var scheduleList = new List <RequestRoutingRuleSchedule>();

            scheduleList.Add(fakeSchedule);

            var routingRuleReq = new RoutingRuleRequest
            {
                RoutingRuleName = "test new",
                SearchCriteriaGranularityLevel = 1,
                ActorKey             = Guid.Parse("6DD7B978-2BAE-4C0B-9ED2-0A79FB689A46"),
                RoutingRuleSchedules = scheduleList,
            };

            var fakeRoutingRuleScheduleTiming = new RoutingRuleScheduleTiming {
                RoutingRuleScheduleTimingKey = Utility.GetNewGuid(),
                TenantKey               = mockTenantGuid, // Guid.Parse(_executionContextAccessor.Current.Tenant.TenantKey),
                ScheduleTimingKey       = mockScheduleGuid,
                RoutingRuleKey          = mockRoutingRuleGuid,
                CreatedByActorKey       = routingRuleReq.ActorKey,
                LastModifiedByActorKey  = routingRuleReq.ActorKey,
                CreatedDateUTCDateTime  = DateTimeOffset.Now,
                LastModifiedUTCDateTime = DateTimeOffset.Now
            };
            var _schedules = new List <RoutingRuleScheduleTiming>();

            _schedules.Add(fakeRoutingRuleScheduleTiming);

            var mockRoutingRule = new RoutingRule
            {
                RoutingRuleName = routingRuleReq.RoutingRuleName.Trim(),
                TenantKey       = mockTenantGuid, // Guid.Parse(_executionContextAccessor.Current.Tenant.TenantKey),
                FacilityKey     = mockFacilityGuid,
                SearchCriteriaGranularityLevel = routingRuleReq.SearchCriteriaGranularityLevel,
                CreatedByActorKey         = routingRuleReq.ActorKey,
                LastModifiedByActorKey    = routingRuleReq.ActorKey,
                RoutingRuleScheduleTiming = _schedules.Count() > 0 ? _schedules : null,
                RoutingRuleKey            = mockRoutingRuleGuid,
            };

            //_mockRoutingRuleRepository.Setup(x => x.Add(mockRoutingRule)).Returns();
            //Act
            var response = _routingRuleManager.AddRoutingRule(routingRuleReq, mockFacilityGuid, headers);

            //Assert
            Assert.Contains("Routing Rule Created Successfully", response.Message);
            Assert.Equal(mockRoutingRuleGuid, response.Id);
        }
Exemplo n.º 18
0
        public void PropertyGetFetch_RouteAction()
        {
            RoutingRule oRule = new RoutingRule();
            const RoutingRuleActionType expectedValue = RoutingRuleActionType.Hangup;

            oRule.RouteAction = expectedValue;
            Assert.IsTrue(oRule.ChangeList.ValueExists("RouteAction", (int)expectedValue), "RouteAction value get fetch failed");
        }
Exemplo n.º 19
0
        public void PropertyGetFetch_Undeletable()
        {
            RoutingRule oRule         = new RoutingRule();
            const bool  expectedValue = true;

            oRule.Undeletable = expectedValue;
            Assert.IsTrue(oRule.ChangeList.ValueExists("Undeletable", expectedValue), "Undeletable value get fetch failed");
        }
Exemplo n.º 20
0
        public void PropertyGetFetch_UseDefaultLanguage()
        {
            RoutingRule oRule         = new RoutingRule();
            const bool  expectedValue = false;

            oRule.UseDefaultLanguage = expectedValue;
            Assert.IsTrue(oRule.ChangeList.ValueExists("UseDefaultLanguage", expectedValue), "UseDefaultLanguage value get fetch failed");
        }
Exemplo n.º 21
0
        public void PropertyGetFetch_RouteTargetHandlerObjectId()
        {
            RoutingRule  oRule         = new RoutingRule();
            const string expectedValue = "String test";

            oRule.RouteTargetHandlerObjectId = expectedValue;
            Assert.IsTrue(oRule.ChangeList.ValueExists("RouteTargetHandlerObjectId", expectedValue), "RouteTargetHandlerObjectId value get fetch failed");
        }
Exemplo n.º 22
0
        public void PropertyGetFetch_RouteTargetConversation()
        {
            RoutingRule             oRule         = new RoutingRule();
            const ConversationNames expectedValue = ConversationNames.SystemTransfer;

            oRule.RouteTargetConversation = expectedValue;
            Assert.IsTrue(oRule.ChangeList.ValueExists("RouteTargetConversation", expectedValue.ToString()), "RouteTargetConversation value get fetch failed");
        }
Exemplo n.º 23
0
        public void PropertyGetFetch_Type()
        {
            RoutingRule           oRule         = new RoutingRule();
            const RoutingRuleType expectedValue = RoutingRuleType.Forwarded;

            oRule.Type = expectedValue;
            Assert.IsTrue(oRule.ChangeList.ValueExists("Type", (int)expectedValue), "Type value get fetch failed");
        }
Exemplo n.º 24
0
        public void PropertyGetFetch_State()
        {
            RoutingRule            oRule         = new RoutingRule();
            const RoutingRuleState expectedValue = RoutingRuleState.Inactive;

            oRule.State = expectedValue;
            Assert.IsTrue(oRule.ChangeList.ValueExists("State", (int)expectedValue), "State value get fetch failed");
        }
Exemplo n.º 25
0
        public void PropertyGetFetch_LanguageCode()
        {
            RoutingRule oRule         = new RoutingRule();
            const int   expectedValue = 1066;

            oRule.LanguageCode = expectedValue;
            Assert.IsTrue(oRule.ChangeList.ValueExists("LanguageCode", expectedValue), "LanguageCode value get fetch failed");
        }
Exemplo n.º 26
0
        public void PropertyGetFetch_SearchSpaceObjectId()
        {
            RoutingRule  oRule         = new RoutingRule();
            const string expectedValue = "String test";

            oRule.SearchSpaceObjectId = expectedValue;
            Assert.IsTrue(oRule.ChangeList.ValueExists("SearchSpaceObjectId", expectedValue), "SearchSpaceObjectId value get fetch failed");
        }
Exemplo n.º 27
0
        public void PropertyGetFetch_CallType()
        {
            RoutingRule oRule = new RoutingRule();
            const RoutingRuleCallType expectedValue = RoutingRuleCallType.External;

            oRule.CallType = expectedValue;
            Assert.IsTrue(oRule.ChangeList.ValueExists("CallType", (int)expectedValue), "CallType value get fetch failed");
        }
Exemplo n.º 28
0
        public void GetRoutingRules_ValidQuery_NoResults()
        {
            List <RoutingRule> oRules;
            var res = RoutingRule.GetRoutingRules(_connectionServer, out oRules, 1, 20, "query=(ObjectId is blah)");

            Assert.IsTrue(res.Success, "Calling GetRoutingRules with valid query should not fail:" + res);
            Assert.IsTrue(oRules.Count == 0, "Getting rules with valid query for no results should return 0 rules, returned:" + oRules.Count);
        }
Exemplo n.º 29
0
        public void GetRoutingRules_InvalidQuery_Failure()
        {
            List <RoutingRule> oRules;
            var res = RoutingRule.GetRoutingRules(_connectionServer, out oRules, 1, 20, "query=(blah is blah)");

            Assert.IsFalse(res.Success, "Calling GetRoutingRules with invalid query should fail:");
            Assert.IsTrue(oRules.Count == 0, "Getting rules with invalid query should return 0 rules, returned:" + oRules.Count);
        }
Exemplo n.º 30
0
        /// <summary>
        /// to get routing rule by Id.
        /// </summary>
        /// <param name="ruleId"></param>
        /// <param name="facilityID"></param>
        /// <returns></returns>
        public RoutingRulesById GetByID(Guid ruleId)
        {
            var facilityID = Utility.ParseStringToGuid(_executionContextAccessor.Current.Facility.FacilityKey);

            RoutingRule rule = _routingRulesRepository.GetRoutingRule(ruleId, facilityID).GetAwaiter().GetResult();

            return(_mapper.Map <RoutingRulesById>(rule));
        }
Exemplo n.º 31
0
        public void Send(byte[] buffer, byte[] dstUuid, RoutingRule routingRule)
        {
            // todo supported for token

            // gateMessageType => byte
            // serviceId => int32
            // uuid => byte[4]
            var gateMsgBuffer = new byte[] { (byte)GateMessage.Send };
            var serviceId = routingRule.GateRule.GetServiceId();
            var head = new byte[sizeof(Int32)+1];

            Helper.Int32ToByteArray(serviceId, head, 0);
            head[4] = (byte) Mode.Invoke;

            handle.SendDatav(gateMsgBuffer, uuid.ToByteArray(), head, buffer);
        }
Exemplo n.º 32
0
 public void Send(byte[] buffer, byte[] dstUuid, RoutingRule routingRule)
 {
     lock (mqChannel)
     {
         //todo uuid.ToString() consumes too much
         mqChannel.BasicPublish(routingRule.AmqpRule.GetDelegateExchangeName(), routingRule.AmqpRule.GetDelegateRoutingKey(dstUuid), null, buffer);
     }
 }
Exemplo n.º 33
0
 public void Send(byte[] buffer, byte[] dstUuid, RoutingRule routingRule)
 {
     // modify data associated with a node
     // no need to concern version , at present
     var ret = handle.SetData(routingRule.ZkRule.GetServicePath(), buffer, -1);
 }
Exemplo n.º 34
0
 public void Send(byte[] buffer, byte[] dstUuid, RoutingRule routingRule)
 {
     // mqttclient push msg to a thread-safe queue
     try
     {
         //todo uuid.ToString() 
         //todo dstUuid arg have no use here
         handle.Publish(routingRule.MqttRule.GetPublishKey(uuid), new MqttPayload(buffer, 0), QoS.BestEfforts, false);
     }
     catch (Exception e)
     {
         Log.Error("MqttAdaptor Send throw exp:{0}", e);
     }
 }