public void GetCurrentPartnerIdReturnPartnerId() { SharePointServiceLocator.ReplaceCurrentServiceLocator(new ActivatingServiceLocator() .RegisterTypeMapping <IHierarchicalConfig, MockConfigManager>() .RegisterTypeMapping <ILogger, MockLogger>()); SPFarm fakeFarm = Isolate.Fake.Instance <SPFarm>(); Isolate.WhenCalled(() => SPFarm.Local).WillReturn(fakeFarm); Isolate.WhenCalled(() => ServerContext.GetContext(new SPSite(null))).WillReturn(null); Isolate.WhenCalled(() => SPContext.Current.Site).WillReturn(null); UserProfileManager fakeUserProfileManager = Isolate.Fake.Instance <UserProfileManager>(); Isolate.Swap.NextInstance <UserProfileManager>().With(fakeUserProfileManager); UserProfile fakeUserProfile = Isolate.Fake.Instance <UserProfile>(); Isolate.WhenCalled(() => fakeUserProfileManager.GetUserProfile(string.Empty)).WillReturn(fakeUserProfile); Isolate.WhenCalled(() => SPContext.Current.Web.CurrentUser.LoginName).WillReturn("User1"); Isolate.WhenCalled(() => fakeUserProfileManager.UserExists("User1")).WithExactArguments().WillReturn(true); Isolate.WhenCalled(() => fakeUserProfile["PartnerId"].Value).WillReturn("TestPartnerId"); PartnerSiteDirectory target = new PartnerSiteDirectory(); string actualPartnerId = target.GetCurrentPartnerId(); Assert.AreEqual("TestPartnerId", actualPartnerId); }
public void GetCurrentPartnerIdShouldOnlyRunInSharePointContext() { SharePointServiceLocator.ReplaceCurrentServiceLocator(new ActivatingServiceLocator() .RegisterTypeMapping <IHierarchicalConfig, MockConfigManager>()); PartnerSiteDirectory target = new PartnerSiteDirectory(); target.GetCurrentPartnerId(); }
public void GetCurrentPartnerIdThrowsPartnerNotFoundException() { SharePointServiceLocator.ReplaceCurrentServiceLocator(new ActivatingServiceLocator() .RegisterTypeMapping <IHierarchicalConfig, MockConfigManager>() .RegisterTypeMapping <ILogger, MockLogger>()); SPFarm fakeFarm = Isolate.Fake.Instance <SPFarm>(); Isolate.WhenCalled(() => SPFarm.Local).WillReturn(fakeFarm); Isolate.WhenCalled(() => SPContext.Current.Web.CurrentUser.LoginName).WillReturn("testuser"); UserProfileManager fakeUserProfileManager = Isolate.Fake.Instance <UserProfileManager>(); Isolate.Swap.NextInstance <UserProfileManager>().With(fakeUserProfileManager); Isolate.WhenCalled(() => fakeUserProfileManager.GetUserProfile(new Guid())).WillThrow(new Exception()); PartnerSiteDirectory target = new PartnerSiteDirectory(); target.GetCurrentPartnerId(); }