private static RegisteredUser Parse(string userInformationAsJson) { if (String.IsNullOrEmpty(userInformationAsJson)) return null; var jsSerializer = new JavaScriptSerializer(); var userInformation = jsSerializer.Deserialize<Dictionary<string, object>>(userInformationAsJson); RegisteredUser information = new RegisteredUser() { FacebookId = userInformation["id"].ToString(), Name = userInformation["name"].ToString(), Email = userInformation["email"].ToString(), Bio = userInformation.ContainsKey("bio") ? userInformation["bio"].ToString() : string.Empty, }; if (userInformation.ContainsKey("location")) { var location = userInformation["location"] as Dictionary<string, object>; if (null != location) { information.City = location["name"].ToString(); } } return information; }
public void AddRegisteredUser_Added_NotFail_Test() { IRegisteredUserRepository target = new RegisteredUserRepository(); RegisteredUser registeredUser = new RegisteredUser(); registeredUser.Name = Guid.NewGuid().ToString(); registeredUser.FacebookId = Guid.NewGuid().ToString(); registeredUser.Email = Guid.NewGuid().ToString(); Assert.IsTrue(target.Add(registeredUser) > 0); }
public void AddRegisteredUser_NotAdded_AlreadyExists_Test() { var context = new MyEventsContext(); var user = context.RegisteredUsers.FirstOrDefault(); IRegisteredUserRepository target = new RegisteredUserRepository(); RegisteredUser registeredUser = new RegisteredUser(); registeredUser.Name = Guid.NewGuid().ToString(); registeredUser.FacebookId = user.FacebookId; registeredUser.Email = Guid.NewGuid().ToString(); int actual = target.Add(registeredUser); Assert.AreEqual(user.RegisteredUserId, actual ); }
/// <summary> /// <see cref="MyEvents.Data.IRegisteredUserRepository"/> /// </summary> /// <param name="registeredUser"> <see cref="MyEvents.Data.IRegisteredUserRepository"/></param> public int Add(RegisteredUser registeredUser) { using (var context = new MyEventsContext()) { var user = Get(registeredUser.FacebookId); if (user == null) { context.RegisteredUsers.Add(registeredUser); context.SaveChanges(); return registeredUser.RegisteredUserId; } else { return user.RegisteredUserId; } } }
/// <summary> /// Add RegisteredUser /// </summary> /// <param name="registeredUser">registeredUser information</param> /// <returns>RegisteredUser id</returns> public int PostRegisteredUserCreateIfNotExists(RegisteredUser registeredUser) { if (registeredUser == null) throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); return _registeredUserRepository.Add(registeredUser); }
private int AddUser(MyEventsIdentity identity) { var user = new RegisteredUser() { Email = identity.Email, FacebookId = identity.ThirdPartyUserId, Name = identity.UserName, Bio = identity.Bio, City = identity.City }; int registeredUserId = _registeredUserRepository.Add(user); return registeredUserId; }
public void PostRegisteredUser_Call_NotFail_Test() { int expected = 1; bool called = false; RegisteredUser registeredUser = new RegisteredUser(); IRegisteredUserRepository registeredUserService = new StubIRegisteredUserRepository() { AddRegisteredUser = RegisteredUserParam => { called = true; return expected; } }; var target = new RegisteredUsersController(registeredUserService); int actual = target.PostRegisteredUserCreateIfNotExists(registeredUser); Assert.IsTrue(called); Assert.AreEqual(expected, actual); }