chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi,
How I can test the code below:
        public static void ActivateWebFeature(SPWeb web, Guid featureId)
        {
            if (web.Features[featureId] == null) // check if the feature is enabled
            {
                web.Features.Add(featureId, true);
                web.Update();
            }
        }


The problem is that "web.Features[featureId]" part is always null.
I've tried with
            
            Guid featureId = Guid.NewGuid();
            var feature = Isolate.Fake.Instance<SPFeature>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => web.Features[featureId]).WillReturn(feature);


but no luck. Please advise.
asked by askinh (720 points)

2 Answers

0 votes
It worked with:

            
var feature = Isolate.Fake.Instance<SPFeature>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => web.Features).WillReturnCollectionValuesOf(new[] {feature});
answered by askinh (720 points)
0 votes
Hello,

Can you please post the whole test method?
answered by NofarC (4k points)
...