Exemplo n.º 1
0
        public void PostControllerSavesPublicEntry()
        {
            // Arrange
            var entryVM = new EntryViewModel()
            {
                Content = "SuperContent",
                Summary = "SuperSummary"
            };

            var entryResult = new Entry()
            {
                Content = "SuperContent",
                Summary = "SuperSummary"
            };

            var repository = new Mock <EntryRepository>(It.IsAny <DbContext>());

            repository.Setup(x => x.Create(It.IsAny <Entry>())).Returns(It.IsAny <Entry>());
            var service    = new EntriesService(repository.Object);
            var controller = GetEntriesControllerWithUser(service);

            // Act
            var result = controller.Post(entryVM) as OkObjectResult;

            // Assert
            Assert.Equal(result.StatusCode, StatusCodes.Status200OK);
        }
Exemplo n.º 2
0
 public IActionResult Publicaciones(int page = 1)
 {
     if (page < 1)
     {
         return(RedirectToAction("Index", "Home"));
     }
     return(View(EntriesService.GetSectionModel(_searchService, "RSS", page)));
 }
Exemplo n.º 3
0
        public IActionResult Busqueda(string q, int page = 1)
        {
            if (string.IsNullOrWhiteSpace(q) || page < 1)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var model = EntriesService.GetModel(_searchService, q, page);

            if (model.Cantidad == 0)
            {
                return(View("~/Views/Error/Error404.cshtml"));
            }
            return(View(model));
        }
Exemplo n.º 4
0
        private static EntriesController GetEntriesControllerWithUser(EntriesService service)
        {
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, "1")
            }
                                                              )
                                           );

            var controller = new EntriesController(service);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user
                }
            };
            return(controller);
        }
Exemplo n.º 5
0
        public async Task GetControllerReturnsExistingEntry()
        {
            // Arrange
            var entry = new Entry()
            {
                Id = 99
            };

            var repository = new Mock <EntryRepository>(It.IsAny <DbContext>());

            repository.Setup(x => x.GetByIdAsync(99)).Returns(Task.FromResult(entry));
            var service    = new EntriesService(repository.Object);
            var controller = GetEntriesControllerWithUser(service);

            // Act
            var result = await controller.Get(entry.Id) as OkObjectResult;

            // Assert
            Assert.Equal(result.StatusCode, StatusCodes.Status200OK);
            Assert.Equal(result.Value, entry);
        }
Exemplo n.º 6
0
 public EntriesController(EntriesService service)
 {
     _service = service;
 }
Exemplo n.º 7
0
 public EntriesController(EntriesService es, AccountService aServ)
 {
     _es = es;
     _as = aServ;
 }