Example #1
0
        public async Task P2PBySlug_Should_Call_IPodcastService_GetP2PBySlug_And_Return_NotFound_If_IMeetupService_GetP2PBySlug_Returns_Null()
        {
            P2PControllerMock mock = P2PControllerMock.Create();

            mock.PodcastService.Setup(service => service.GetP2PBySlug(It.IsAny <string>())).ReturnsAsync(() => null);

            IActionResult actionResult = await mock.P2PBySlug("burak-selim-senyurt");

            var notFoundResult = actionResult as NotFoundResult;

            Assert.NotNull(notFoundResult);
            mock.PodcastService.Verify(service => service.GetP2PBySlug(It.IsAny <string>()), Times.Once);
        }
Example #2
0
        public async Task P2Ps_Should_Call_IPodcastService_GetP2Ps_And_Return_Ok()
        {
            P2PControllerMock mock = P2PControllerMock.Create();

            mock.PodcastService.Setup(service => service.GetP2Ps()).ReturnsAsync(() => new List <IPodcastModel>());

            IActionResult actionResult = await mock.P2Ps();

            var okObjectResult = actionResult as OkObjectResult;

            Assert.NotNull(okObjectResult);

            var podcastModels = okObjectResult.Value as List <IPodcastModel>;

            Assert.NotNull(podcastModels);
            mock.PodcastService.Verify(service => service.GetP2Ps(), Times.Once);
        }
Example #3
0
        public async Task P2PBySlug_Should_Return_BadRequest_If_ModelState_Is_Invalid()
        {
            P2PControllerMock mock = P2PControllerMock.Create();

            mock.ModelState.AddModelError("test", "test");

            IActionResult actionResult = await mock.P2PBySlug("burak-selim-senyurt");

            var badRequestObjectResult = actionResult as BadRequestObjectResult;

            Assert.NotNull(badRequestObjectResult);

            var serializableError = badRequestObjectResult.Value as SerializableError;

            Assert.NotNull(serializableError);
            Assert.True(((string[])serializableError["test"])[0] == "test");
            mock.PodcastService.Verify(service => service.GetP2PBySlug(It.IsAny <string>()), Times.Never);
        }
Example #4
0
        public async Task P2PBySlug_Should_Call_IPodcastService_GetP2PBySlug_And_Return_Ok()
        {
            P2PControllerMock mock = P2PControllerMock.Create();

            var slug = "burak-selim-senyurt";

            mock.PodcastService.Setup(service => service.GetP2PBySlug(It.Is <string>(i => i == slug))).ReturnsAsync(() => new P2PModel());

            IActionResult actionResult = await mock.P2PBySlug(slug);

            var okObjectResult = actionResult as OkObjectResult;

            Assert.NotNull(okObjectResult);

            var p2PModel = okObjectResult.Value as P2PModel;

            Assert.NotNull(p2PModel);
            mock.PodcastService.Verify(service => service.GetP2PBySlug(It.IsAny <string>()), Times.Once);
        }