public Reader CreateFBReader(string accessToken) { if (string.IsNullOrEmpty(accessToken)) { throw new ArgumentNullException("accessToke"); } var client = new FacebookClient(accessToken); dynamic me = client.Get("me"); string userName = me.username; var reader = this.Uow.Readers.GetAll().FirstOrDefault(r => r.UserName.ToLower() == userName.ToLower()); // Check if reader already exists if (reader == null) { reader = new Reader() { UserName = userName, Email = me.email, FirstName = me.first_name, LastName = me.last_name, Gender = me.gender, Link = me.link, CreatedOn = DateTime.Now }; this.Uow.Readers.Add(reader); this.Uow.Commit(); } return reader; }
public ReaderDto(Reader reader) { Id = reader.Id; UserName = reader.UserName; FullName = reader.FullName; Gender = reader.Gender; Link = reader.Link; CreatedOn = reader.CreatedOn; }
public void Setup() { user = new Mock<IPrincipal>(); identity = new Mock<IIdentity>(); user.Setup(x => x.Identity).Returns(identity.Object); identity.Setup(x => x.Name).Returns("Tom"); Thread.CurrentPrincipal = user.Object; uowMock = new Mock<IReadgressUow>(); readerTest = new Reader { Id = 1, FirstName = "Tom", LastName = "Jerry", Email = "*****@*****.**", Gender = "Male", UserName = "******", Link = "www.jerry.com", CreatedOn = DateTime.Now }; }
public void Setup() { user = new Mock<IPrincipal>(); identity = new Mock<IIdentity>(); user.Setup(x => x.Identity).Returns(identity.Object); identity.Setup(x => x.Name).Returns("Tom"); Thread.CurrentPrincipal = user.Object; uowMock = new Mock<IReadgressUow>(); bookmarkRepositoryMock = new Mock<IBookmarkRepository>(); HttpConfiguration config = new HttpConfiguration(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/bookmark"); IHttpRoute route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}"); HttpRouteData routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "bookmark" } }); sut = new BookmarkController(uowMock.Object); sut.ControllerContext = new HttpControllerContext(config, routeData, request); sut.Request = request; sut.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; sut.Request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, routeData); readerTest = new Reader { Id = 1, FirstName = "Tom", LastName = "Jerry", Email = "*****@*****.**", Gender = "Male", UserName = "******", Link = "www.jerry.com", CreatedOn = DateTime.Now }; progressTest = new Progress() { Id = 1, Isbn = "OL12345", ReaderId = 1, Reader = readerTest, IsFinished = false }; bookmarksTest = new List<Bookmark>() { new Bookmark() { Id=1, ProgressId=1, Progress=progressTest, PageNumber=20, CreatedOn=DateTime.Now }, new Bookmark() { Id=2, ProgressId=1, Progress=progressTest, PageNumber=30, CreatedOn=DateTime.Now } }; }