Esempio n. 1
0
        public async Task CreatePost_WithCorrectData_ShouldReturnSuccessMessageAndReturnToSubcategoriesIndex()
        {
            string successMessage = null;

            //Arrange
            Mock <IManagerCategoryService> managerCategoryService = new Mock <IManagerCategoryService>();

            managerCategoryService
            .Setup(m => m.GetAllBasicListingAsync(false))
            .ReturnsAsync(new List <CategoryBasicServiceModel>());

            Mock <IManagerSubcategoryService> managerSubcategoryService = new Mock <IManagerSubcategoryService>();

            managerSubcategoryService
            .Setup(m => m.CreateAsync(null, 0))
            .Returns(Task.CompletedTask);

            Mock <ISubcategoryService> subcategoryService = new Mock <ISubcategoryService>();

            subcategoryService
            .Setup(c => c.IsSubcategoryExistingByName(null))
            .ReturnsAsync(false);

            Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>();

            tempData
            .SetupSet(t => t[TempDataSuccessMessageKey] = It.IsAny <string>())
            .Callback((string key, object message) => successMessage = message as string);

            SubcategoriesController subcategoriesController = new SubcategoriesController(managerSubcategoryService.Object, managerCategoryService.Object, subcategoryService.Object)
            {
                TempData = tempData.Object
            };

            //Act
            var result = await subcategoriesController.Create(new SubcategoryFormViewModel());

            //Assert
            successMessage.Should().Be(string.Format(EntityCreated, SubcategoryEntity));

            result.Should().BeOfType <RedirectToActionResult>();

            result.As <RedirectToActionResult>().ActionName.Should().Be("Index");
            result.As <RedirectToActionResult>().ControllerName.Should().Be("Subcategories");
            result.As <RedirectToActionResult>().RouteValues.Keys.Should().Contain("isDeleted");
            result.As <RedirectToActionResult>().RouteValues.Values.Should().Contain(false);
        }
Esempio n. 2
0
        public async Task CreateGet_ShouldReturnValidViewModel()
        {
            //Arrange
            Mock <IManagerCategoryService> managerCategoryService = new Mock <IManagerCategoryService>();

            managerCategoryService
            .Setup(m => m.GetAllBasicListingAsync(false))
            .ReturnsAsync(new List <CategoryBasicServiceModel>());

            SubcategoriesController subcategoriesController = new SubcategoriesController(null, managerCategoryService.Object, null);

            //Act
            var result = await subcategoriesController.Create();

            //Assert
            result.Should().BeOfType <ViewResult>();

            result.As <ViewResult>().Model.Should().BeOfType <SubcategoryFormViewModel>();
        }
Esempio n. 3
0
        public async Task CreatePost_WithExistingSubcategory_ShouldReturnErrorMessageAndReturnValidViewModel()
        {
            string errorMessage = null;

            //Arrange
            Mock <IManagerCategoryService> managerCategoryService = new Mock <IManagerCategoryService>();

            managerCategoryService
            .Setup(m => m.GetAllBasicListingAsync(false))
            .ReturnsAsync(new List <CategoryBasicServiceModel>());

            Mock <ISubcategoryService> subcategoryService = new Mock <ISubcategoryService>();

            subcategoryService
            .Setup(c => c.IsSubcategoryExistingByName(null))
            .ReturnsAsync(true);

            Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>();

            tempData
            .SetupSet(t => t[TempDataErrorMessageKey] = It.IsAny <string>())
            .Callback((string key, object message) => errorMessage = message as string);

            SubcategoriesController subcategoriesController = new SubcategoriesController(null, managerCategoryService.Object, subcategoryService.Object)
            {
                TempData = tempData.Object
            };

            //Act
            var result = await subcategoriesController.Create(new SubcategoryFormViewModel());

            //Assert
            errorMessage.Should().Be(string.Format(EntityExists, SubcategoryEntity));

            result.Should().BeOfType <ViewResult>();

            result.As <ViewResult>().Model.Should().BeOfType <SubcategoryFormViewModel>();
        }