public BursifyUserController(MembershipApi membershipApi, UserApi userApi, StudentApi studentApi, SponsorApi sponsorApi)
 {
     _membershipApi = membershipApi;
     _userApi       = userApi;
     _studentApi    = studentApi;
     _sponsorApi    = sponsorApi;
 }
 public AccountController(MembershipApi membershipApi, StudentApi studentApi)
 {
     _membershipApi = membershipApi;
     _studentApi    = studentApi;
 }
        public void SaveUserWithOutExtensionProperties()
        {
            MockRepository mockRepository = new MockRepository();
            IOrganizationApi organizationApi = mockRepository.StrictMock<IOrganizationApi>();
            SetupResult.For(organizationApi.GetOrganization(Guid.Empty)).IgnoreArguments().Return(new OrganizationObject());
            mockRepository.ReplayAll();

            UserObject userObject = new UserObject
            {
                Comment = "IT specialist",
                DisplayName = "Eunge Liu",
                Email = "*****@*****.**",
                IsApproved = true,
                MobilePin = "137641855XX",
                UserName = "******"
            };

            IMembershipApi membershipApi = new MembershipApi(SpringContext.Current.GetObject<IAuthenticationContext>(), organizationApi);
            membershipApi.Save(userObject, "password1", null);
            createdObjectIds.Add(userObject.UserId);

            userObject = membershipApi.Get(userObject.UserId);
            userObject.DisplayName = "Eunge";
            membershipApi.Save(userObject, null, null);

            userObject = membershipApi.Get(userObject.UserId);
            Assert.AreEqual("Eunge", userObject.DisplayName);
        }
        public void CacheCallingWhenUpdateUserTest()
        {
            IAuthenticationContext authenticationContext = SpringContext.Current.GetObject<IAuthenticationContext>();
            MockRepository mockRepository = new MockRepository();
            IOrganizationApi organizationApi = mockRepository.StrictMock<IOrganizationApi>();
            SetupResult.For(organizationApi.GetOrganization(Guid.Empty)).IgnoreArguments().Return(new OrganizationObject());
            mockRepository.ReplayAll();

            MembershipApi membershipApi = new MembershipApi(authenticationContext, organizationApi);
            Guid userId = this.CreateUser(membershipApi);
            UserObject userObject = membershipApi.Get(userId);

            organizationApi = mockRepository.StrictMock<IOrganizationApi>();
            ICache cacheInstance = mockRepository.StrictMock<ICache>();
            membershipApi = new MembershipApi(authenticationContext, organizationApi);
            membershipApi.Cache = cacheInstance;

            using (mockRepository.Record())
            using (mockRepository.Ordered())
            {
                organizationApi.Expect(api => api.GetOrganization(Guid.Empty)).IgnoreArguments().Return(new OrganizationObject());

                // remove the cache for original user id
                cacheInstance.Expect(cache => cache.Remove(null)).IgnoreArguments();
            }

            using (mockRepository.Playback())
            {
                userObject.UserName = "******";
                membershipApi.Save(userObject, "password1", null);
            }
        }
        public void CacheCallingWhenGetUserByNameTest()
        {
            IAuthenticationContext authenticationContext = SpringContext.Current.GetObject<IAuthenticationContext>();

            MockRepository mockRepository = new MockRepository();
            ICache cacheInstance = mockRepository.StrictMock<ICache>();
            IOrganizationApi organizationApi = mockRepository.DynamicMock<IOrganizationApi>();
            SetupResult.For(organizationApi.GetOrganization(Guid.Empty)).IgnoreArguments().Return(new OrganizationObject());
            mockRepository.ReplayAll();

            MembershipApi membershipApi = new MembershipApi(authenticationContext, organizationApi);
            Guid userId = this.CreateUser(membershipApi);
            UserObject userObject = membershipApi.Get(userId);
            string userName = userObject.UserName;

            membershipApi.Cache = cacheInstance;
            using (mockRepository.Record())
            using (mockRepository.Ordered())
            {
                // Nothing on cache.
            }

            using (mockRepository.Playback())
            {
                membershipApi.Get(userName);
            }
        }
        public void CacheCallingWhenGetUserByIdTest()
        {
            IAuthenticationContext authenticationContext = SpringContext.Current.GetObject<IAuthenticationContext>();

            MockRepository mockRepository = new MockRepository();
            ICache cacheInstance = mockRepository.StrictMock<ICache>();
            IOrganizationApi organizationApi = mockRepository.DynamicMock<IOrganizationApi>();
            SetupResult.For(organizationApi.GetOrganization(Guid.Empty)).IgnoreArguments().Return(new OrganizationObject());
            mockRepository.ReplayAll();

            MembershipApi membershipApi = new MembershipApi(authenticationContext, organizationApi);
            Guid userId = this.CreateUser(membershipApi);

            membershipApi.Cache = cacheInstance;

            using (mockRepository.Record())
            using (mockRepository.Ordered())
            {
                Action<MethodInvocation> methodInvocationCallback = methodInvocation =>
                {
                    Assert.AreEqual(1, methodInvocation.Arguments.Length);
                    Assert.AreEqual(typeof(string), methodInvocation.Arguments[0].GetType());
                };

                // get UserObject by UserId, returns null from the cache
                cacheInstance.Expect(cache => cache.Get(null)).IgnoreArguments().WhenCalled(methodInvocationCallback).Return(null);

                methodInvocationCallback = methodInvocation =>
                {
                    Assert.AreEqual(4, methodInvocation.Arguments.Length);
                    Assert.AreEqual(typeof(string), methodInvocation.Arguments[0].GetType());
                    Assert.AreEqual(typeof(UserObject), methodInvocation.Arguments[1].GetType());
                };

                // Add pair of (UserId, UserObject) to cache
                cacheInstance.Expect(cache => cache.Add(null, null, TimeSpan.Zero, CachePriorityTypes.Normal)).IgnoreArguments().WhenCalled(methodInvocationCallback);
            }

            using (mockRepository.Playback())
            {
                membershipApi.Get(userId);
            }
        }
        public void CacheCallingWhenAddUserTest()
        {
            IAuthenticationContext authenticationContext = SpringContext.Current.GetObject<IAuthenticationContext>();

            MockRepository mockRepository = new MockRepository();
            IOrganizationApi organizationApi = mockRepository.StrictMock<IOrganizationApi>();
            ICache cacheInstance = mockRepository.StrictMock<ICache>();
            MembershipApi membershipApi = new MembershipApi(authenticationContext, organizationApi) { Cache = cacheInstance };

            using (mockRepository.Record())
            using (mockRepository.Ordered())
            {
                organizationApi.Expect(api => api.GetOrganization(Guid.Empty)).IgnoreArguments().Return(new OrganizationObject());

                // remove the cache.
                cacheInstance.Remove(null);
                LastCall.IgnoreArguments();
            }

            using (mockRepository.Playback())
            {
                this.CreateUser(membershipApi);
            }
        }