public void Create_InputDtoAddUnit_AreSame()
        {
            var input = new InputDtoAddUnit("km");

            _unitFactory.CreateFromType(input.Type).Returns(new Unit(input.Type));
            var iunit = _unitFactory.CreateFromType(input.Type);

            _unitRepository.Query().Returns(getUnitList());
            _unitRepository.Create(iunit).Returns(new Unit(input.Type));

            var res = _unitService.Create(input);

            var expected = new OutputDtoAddUnit("km");

            Assert.AreEqual(expected, res);
        }
Пример #2
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IUnitService, IUnitRepository>();
            var model         = new ApiUnitServerRequestModel();
            var validatorMock = new Mock <IApiUnitServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiUnitServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new UnitService(mock.LoggerMock.Object,
                                          mock.MediatorMock.Object,
                                          mock.RepositoryMock.Object,
                                          validatorMock.Object,
                                          mock.DALMapperMockFactory.DALUnitMapperMock,
                                          mock.DALMapperMockFactory.DALCallAssignmentMapperMock,
                                          mock.DALMapperMockFactory.DALUnitOfficerMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiUnitServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <UnitCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Пример #3
0
        public JsonResult Create(Unit unit)
        {
            unit.Initialization(ObjectInitType.Insert, "", HttpContext);
            int result = unitService.Create(unit);

            if (result != 0)
            {
                return(Json(new { messageType = "success", note = AppGlobal.InsertSuccessMessage }));
            }
            else
            {
                return(Json(new { messageType = "eror", note = AppGlobal.InsertFailMessage }));
            }
        }
Пример #4
0
        public IActionResult Create(Unit unit)
        {
            int  count     = 0;
            var  json      = HttpContext.Request.Cookies["user"];
            User loginuser = JsonConvert.DeserializeObject <User>(json);

            unit.Proid = loginuser.relation.Proid;
            unit.Uid   = loginuser.detail.Uid;
            PlanService planService = new PlanService();

            unit.Pname = planService.Show((int)unit.Pid).Pname;
            count      = unitService.Create(unit);
            //if(count>0)
            return(Redirect(Url.Action("Index", "_Unit")));
            //else
        }
Пример #5
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IUnitService, IUnitRepository>();

            var model = new ApiUnitServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Unit>())).Returns(Task.FromResult(new Unit()));
            var service = new UnitService(mock.LoggerMock.Object,
                                          mock.MediatorMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.UnitModelValidatorMock.Object,
                                          mock.DALMapperMockFactory.DALUnitMapperMock,
                                          mock.DALMapperMockFactory.DALCallAssignmentMapperMock,
                                          mock.DALMapperMockFactory.DALUnitOfficerMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.UnitModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiUnitServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Unit>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <UnitCreatedNotification>(), It.IsAny <CancellationToken>()));
        }