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

            service.Setup(s => s.AddViewedAsync("id"))
            .ReturnsAsync(() => true);

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

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

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

            service.Setup(s => s.AddViewedAsync("id"))
            .Throws(new Exception());

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

            var result = await controller.AddViewed("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");
        }