Exemplo n.º 1
0
        public void ProfilePageUpdate()
        {
            var page = new ProfilePage()
            {
                ApplicationIdentifier = Guid.NewGuid(),
                Handle          = Guid.NewGuid().ToString(),
                OwnerIdentifier = Guid.NewGuid(),
            };

            var core = new UserCore();

            core.Save(page);
            var newPage = new ProfilePage()
            {
                ExistingHandle        = page.Handle,
                Handle                = Guid.NewGuid().ToString(),
                ApplicationIdentifier = page.ApplicationIdentifier,
                OwnerIdentifier       = page.OwnerIdentifier,
            };

            core.Save(newPage);
            var get = core.Get(page);

            Assert.IsNull(get);
            get = core.Get(newPage);
            Assert.AreEqual <string>(newPage.Handle, get.Handle);
            Assert.AreEqual <Guid>(newPage.ApplicationIdentifier, get.ApplicationIdentifier);
            Assert.AreEqual <Guid>(newPage.OwnerIdentifier, get.OwnerIdentifier);
        }
Exemplo n.º 2
0
        public void ProfilePageEditAnothers()
        {
            var page = new ProfilePage()
            {
                ApplicationIdentifier = Guid.NewGuid(),
                Handle          = Guid.NewGuid().ToString(),
                OwnerIdentifier = Guid.NewGuid(),
            };

            var core = new UserCore();

            core.Save(page);
            page.OwnerIdentifier = Guid.NewGuid();
            core.Save(page);
        }
Exemplo n.º 3
0
        public ActionResult Save(UserPreference preference)
        {
            using (new PerformanceMonitor())
            {
                try
                {
                    if (null == preference)
                    {
                        return(this.Json(WebResponse.Bind((int)Fault.DataNotSpecified, "Preference not specified"), JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        var user = User.Identity.Data();
                        preference.User = new User()
                        {
                            Identifier = user.Identifier,
                        };
                        preference.Application = Application.Current;
                        preference.MaximumAllowedApplications = null;

                        var saved = userCore.Save(preference);

                        return(this.Json(saved, JsonRequestBehavior.AllowGet));
                    }
                }
                catch (Exception ex)
                {
                    logger.Log(ex, EventTypes.Error, (int)Fault.Unknown);
                    return(this.Json(WebResponse.Bind((int)Fault.Unknown, ex.Message), JsonRequestBehavior.AllowGet));
                }
            }
        }
        public ActionResult Edit(FormCollection collection)
        {
            var twitterHandle = collection["TwitterHandle"];

            if (string.IsNullOrWhiteSpace(twitterHandle))
            {
                return(base.RedirectToAction("Index", "Home"));
            }
            else
            {
                var source     = new DomainSource();
                var user       = source.GetUserByEmail(Application.Default.Identifier, base.User.Identity.Name);
                var preference = new UserPreference()
                {
                    TwitterHandle = twitterHandle,
                    User          = user.Convert(),
                    Application   = Application.Default,
                };

                var core = new UserCore();
                core.Save(preference);

                return(this.Edit());
            }
        }
Exemplo n.º 5
0
        public void UserPreferenceRoundTrip()
        {
            var core  = new UserCore();
            var pref  = this.Preference();
            var saved = core.Save(pref);

            Assert.AreEqual <Guid>(pref.User.Identifier, saved.User.Identifier);
            Assert.AreEqual <Guid>(pref.Application.Identifier, saved.Application.Identifier);
            Assert.AreEqual <Guid>(pref.CurrentApplication.Identifier, saved.CurrentApplication.Identifier);
            Assert.AreEqual <string>(pref.TimeZone.Id, saved.TimeZone.Id);
            Assert.AreEqual <string>(pref.TwitterHandle, saved.TwitterHandle);
            Assert.AreEqual <string>(pref.AbcHandle, saved.AbcHandle);
            Assert.AreEqual <string>(pref.GitHubHandle, saved.GitHubHandle);
            Assert.AreEqual <string>(pref.City, saved.City);
            Assert.AreEqual <string>(pref.Country, saved.Country);

            var got = core.Get(pref);

            Assert.AreEqual <Guid>(pref.User.Identifier, got.User.Identifier);
            Assert.AreEqual <Guid>(pref.Application.Identifier, got.Application.Identifier);
            Assert.AreEqual <Guid>(pref.CurrentApplication.Identifier, got.CurrentApplication.Identifier);
            Assert.AreEqual <string>(pref.TimeZone.Id, got.TimeZone.Id);
            Assert.AreEqual <string>(pref.TwitterHandle, got.TwitterHandle);
            Assert.AreEqual <string>(pref.AbcHandle, got.AbcHandle);
            Assert.AreEqual <string>(pref.GitHubHandle, got.GitHubHandle);
            Assert.AreEqual <string>(pref.City, got.City);
            Assert.AreEqual <string>(pref.Country, got.Country);
        }
Exemplo n.º 6
0
        public void GetPublicProfiles()
        {
            var appId = Guid.NewGuid();
            var core  = new UserCore();

            for (int i = 0; i < 5; i++)
            {
                var page = new ProfilePage()
                {
                    ApplicationIdentifier = appId,
                    Handle          = Guid.NewGuid().ToString(),
                    OwnerIdentifier = Guid.NewGuid(),
                };

                core.Save(page);
            }
            var app = new Application()
            {
                Identifier = appId,
            };

            var profiles = core.PublicProfiles(app);

            Assert.AreEqual <int>(5, profiles.Count());
        }
        private void SetPreference(Guid appId, Guid userId)
        {
            using (new PerformanceMonitor())
            {
                var app = new Application()
                {
                    Identifier = ServerConfiguration.ApplicationIdentifier,
                };
                var currentApp = new Application()
                {
                    Identifier = appId,
                };
                var user = new User()
                {
                    Identifier = userId,
                };
                var pref = new UserPreference()
                {
                    Application        = app,
                    CurrentApplication = currentApp,
                    User = user,
                    MaximumAllowedApplications = null,
                };

                var core = new UserCore();
                core.Save(pref);
            }
        }
Exemplo n.º 8
0
        public void SaveUserPreferenceEmptyUserId()
        {
            var core = new UserCore();
            var pref = this.Preference();

            pref.User.Identifier = Guid.Empty;
            core.Save(pref);
        }
Exemplo n.º 9
0
        public void SaveUserPreferenceNullUser()
        {
            var core = new UserCore();
            var pref = this.Preference();

            pref.User = null;
            core.Save(pref);
        }
Exemplo n.º 10
0
        public void SaveUserPreferenceNullApplication()
        {
            var core = new UserCore();
            var pref = this.Preference();

            pref.Application = null;
            core.Save(pref);
        }
Exemplo n.º 11
0
        public void SaveContactNullOwner()
        {
            var core = new UserCore();
            var data = this.Contact();

            data.Owner = null;
            core.Save(data);
        }
Exemplo n.º 12
0
        public void SaveContactEmptyOwnerIdentifier()
        {
            var core = new UserCore();
            var data = this.Contact();

            data.Owner.Identifier = Guid.Empty;
            core.Save(data);
        }
Exemplo n.º 13
0
        public void SaveContactGroupEmptyIdentifier()
        {
            var core = new UserCore();
            var data = this.Group();

            data.Identifier = Guid.Empty;
            core.Save(data);
        }
Exemplo n.º 14
0
        public void SaveProfilePageHandleInvalid()
        {
            var profile = new ProfilePage()
            {
                ApplicationIdentifier = Guid.NewGuid(),
                Handle          = StringHelper.NullEmptyWhiteSpace(),
                OwnerIdentifier = Guid.NewGuid(),
            };

            var core = new UserCore();

            core.Save(profile);
        }
Exemplo n.º 15
0
        public void SaveProfilePageOwnerIdentifierEmpty()
        {
            var profile = new ProfilePage()
            {
                ApplicationIdentifier = Guid.NewGuid(),
                Handle          = StringHelper.ValidString(),
                OwnerIdentifier = Guid.Empty,
            };

            var core = new UserCore();

            core.Save(profile);
        }
Exemplo n.º 16
0
        public void SaveProfilePage()
        {
            var page = new ProfilePage()
            {
                ApplicationIdentifier = Guid.NewGuid(),
                Handle          = Guid.NewGuid().ToString(),
                OwnerIdentifier = Guid.NewGuid(),
            };

            var core     = new UserCore();
            var returned = core.Save(page);

            Assert.AreEqual <string>(page.Handle, returned.Handle);
            Assert.AreEqual <Guid>(page.ApplicationIdentifier, returned.ApplicationIdentifier);
            Assert.AreEqual <Guid>(page.OwnerIdentifier, returned.OwnerIdentifier);
        }
Exemplo n.º 17
0
        public void GetContactGroups()
        {
            var user   = this.UserData();
            var random = new Random();
            var count  = random.Next(50);
            var core   = new UserCore();

            for (int i = 0; i < count; i++)
            {
                var c = this.Group();
                c.Owner = user;
                core.Save(c);
            }

            var groups = core.GetGroups(user);

            Assert.AreEqual <int>(count, groups.Count());
        }
Exemplo n.º 18
0
        public void RoundTripProfilePage()
        {
            var page = new ProfilePage()
            {
                ApplicationIdentifier = Guid.NewGuid(),
                Handle          = Guid.NewGuid().ToString(),
                OwnerIdentifier = Guid.NewGuid(),
            };

            var core = new UserCore();

            core.Save(page);
            var get = core.Get(page);

            Assert.IsNotNull(get);
            Assert.AreEqual <string>(page.Handle, get.Handle);
            Assert.AreEqual <Guid>(page.ApplicationIdentifier, get.ApplicationIdentifier);
            Assert.AreEqual <Guid>(page.OwnerIdentifier, get.OwnerIdentifier);
        }
Exemplo n.º 19
0
        public void GetContacts()
        {
            var user   = this.UserData();
            var random = new Random();
            var count  = random.Next(50);
            var core   = new UserCore();

            Parallel.For(
                0,
                count,
                (a, b) =>
            {
                var c   = this.Contact();
                c.Owner = user;
                core.Save(c);
            });
            var contacts = core.GetContacts(user);

            Assert.AreEqual <int>(count, contacts.Count());
        }
Exemplo n.º 20
0
        public ActionResult AddUserToTribe(string tribe)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(tribe))
                {
                    return(this.Json(WebResponse.Bind((int)Fault.Unknown, "Tribe must be specified."), JsonRequestBehavior.AllowGet));
                }

                var source = new DomainSource();
                var user   = source.GetUserByEmail(Application.Default.Identifier, base.User.Identity.Name);
                var core   = new UserCore();
                core.Save(user.Convert(), tribe);
            }
            catch (Exception ex)
            {
                logger.Log(ex, EventTypes.Warning, 999);
                return(this.Json(WebResponse.Bind((int)Fault.Unknown, ex.Message), JsonRequestBehavior.AllowGet));
            }
            return(View());
        }
Exemplo n.º 21
0
        public ActionResult Profile(FormCollection collection)
        {
            using (new Service.PerformanceMonitor())
            {
                try
                {
                    var preference = new UserPreference()
                    {
                        Application = Application.Current,
                        User        = User.Identity.Data(),
                    };

                    var timeZoneId = collection["TimeZone.Id"];
                    preference               = userCore.Get(preference);
                    preference.TimeZone      = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
                    preference.TwitterHandle = collection["TwitterHandle"];
                    preference.GitHubHandle  = collection["GitHubHandle"];
                    preference.AbcHandle     = collection["AbcHandle"];
                    preference.Country       = collection["Country"];
                    preference.City          = collection["City"];
                    userCore.Save(preference);

                    var source = new DomainSource();

                    var user = source.GetUserByNameIdentifier(Application.Current.Identifier, User.Identity.NameIdentifier());
                    user.Email          = collection["Email"];
                    user.UserName       = collection["UserName"];
                    user.LastActivityOn = DateTime.UtcNow;

                    source.Update(user);
                }
                catch (Exception ex)
                {
                    log.Log(ex, EventTypes.Warning, (int)Fault.Unknown);
                }

                return(this.Profile());
            }
        }
Exemplo n.º 22
0
        public void SaveUserPreferenceNull()
        {
            var core = new UserCore();

            core.Save((UserPreference)null);
        }
Exemplo n.º 23
0
        /// <summary>
        /// GitHub Auth API
        /// </summary>
        /// <remarks>
        /// GET: /Auth/GitHub
        /// </remarks>
        /// <returns></returns>
        public ActionResult GitHub()
        {
            var code = Request.Params["code"];

            if (!string.IsNullOrWhiteSpace(code))
            {
                try
                {
                    string responseData = null;
                    using (var client = new WebClient())
                    {
                        var nameValuePairs = new NameValueCollection();
                        nameValuePairs.Add("code", code);
                        nameValuePairs.Add("client_secret", ServerConfiguration.GitHubSecret);
                        nameValuePairs.Add("client_id", ServerConfiguration.GitHubClientId);
                        client.Headers.Add("content-type", "application/x-www-form-urlencoded");
                        var response = client.UploadValues(GitHubAuthorizationPost, nameValuePairs);
                        responseData = client.Encoding.GetString(response);
                    }

                    if (!string.IsNullOrWhiteSpace(responseData))
                    {
                        var    gitHubResponse = GitHubResponse.Parse(responseData);
                        string profileJson    = null;
                        using (var client = new WebClient())
                        {
                            profileJson = client.DownloadString(string.Format(GitHubApi, "user", gitHubResponse.AccessToken));
                        }

                        if (!string.IsNullOrWhiteSpace(profileJson))
                        {
                            var serializer = new JavaScriptSerializer();

                            var profile = serializer.Deserialize <GitHubProfile>(profileJson);
                            if (this.Login(profile)) //New User
                            {
                                var source     = new DomainSource();
                                var user       = source.GetUserByNameIdentifier(Application.Default.Identifier, string.Format("github{0}", profile.Id));
                                var preference = profile.Convert();
                                preference.Application = Application.Default;
                                preference.User        = user.Convert();
                                var core = new UserCore();
                                core.Save(preference);
                                var profilePage = ((IConvert <ProfilePage>)profile).Convert();
                                profilePage.ApplicationIdentifier = Application.Default.Identifier;
                                profilePage.OwnerIdentifier       = user.Id;
                                profilePage.GitCode        = code;
                                profilePage.GitAccessToken = gitHubResponse.AccessToken;
                                core.Save(profilePage);
                                return(this.RedirectToAction("Welcome", "Home"));
                            }
                            else
                            {
                                return(this.RedirectToAction("Index", "Profile", new { username = profile.Login }));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Log(ex, Abc.Services.Contracts.EventTypes.Critical, (int)ServiceFault.Unknown);
                }
            }

            return(this.RedirectToAction("Index", "Auth"));
        }
Exemplo n.º 24
0
        public void SaveContactGroupNullContactGroup()
        {
            var core = new UserCore();

            core.Save((ContactGroup)null);
        }
Exemplo n.º 25
0
        public void SaveProfilePagePageNull()
        {
            var core = new UserCore();

            core.Save((ProfilePage)null);
        }
Exemplo n.º 26
0
        public void SaveContactNullContact()
        {
            var core = new UserCore();

            core.Save((Contact)null);
        }