コード例 #1
0
        public void GetCreateShouldReturnView()
        {
            // Arrange
            var controller = new DrugGroupsController(null, null);

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

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

            viewName.Should().BeNull();
        }
コード例 #2
0
        public async Task PostCreateShouldReturnsViewWithModelWhenModelNameExists()
        {
            // Arrange
            var resultDrugGroup        = new DrugGroup();
            var drugGroupFormModel     = DataHelper.GetDrugGroupFormModel();
            var adminDrugGroupsService = new Mock <IAdminDrugGroupsService>();
            var userManager            = this.GetUserManagerMock();

            adminDrugGroupsService
            .Setup(s => s.CreateAsync(It.IsAny <DrugGroup>()))
            .Callback((DrugGroup model) => { resultDrugGroup = model; })
            .ReturnsAsync(false);

            var controller = new DrugGroupsController(adminDrugGroupsService.Object, userManager.Object);

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

            // Assert
            result.Should().NotBeNull();
            controller.ModelState[WebConstants.StatusMessage].Errors[0].ErrorMessage.Should().Be(WebConstants.DrugGroupNameExists);
        }
コード例 #3
0
        public async Task PostCreateShouldReturnRedirectWithValidModel()
        {
            // Arrange
            var    resultDrugGroup        = new DrugGroup();
            var    drugGroupFormModel     = DataHelper.GetDrugGroupFormModel();
            string successMessage         = null;
            var    userManager            = this.GetUserManagerMock();
            var    adminDrugGroupsService = new Mock <IAdminDrugGroupsService>();

            adminDrugGroupsService
            .Setup(s => s.CreateAsync(It.IsAny <DrugGroup>()))
            .Callback((DrugGroup model) => { resultDrugGroup = 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 DrugGroupsController(adminDrugGroupsService.Object, userManager.Object);

            controller.TempData = tempData.Object;

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

            // Assert
            resultDrugGroup.Should().NotBeNull();
            resultDrugGroup.Name.Should().Be(drugGroupFormModel.Name);

            successMessage.Should().Be($"Drug group {drugGroupFormModel.Name} successfully created.");

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

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