Пример #1
0
 public ActionResult CreateProvider(ProviderCreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         IProviderService providerSvc = new ProviderService();
         providerSvc.CreateProvider(model.Name);
         return(RedirectToAction(nameof(ProviderList)));
     }
     ModelState.AddModelError("", "您录入的信息有误");
     return(View());
 }
Пример #2
0
        public void FailWithUnauthorizedAccessExceptionIfUserTriesToAccessAnythingWithoutProviderManagementPrivilege()
        {
            Provider providerToCreate = new Provider("Antel", 20, new List <IField>());
            var      mockUnitOfWork   = new Mock <IUnitOfWork>();

            mockUnitOfWork
            .Setup(un => un.CurrentSignedInUserHasRequiredPrivilege(It.IsAny <string>(), ProviderManagementPrivilege.GetInstance()))
            .Returns(false);
            ProviderService providerService = new ProviderService(mockUnitOfWork.Object);

            int id = providerService.CreateProvider(providerToCreate, It.IsAny <string>());
        }
Пример #3
0
        public void FailWithNullArgumentExceptionIfToBeCreatedNewProviderIsNull()
        {
            Provider nullProvider   = null;
            var      mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork
            .Setup(un => un.CurrentSignedInUserHasRequiredPrivilege(It.IsAny <string>(), ProviderManagementPrivilege.GetInstance()))
            .Returns(true);
            ProviderService providerService = new ProviderService(mockUnitOfWork.Object);

            int id = providerService.CreateProvider(nullProvider, It.IsAny <string>());
        }
Пример #4
0
        public void FailWithArgumentExceptionIfToBeCreatedNewProviderIsMarkedAsDeleted()
        {
            Provider deletedProvider = new Provider("UTE", 60, new List <IField>());

            deletedProvider.MarkAsInactiveToShowItIsDeleted();
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork
            .Setup(un => un.CurrentSignedInUserHasRequiredPrivilege(It.IsAny <string>(), ProviderManagementPrivilege.GetInstance()))
            .Returns(true);
            ProviderService providerService = new ProviderService(mockUnitOfWork.Object);

            int id = providerService.CreateProvider(deletedProvider, It.IsAny <string>());
        }
Пример #5
0
        public void BeAbleToCreateNewProviderInRepository()
        {
            User receivedUser   = new User("Bruno", "*****@*****.**", "#ElBizagra1996", AdminRole.GetInstance());
            var  mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(un => un.CurrentSignedInUserHasRequiredPrivilege(receivedUser.Email, ProviderManagementPrivilege.GetInstance())).Returns(true);
            mockUnitOfWork.Setup(un => un.ProviderRepository.Insert(It.IsAny <Provider>()));
            mockUnitOfWork.Setup(un => un.Save());
            ProviderService providerService = new ProviderService(mockUnitOfWork.Object);

            Provider oneProvider = new Provider("UTE", 60, new List <IField>());
            int      id          = providerService.CreateProvider(oneProvider, receivedUser.Email);

            mockUnitOfWork.VerifyAll();
        }
Пример #6
0
        public void FailWithInvalidOperationExceptionIfToBeCreatedNewProviderHasTheNameOfAnActiveProviderInRepository()
        {
            Provider providerWithSameName     = new Provider("UTE", 60, new List <IField>());
            Provider providerWithRepeatedName = new Provider("UTE", 25, new List <IField>());
            var      mockUnitOfWork           = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(un => un.ProviderRepository.Get(
                                     It.IsAny <System.Linq.Expressions.Expression <Func <Provider, bool> > >(), null, "")).Returns(new[] { providerWithSameName });
            mockUnitOfWork
            .Setup(un => un.CurrentSignedInUserHasRequiredPrivilege(It.IsAny <string>(), ProviderManagementPrivilege.GetInstance()))
            .Returns(true);
            ProviderService providerService = new ProviderService(mockUnitOfWork.Object);

            int id = providerService.CreateProvider(providerWithRepeatedName, It.IsAny <string>());
        }
Пример #7
0
        public ActionResult Create(ProviderCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            //HttpPostedFileBase file = Request.Files["ImageData"]; //Do I need this line?
            var service = new ProviderService();

            if (service.CreateProvider(model))
            {
                TempData["SaveResult"] = "Provider successfully created.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Provider could not be created.");
            return(View(model));
        }