public void GetCreateShouldReturnView()
        {
            // Arrange
            var controller = new BrandsController(null, null);

            // Act
            var result = controller.Create();

            // Assert
            result.Should().NotBeNull();
            result.Should().BeOfType <ViewResult>();
            var viewName = result.As <ViewResult>().ViewName;

            viewName.Should().BeNull();
        }
        public async Task PostCreateShouldReturnsViewWithModelWhenModelNameExists()
        {
            // Arrange
            var resultBrand        = new Brand();
            var brandFormModel     = DataHelper.GetBrandFormModel();
            var adminBrandsService = new Mock <IAdminBrandsService>();
            var userManager        = this.GetUserManagerMock();

            adminBrandsService
            .Setup(s => s.CreateAsync(It.IsAny <Brand>()))
            .Callback((Brand model) => { resultBrand = model; })
            .ReturnsAsync(false);

            var controller = new BrandsController(adminBrandsService.Object, userManager.Object);

            // Act
            var result = await controller.Create(brandFormModel);

            // Assert
            result.Should().NotBeNull();
            controller.ModelState[WebConstants.StatusMessage].Errors[0].ErrorMessage.Should().Be(WebConstants.BrandNameExists);
        }
        public async Task PostCreateShouldReturnRedirectWithValidModel()
        {
            // Arrange
            var    resultBrand        = new Brand();
            var    brandFormModel     = DataHelper.GetBrandFormModel();
            string successMessage     = null;
            var    userManager        = this.GetUserManagerMock();
            var    adminBrandsService = new Mock <IAdminBrandsService>();

            adminBrandsService
            .Setup(s => s.CreateAsync(It.IsAny <Brand>()))
            .Callback((Brand model) => { resultBrand = model; })
            .ReturnsAsync(true);

            var tempData = new Mock <ITempDataDictionary>();

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

            var controller = new BrandsController(adminBrandsService.Object, userManager.Object);

            controller.TempData = tempData.Object;

            // Act
            var result = await controller.Create(brandFormModel);

            // Assert
            resultBrand.Should().NotBeNull();
            resultBrand.Name.Should().Be(brandFormModel.Name);
            resultBrand.WebSite.Should().Be(brandFormModel.WebSite);

            successMessage.Should().Be($"Brand {brandFormModel.Name} successfully created.");

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

            result.As <RedirectToActionResult>().ActionName.Should().Be("Index");
        }