public void Ordering_by_agency_ancestors() { var markupSubject = new MarkupSubjectInfo { AgencyAncestors = new List <int> { 3, 2 }, AgencyId = 1, AgentId = 1, CountryHtId = "Russia", LocalityHtId = "Moscow" }; var markupDestination = new MarkupDestinationInfo { AccommodationHtId = "President Hotel", CountryHtId = "UAE", LocalityHtId = "Dubai" }; var markupPolicies = new List <MarkupPolicy> { new() { Id = 9, Order = 1, SubjectScopeType = SubjectMarkupScopeTypes.Agency, SubjectScopeId = "1", DestinationScopeType = DestinationMarkupScopeTypes.Global }, new() { Id = 7, Order = 4, SubjectScopeType = SubjectMarkupScopeTypes.Agency, SubjectScopeId = "2", DestinationScopeType = DestinationMarkupScopeTypes.Global }, new() { Id = 5, Order = 1, SubjectScopeType = SubjectMarkupScopeTypes.Agency, SubjectScopeId = "3", DestinationScopeType = DestinationMarkupScopeTypes.Global }, }; var service = MarkupPolicyServiceMock.Create(markupPolicies); var policies = service.Get(markupSubject, markupDestination, default); Assert.Equal("3", policies[0].SubjectScopeId); Assert.Equal("2", policies[1].SubjectScopeId); Assert.Equal("1", policies[2].SubjectScopeId); }
public void Specific_agent_and_specific_hotel() { var markupSubject = new MarkupSubjectInfo { AgencyAncestors = new List <int>(), AgencyId = 1, AgentId = 1, CountryHtId = "Russia", LocalityHtId = "Moscow" }; var markupDestination = new MarkupDestinationInfo { AccommodationHtId = "President Hotel", CountryHtId = "UAE", LocalityHtId = "Dubai" }; var markupPolicies = new List <MarkupPolicy> { new() { Id = 1, Order = 1, SubjectScopeType = SubjectMarkupScopeTypes.Agent, SubjectScopeId = AgentInAgencyId.Create(agentId: 1, agencyId: 1).ToString(), DestinationScopeType = DestinationMarkupScopeTypes.Accommodation, DestinationScopeId = "President Hotel" }, new() { Id = 2, Order = 2, SubjectScopeType = SubjectMarkupScopeTypes.Agent, SubjectScopeId = AgentInAgencyId.Create(agentId: 2, agencyId: 1).ToString(), DestinationScopeType = DestinationMarkupScopeTypes.Accommodation, DestinationScopeId = "President Hotel" } }; var service = MarkupPolicyServiceMock.Create(markupPolicies); var policies = service.Get(markupSubject, markupDestination, default); Assert.Single(policies); Assert.Equal(1, policies[0].Id); } }
public List<MarkupPolicy> Get(MarkupSubjectInfo subjectInfo, MarkupDestinationInfo destinationInfo, MarkupPolicyTarget policyTarget) { var agencyId = subjectInfo.AgencyId; var agencyTreeIds = subjectInfo.AgencyAncestors; agencyTreeIds.Add(agencyId); var policies = _markupPolicyStorage.Get(policy => IsApplicableBySubject(policy, subjectInfo) && IsApplicableByObject(policy, destinationInfo) ); return policies .OrderBy(p => p.SubjectScopeType) .ThenBy(p => p.DestinationScopeType) .ThenBy(p => p.SubjectScopeType == SubjectMarkupScopeTypes.Agency && p.SubjectScopeId != string.Empty ? agencyTreeIds.IndexOf(int.Parse(p.SubjectScopeId)) : 0) .ThenBy(p => p.Order) .ToList();
public void Global_markups_should_be_returned() { var markupSubject = new MarkupSubjectInfo { AgencyAncestors = new List <int>(), AgencyId = 1, AgentId = 1, CountryHtId = "Russia", LocalityHtId = "Moscow" }; var markupDestination = new MarkupDestinationInfo { AccommodationHtId = "President Hotel", CountryHtId = "UAE", LocalityHtId = "Dubai" }; var markupPolicies = new List <MarkupPolicy> { new() { Id = 1, Order = 1, SubjectScopeType = SubjectMarkupScopeTypes.Global, DestinationScopeType = DestinationMarkupScopeTypes.Global }, new() { Id = 2, Order = 2, SubjectScopeType = SubjectMarkupScopeTypes.Locality, SubjectScopeId = "Kiev", DestinationScopeType = DestinationMarkupScopeTypes.Global } }; var service = MarkupPolicyServiceMock.Create(markupPolicies); var policies = service.Get(markupSubject, markupDestination, default); Assert.Single(policies); Assert.Equal(1, policies[0].Id); }
public void Markups_for_specific_hotel_should_be_returned() { var markupSubject = GetDummyMarkupSubject(); var markupDestination = new MarkupDestinationInfo { AccommodationHtId = "President Hotel", CountryHtId = "UAE", LocalityHtId = "Dubai" }; var markupPolicies = new List <MarkupPolicy> { new() { Id = 1, Order = 1, SubjectScopeType = SubjectMarkupScopeTypes.Global, DestinationScopeType = DestinationMarkupScopeTypes.Accommodation, DestinationScopeId = "President Hotel" }, new() { Id = 2, Order = 2, SubjectScopeType = SubjectMarkupScopeTypes.Global, DestinationScopeType = DestinationMarkupScopeTypes.Accommodation, DestinationScopeId = "Hilton" } }; var service = MarkupPolicyServiceMock.Create(markupPolicies); var policies = service.Get(markupSubject, markupDestination, default); Assert.Single(policies); Assert.Equal(1, policies[0].Id); }
public void Ordering_by_subject_scope_type() { var markupSubject = new MarkupSubjectInfo { AgencyAncestors = new List <int>(), AgencyId = 1, AgentId = 1, CountryHtId = "Russia", LocalityHtId = "Moscow" }; var markupDestination = new MarkupDestinationInfo { AccommodationHtId = "President Hotel", CountryHtId = "UAE", LocalityHtId = "Dubai" }; var markupPolicies = new List <MarkupPolicy> { new() { Id = 9, Order = 1, SubjectScopeType = SubjectMarkupScopeTypes.Global, DestinationScopeType = DestinationMarkupScopeTypes.Country, DestinationScopeId = "UAE" }, new() { Id = 7, Order = 4, SubjectScopeType = SubjectMarkupScopeTypes.Global, DestinationScopeType = DestinationMarkupScopeTypes.Global }, new() { Id = 5, Order = 1, SubjectScopeType = SubjectMarkupScopeTypes.Global, DestinationScopeType = DestinationMarkupScopeTypes.Accommodation, DestinationScopeId = "President Hotel" }, new() { Id = 2, Order = 2, SubjectScopeType = SubjectMarkupScopeTypes.Global, DestinationScopeType = DestinationMarkupScopeTypes.Locality, DestinationScopeId = "Dubai" } }; var service = MarkupPolicyServiceMock.Create(markupPolicies); var policies = service.Get(markupSubject, markupDestination, default); Assert.Equal(DestinationMarkupScopeTypes.Global, policies[0].DestinationScopeType); Assert.Equal(DestinationMarkupScopeTypes.Country, policies[1].DestinationScopeType); Assert.Equal(DestinationMarkupScopeTypes.Locality, policies[2].DestinationScopeType); Assert.Equal(DestinationMarkupScopeTypes.Accommodation, policies[3].DestinationScopeType); } }
public async Task <TDetails> ApplyMarkups <TDetails>(MarkupSubjectInfo subject, MarkupDestinationInfo destinationInfo, TDetails details, Func <TDetails, PriceProcessFunction, ValueTask <TDetails> > priceProcessFunc, Action <MarkupApplicationResult <TDetails> > logAction = null) { var policies = _markupPolicyService.Get(subject, destinationInfo, MarkupPolicyTarget.AccommodationAvailability); var currentData = details; foreach (var policy in policies) { var detailsBefore = currentData; var markupFunction = GetPriceProcessFunction(policy); currentData = await priceProcessFunc(currentData, markupFunction); var discountFunction = await _discountFunctionService.Get(policy, subject); currentData = await priceProcessFunc(currentData, discountFunction);; logAction?.Invoke(new MarkupApplicationResult <TDetails>(detailsBefore, policy, currentData)); } return(currentData); }