Exemplo n.º 1
0
        public async Task Favorite_ShouldReturnTrue()
        {
            var service = new Mock <IStoryService>();

            service.Setup(s => s.FavoriteAsync("id", user))
            .ReturnsAsync(() => true);

            StoriesController controller = new StoriesController(
                service.Object, userManager.Object, logger)
            {
                TempData = new TempDataDictionary(httpContext.Object, tempDataProvider.Object)
            };

            var result = await controller.Favorite("id");

            result.ShouldBeTrue();
        }
Exemplo n.º 2
0
        public async Task Favorite_ShouldReturnFalse()
        {
            var service = new Mock <IStoryService>();

            service.Setup(s => s.FavoriteAsync("id", user))
            .Throws(new Exception());

            StoriesController controller = new StoriesController(
                service.Object, userManager.Object, logger)
            {
                TempData = new TempDataDictionary(httpContext.Object, tempDataProvider.Object)
            };

            var result = await controller.Favorite("id");

            result.ShouldBeFalse();
            controller.TempData.ContainsKey("notification").ShouldBeTrue();
            controller.TempData["notification"].ShouldNotBeNull();
            controller.TempData["notification"].ShouldBeOfType <string[]>();
            string[] arr = controller.TempData["notification"] as string[];
            arr[0].ShouldBe("danger");
        }