public void ReturnStatusDto_WhenInvokedWithCorrectParameters() { //Arrange var mapperMock = new Mock <IMappingProvider>(); var statusesRepoMock = new Mock <IRepository <Status> >(); var statusService = new StatusesService(mapperMock.Object, statusesRepoMock.Object); var data = new List <Status>() { new Status { Id = 1, Name = "Draft" }, new Status { Id = 2, Name = "Publish" } }; var dataMapper = new StatusDto() { Id = 1, Name = "Draft" }; statusesRepoMock.Setup(x => x.All).Returns(data.AsQueryable()); mapperMock.Setup(m => m.MapTo <StatusDto>(It.IsAny <Status>())).Returns(dataMapper); //Act var statusDto = statusService.GetStatusByName("Draft"); //&Assert Assert.IsNotNull(statusDto); Assert.IsInstanceOfType(statusDto, typeof(StatusDto)); }
public void InnokeMapperMapToMethod() { //Arrange var mapperMock = new Mock <IMappingProvider>(); var statusesRepoMock = new Mock <IRepository <Status> >(); var statusService = new StatusesService(mapperMock.Object, statusesRepoMock.Object); var data = new List <Status>() { new Status { Id = 1, Name = "Draft" }, new Status { Id = 2, Name = "Publish" } }; var dataMapper = new StatusDto() { Id = 1, Name = "Draft" }; statusesRepoMock.Setup(x => x.All).Returns(data.AsQueryable()); mapperMock.Setup(m => m.MapTo <StatusDto>(It.IsAny <Status>())).Returns(dataMapper); //Act var statusDto = statusService.GetStatusByName("Draft"); //&Assert mapperMock.Verify(x => x.MapTo <StatusDto>(It.IsAny <Status>()), Times.Once); }
public void ThrowArgumentException_WhenStatusNameParameterIsEmptyString() { //Arrange var mapperMock = new Mock <IMappingProvider>(); var statusesRepoMock = new Mock <IRepository <Status> >(); var statusService = new StatusesService(mapperMock.Object, statusesRepoMock.Object); Assert.ThrowsException <ArgumentException>(() => statusService.GetStatusByName(string.Empty)); }
public void CreateInstance_WhenInvokedWithValidParameters() { //Arrange var mapperMock = new Mock <IMappingProvider>(); var statusesRepoMock = new Mock <IRepository <Status> >(); //Act var statusService = new StatusesService(mapperMock.Object, statusesRepoMock.Object); //Assert Assert.IsNotNull(statusService); Assert.IsInstanceOfType(statusService, typeof(IStatusesService)); }
public void ThrowArgumentNullException_WhenStatusEntityIsNull() { //Arrange var mapperMock = new Mock <IMappingProvider>(); var statusesRepoMock = new Mock <IRepository <Status> >(); var statusService = new StatusesService(mapperMock.Object, statusesRepoMock.Object); var data = new List <Status>() { new Status { Id = 1, Name = "Draft" }, new Status { Id = 2, Name = "Publish" } }; statusesRepoMock.Setup(x => x.All).Returns(data.AsQueryable()); //Act&Assert Assert.ThrowsException <ArgumentNullException>(() => statusService.GetStatusByName("sucks")); }
public ActionResult Index(long?replyTo) { if (Token == null) { ViewData["Url"] = new AuthenticationService().GetAuthenticationUrl(); return(View("Unauthenticated")); } var service = new StatusesService(Token); ViewData["Action"] = "Index"; ViewData["PageTitle"] = "home"; if (replyTo != null) { try { ViewData["InReplyTo"] = service.GetSingleStatus(replyTo.Value); } catch (TweetSharpException ex) { //todo - I can't find a good way to detect invalid tweet IDs other than catching the error when thrown. //So, we try/catch, signal the error and redirect home without the replyTo. ErrorSignal.FromCurrentContext().Raise(ex, System.Web.HttpContext.Current); return(RedirectToAction("Index")); } } //if this call fails it will fail in the view and be handled by our standard error handing mechanism ViewData["loadInitialData"] = ExecuteOrRedirect(() => new JavaScriptSerializer().Serialize(service.OnHomeTimeline(null, null))); ViewData["loadMoreUrl"] = "/statuses/onHomeTimeline/"; return(View()); }
public JsonResult Favorites(int?page) { var service = new StatusesService(Token); return(StandardJsonResult(service, s => s.Favorites(page))); }
public JsonResult Mentions(long?newerThan, long?olderThan) { var service = new StatusesService(Token); return(StandardJsonResult(service, s => s.Mentions(newerThan, olderThan))); }
public JsonResult OnHometimeline(long?newerThan, long?olderThan) { var service = new StatusesService(Token); return(StandardJsonResult(service, s => s.OnHomeTimeline(newerThan, olderThan))); }
public IEnumerable <ProjectStatus> GetProjectStatuses() { var projectStatuses = new StatusesService(_dbContext).GetProjectStatuses(); return(projectStatuses); }