Пример #1
0
        //TODO add MEMBER

        //TODO add current user (Mock WebSecurity and autofixt/mock IUser) - Use Case : WebApi.Security.CurrentUser.*

        public IUser WithCurrentUser(int?id = null, string name = null, string username = null, string email = null, string comments = null, DateTime?createDate = null, DateTime?updateDate = null, string language = null, bool isApproved = true, bool isLocked = false, int?startContentId = null, int?startMediaId = null)
        {
            var usr = UmbracoUnitTestHelper.GetUser(_mocks.Resolve <IUser>("Current"),
                                                    id ?? _Fixture.Create <int>(),
                                                    name ?? _Fixture.Create <string>(),
                                                    username ?? _Fixture.Create <string>(),
                                                    email ?? _Fixture.Create <string>(),
                                                    comments ?? _Fixture.Create <string>(),
                                                    createDate ?? _Fixture.Create <DateTime>(),
                                                    updateDate ?? _Fixture.Create <DateTime>(),
                                                    language ?? _Fixture.Create <string>(),
                                                    isApproved,
                                                    isLocked,
                                                    startContentId ?? _Fixture.Create <int>(),
                                                    startMediaId ?? _Fixture.Create <int>());

            var userData = _mocks.Resolve <UserData>();

            userData.SetupAllProperties();
            userData.Object.Id               = usr.Id;
            userData.Object.RealName         = usr.Name;
            userData.Object.Username         = usr.Username;
            userData.Object.Culture          = usr.Language;
            userData.Object.StartContentNode = usr.StartContentId;
            userData.Object.StartMediaNode   = usr.StartMediaId;

            var mockIdentity = _mocks.Resolve <UmbracoBackOfficeIdentity>(null, userData.Object);

            mockIdentity.SetupAllProperties();
            mockIdentity.Setup(s => s.IsAuthenticated).Returns(true);

            var mockPricipal = _mocks.Resolve <IPrincipal>();

            mockPricipal.Setup(s => s.Identity).Returns(mockIdentity.Object);

            var httpContextMock = _mocks.Resolve <HttpContextBase>();

            httpContextMock.Setup(s => s.User).Returns(mockPricipal.Object);

            var webSec = _mocks.Resolve <WebSecurity>(null, _mocks.ResolveObject <HttpContextBase>(), null);

            webSec.Setup(s => s.CurrentUser).Returns(usr);
            webSec.Setup(s => s.GetUserId()).Returns(usr.Id);

            return(usr);
        }