public void AddRoutingRule_ValidArguments_ShouldAddRoutingRules()
        {
            //Arrange
            var mockFacilityGuid                = Utility.ParseStringToGuid(_executionContextAccessor.Current.Facility.FacilityKey);
            var mockRoutingRuleGuid             = Utility.GetNewGuid();
            Dictionary <string, string> headers = new Dictionary <string, string>();

            var mockScheduleGuid = Guid.Parse("E767B738-3944-4896-93A0-6F074BA16890");

            var fakeRountingSchedule = new RequestRoutingRuleSchedule
            {
                ScheduleKey = mockScheduleGuid
            };
            var routingRuleScheduleList = new List <RequestRoutingRuleSchedule>();

            routingRuleScheduleList.Add(fakeRountingSchedule);

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

            //Act
            var response = _routingRuleManager.AddRoutingRule(routingRuleReq, headers);

            //Assert
            Assert.Contains("Routing Rule Created Successfully", response.Message);
            Assert.True(response.IsSuccess);
        }
        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 UpdateRoutingRule_ValidArgument_ShouldUpdateRoutingRule()
        {
            //Arrange
            var mockFacilityGuid     = Utility.ParseStringToGuid(_executionContextAccessor.Current.Facility.FacilityKey);
            var mockRoutingRuleGuid1 = Utility.GetNewGuid();
            var mockRoutingRuleName1 = "test";
            var mockRoutingRuleGuid2 = Utility.GetNewGuid();
            var mockRoutingRuleName2 = "test new";

            var mockScheduleGuid1 = Utility.GetNewGuid();
            var mockScheduleGuid2 = Utility.GetNewGuid();

            Dictionary <string, string> headers = new Dictionary <string, string>();

            var fakeSchedule1 = new ScheduleTiming
            {
                ScheduleTimingKey  = mockScheduleGuid1,
                ScheduleTimingName = "Test Schedule"
            };

            var fakeSchedule2 = new ScheduleTiming
            {
                ScheduleTimingKey  = mockScheduleGuid2,
                ScheduleTimingName = "Test Schedule 2"
            };
            var fakeRoutingRuleSchedule = new RoutingRuleScheduleTiming
            {
                RoutingRuleScheduleTimingKey = Utility.GetNewGuid(),
                TenantKey         = Utility.ParseStringToGuid(_executionContextAccessor.Current.Tenant.TenantKey),
                ScheduleTimingKey = mockScheduleGuid1,
                RoutingRuleKey    = mockRoutingRuleGuid2,
            };

            var fakeCollectionRoutingRuleSchedule = new List <RoutingRuleScheduleTiming>();

            fakeCollectionRoutingRuleSchedule.Add(fakeRoutingRuleSchedule);

            var fakeRoutingRule1 = Task.FromResult <RoutingRule>(new RoutingRule
            {
                RoutingRuleKey  = mockRoutingRuleGuid1,
                RoutingRuleName = mockRoutingRuleName1,
                FacilityKey     = mockFacilityGuid,
                TenantKey       = Utility.ParseStringToGuid(_executionContextAccessor.Current.Tenant.TenantKey),
            });

            var fakeRoutingRule2 = Task.FromResult <RoutingRule>(new RoutingRule
            {
                RoutingRuleKey            = mockRoutingRuleGuid2,
                RoutingRuleName           = mockRoutingRuleName2,
                FacilityKey               = mockFacilityGuid,
                TenantKey                 = Utility.ParseStringToGuid(_executionContextAccessor.Current.Tenant.TenantKey),
                RoutingRuleScheduleTiming = fakeCollectionRoutingRuleSchedule
            });


            var fakeRountingSchedule = new RequestRoutingRuleSchedule
            {
                ScheduleKey = mockScheduleGuid2
            };
            var routingRuleScheduleList = new List <RequestRoutingRuleSchedule>();

            routingRuleScheduleList.Add(fakeRountingSchedule);


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

            _mockRoutingRuleRepository.Setup(x => x.GetRoutingRule(mockRoutingRuleName1, mockFacilityGuid)).Returns(fakeRoutingRule1);
            _mockRoutingRuleRepository.Setup(x => x.GetRoutingRule(mockRoutingRuleGuid2, mockFacilityGuid)).Returns(fakeRoutingRule2);

            //Act
            var response = _routingRuleManager.UpdateRoutingRule(routingRuleReq, mockRoutingRuleGuid2, headers);

            //Assert
            Assert.Contains("Routing Rule Updated Successfully", response.Message);
            Assert.True(response.IsSuccess);
        }