Пример #1
0
        public JsonResult Create([Bind(Include = "code,name,startAt,endAt,shiftType,remark")] Shift model)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                msg = DoValidation(model);

                if (!msg.Success)
                {
                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    IShiftService cs        = new ShiftService(Settings.Default.db);
                    bool          isSucceed = cs.Create(model);

                    msg.Success = isSucceed;
                    msg.Content = isSucceed ? "" : "添加失败";

                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new ResultMessage()
                {
                    Success = false, Content = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #2
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IShiftRepository>();
            var model = new ApiShiftRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Shift>())).Returns(Task.FromResult(new Shift()));
            var service = new ShiftService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.ShiftModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLShiftMapperMock,
                                           mock.DALMapperMockFactory.DALShiftMapperMock,
                                           mock.BOLMapperMockFactory.BOLEmployeeDepartmentHistoryMapperMock,
                                           mock.DALMapperMockFactory.DALEmployeeDepartmentHistoryMapperMock);

            CreateResponse <ApiShiftResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ShiftModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiShiftRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Shift>()));
        }