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); }
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); }
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); }
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"); }
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"); }
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"); }
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"); }
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); } }
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"); }
public void RoutingRule_Constructor_EmptyObjectIdAndDisplayName_Success() { RoutingRule oTemp = new RoutingRule(_mockServer, ""); Console.WriteLine(oTemp.SelectionDisplayString); Console.WriteLine(oTemp.UniqueIdentifier); }
public void RoutingRule_Constructor_ObjectId_Success() { Reset(); RoutingRule oTemp = new RoutingRule(_mockServer, "ObjectId"); Console.WriteLine(oTemp); }
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"); }
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); }
public void RoutingRule_Constructor_Default_Success() { RoutingRule oTemp = new RoutingRule(); Console.WriteLine(oTemp.ToString()); Console.WriteLine(oTemp.DumpAllProps()); }
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); }
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"); }
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"); }
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"); }
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"); }
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"); }
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"); }
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"); }
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"); }
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"); }
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"); }
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); }
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); }
/// <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)); }
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); }
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); } }
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); }
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); } }