Esempio n. 1
0
        public void AllModelsShoudWork()
        {
            // Arrange
            var mockCitiesService            = new Mock <ICitiesService>();
            var mockMakesService             = new Mock <IMakesService>();
            var mockCategoriesService        = new Mock <ICategoriesService>();
            var mockCommentsService          = new Mock <ICommentsService>();
            var mockVehicleCategoriesService = new Mock <IVehicleCategoriesService>();
            var mockColorsService            = new Mock <IColorService>();
            var mockCloudinaryService        = new Mock <ICloudinaryService>();

            var mockUserManager   = this.GetMockUserManager();
            var mockModelsService = new Mock <IModelsService>();
            var mockPostsService  = new Mock <IPostsService>();

            mockModelsService
            .Setup(mc => mc.GetAll <ModelsReturnModel>())
            .Returns(this.GetAll <ModelsReturnModel>());

            var claims = new List <Claim>()
            {
                new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", "5247d66a-84ff-4987-abb5-53b1c2e747c2"),
                new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", "*****@*****.**"),
                new Claim("AspNet.Identity.SecurityStamp", "E7B2QZV5M4OIRM3ZFIVXFVGR3YULFGO7"),
                new Claim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role", "Admin"),
                new Claim("amr", "pwd"),
            };

            var claimsIdentity = new ClaimsIdentity(claims);

            var principal = new ClaimsPrincipal(claimsIdentity);

            Thread.CurrentPrincipal = principal;

            mockUserManager.Setup(mu => mu.GetUserAsync(principal))
            .Returns(Task.FromResult(new ApplicationUser()
            {
                UserName = "******", Image = new Image()
                {
                    Url = "testUrl"
                }
            }));

            // Act
            var controller = new PostsController(
                mockPostsService.Object,
                mockCitiesService.Object,
                mockCategoriesService.Object,
                mockMakesService.Object,
                mockModelsService.Object,
                mockVehicleCategoriesService.Object,
                mockColorsService.Object,
                mockUserManager.Object,
                mockCloudinaryService.Object,
                mockCommentsService.Object);

            // Assert
            var result = controller.AllModels();

            var typeResult = Assert.IsType <ActionResult <ICollection <ModelsReturnModel> > >(result);

            Assert.Equal(3, typeResult.Value.Count);
        }