示例#1
0
        public void CreateKeyFragment_GenerateKeyFragmentFromAllVisitorGroup_ReturnStringWithAllVisitorGroupValue(IContent content, ICacheableSettings cacheableSettings, IViewDataContainer viewDataContainer, [Frozen] IVisitorGroupService visitorGroupService, [Frozen] IVisitorGroupRepository visitorGroupRepository, [Frozen] IEnumerable <VisitorGroup> visitorGroups, VisitorGroupKeyFragmentFactory visitorGroupKeyFragmentFactory)
        {
            var htmlHelper = new HtmlHelper(A.Fake <ViewContext>(), viewDataContainer);

            A.CallTo(() => visitorGroupRepository.List()).Returns(visitorGroups);
            A.CallTo(visitorGroupService)
            .Where(call => call.Method.Name == "IsUserInVisitorGroup" && visitorGroups.Any(vg => vg.Name == (call.Arguments.ElementAtOrDefault(1) as string)))
            .WithReturnType <bool>()
            .Returns(true);

            A.CallTo(() => cacheableSettings.VaryBy).Returns(new[] { VaryBy.VisitorGroups });
            A.CallTo(() => cacheableSettings.Parameters).Returns(new Dictionary <string, string> {
                { VaryBy.VisitorGroups, "*" }
            });

            string expectedResult = string.Join(",", visitorGroups.Select(vg => vg.Name));

            visitorGroupKeyFragmentFactory.CreateKeyFragment(htmlHelper, content, cacheableSettings).Should().Be(expectedResult, "Because the returned value should be the all the visitor groups role names");
        }
示例#2
0
 public VisitorGroupKeyFragmentFactory(IVisitorGroupRepository visitorGroupRepository, IVisitorGroupService visitorGroupService)
 {
     VisitorGroupRepository = visitorGroupRepository ?? throw new ArgumentNullException(nameof(visitorGroupRepository));
     VisitorGroupService    = visitorGroupService ?? throw new ArgumentNullException(nameof(visitorGroupService));
 }