コード例 #1
0
        public void OrderCreateValidator_Should_Fail_Validation_When_ObjectNumber_Null()
        {
            // arrange
            var sut   = new OrderCreateValidator();
            var order = new OrderCreateRequest();

            // act
            var result = sut.Validate(order);

            // assert
            Assert.False(result.IsValid);
        }
コード例 #2
0
        public void OrderCreateValidator_Should_Pass_Validation_When_ObjectNumber_NotNull()
        {
            // arrange
            var sut   = new OrderCreateValidator();
            var order = new OrderCreateRequest {
                ObjectNumber = "B123",
            };

            // act
            var result = sut.Validate(order);

            // assert
            Assert.True(result.IsValid);
        }
コード例 #3
0
        public IActionResult CreateOrder(OrderCreateModel orderCreate)
        {
            orderCreate.PostId    = _post.PostId;
            orderCreate.ProductId = _product.ProductId;
            orderCreate.UserTo    = _userTo.Id;
            orderCreate.UserFrom  = _uow.UserManager.FindByNameAsync(HttpContext.User?.Identity?.Name).Result.Id;
            var product = _uow.ProductRepository.List().Where(p => p.ProductId == _product.ProductId).FirstOrDefault();

            if (orderCreate.ProductCount > product.Count)
            {
                orderCreate.ProductCount = product.Count;
            }
            var validator = new OrderCreateValidator();

            if (validator.Validate(orderCreate).IsValid)
            {
                var orderBL = new OrderBL(_uow, _mapper);
                if (orderBL.AddOrder(orderCreate))
                {
                    return(RedirectToAction("AccountPage", "Account"));
                }
            }
            return(RedirectToAction());
        }