Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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"));
        }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
0
        public JsonResult Favorites(int?page)
        {
            var service = new StatusesService(Token);

            return(StandardJsonResult(service, s => s.Favorites(page)));
        }
Ejemplo n.º 8
0
        public JsonResult Mentions(long?newerThan, long?olderThan)
        {
            var service = new StatusesService(Token);

            return(StandardJsonResult(service, s => s.Mentions(newerThan, olderThan)));
        }
Ejemplo n.º 9
0
        public JsonResult OnHometimeline(long?newerThan, long?olderThan)
        {
            var service = new StatusesService(Token);

            return(StandardJsonResult(service, s => s.OnHomeTimeline(newerThan, olderThan)));
        }
Ejemplo n.º 10
0
        public IEnumerable <ProjectStatus> GetProjectStatuses()
        {
            var projectStatuses = new StatusesService(_dbContext).GetProjectStatuses();

            return(projectStatuses);
        }