public AuthenticationResponse LogOn(string token) { AuthenticationResponse response = null; // ONLY TO USE IN DEMOS WITHOUT INTERNET! if (Convert.ToBoolean(WebConfigurationManager.AppSettings["OfflineMode"])) return GetFakeAuthorization(); if (String.IsNullOrEmpty(token)) throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); RegisteredUser registeredUser = _facebookService.GetUserInformation(token); if (registeredUser != null && !String.IsNullOrEmpty(registeredUser.FacebookId)) { int registeredUserId = _registeredUserRepository.Add(registeredUser); if (registeredUserId > 0) { response = new AuthenticationResponse(); response.RegisteredUserId = registeredUserId; response.UserName = registeredUser.Name; response.Token = MyEventsToken.CreateToken(registeredUserId); response.ExpirationTime = TimeSpan.FromHours(1).TotalMilliseconds; response.FacebookUserId = registeredUser.FacebookId; } } return response; }
public void LogOn_Logged_Test() { string token = "mytoken"; IRegisteredUserRepository eventDefinitionService = new StubIRegisteredUserRepository() { AddRegisteredUser = (user) => { Assert.AreEqual(user.FacebookId, "facebookId"); return(10); } }; IFacebookService facebookService = new StubIFacebookService() { GetUserInformationString = (facebookToken) => { return(new Model.RegisteredUser() { FacebookId = "facebookId" }); } }; var target = new AuthenticationController(eventDefinitionService, facebookService); MyEvents.Api.Authentication.AuthenticationResponse response = target.LogOn(token); Assert.IsNotNull(response); Assert.IsNotNull(response.Token); }
public void LogOn_TokenNotValid_Test() { string token = "mytoken"; IRegisteredUserRepository eventDefinitionService = new StubIRegisteredUserRepository() { GetString = (facebookId) => { Assert.Fail(); return(null); } }; IFacebookService facebookService = new StubIFacebookService() { GetUserInformationString = (facebookToken) => { return(null); } }; var target = new AuthenticationController(eventDefinitionService, facebookService); MyEvents.Api.Authentication.AuthenticationResponse response = target.LogOn(token); Assert.IsNull(response); }
/// <summary> /// Get Fake Authorization to used it when the clients are in no internet mode. /// ONLY TO USE IN DEMOS WITHOUT INTERNET! /// </summary> /// <returns>AuthenticationResponse</returns> public AuthenticationResponse GetFakeAuthorization() { var response = new AuthenticationResponse(); response.RegisteredUserId = Int32.Parse(WebConfigurationManager.AppSettings["fakeUserId"]); response.UserName = WebConfigurationManager.AppSettings["fakeUserName"]; response.Token = MyEventsToken.CreateToken(response.RegisteredUserId); response.ExpirationTime = TimeSpan.FromHours(1).TotalMilliseconds; return response; }
public void GetFakeAuthorization_Coverage_NotFail_Test() { IRegisteredUserRepository eventDefinitionService = new StubIRegisteredUserRepository(); IFacebookService facebookService = new StubIFacebookService(); var target = new AuthenticationController(eventDefinitionService, facebookService); MyEvents.Api.Authentication.AuthenticationResponse response = target.GetFakeAuthorization(); Assert.IsNotNull(response); Assert.IsNotNull(response.Token); }