Exemple #1
0
        public async Task TestCreateMarket_Failed_Error()
        {
            //Arrange
            var marketDetailsViewModel = new MarketDetailsViewModel()
            {
                MarketId   = 1,
                MarketName = "market",
            };
            var market = new Market()
            {
                Id = 1, Name = "Market1", IsActive = true, IsDeleted = false
            };
            var baseResult = new BaseResult <List <Market> >()
            {
                Result = new List <Market>()
                {
                    market
                }
            };

            iMarketLibrary.Setup(x => x.InsertEntity(It.IsAny <Market>())).Returns(Task.FromResult(new BaseResult <long>()
            {
                IsError          = true,
                ExceptionMessage = Helper.Common.GetMockException()
            })).Verifiable();

            //Act
            Task <BaseResult <Market> > actionResult = marketRepository.CreateMarket(marketDetailsViewModel, It.IsAny <string>());

            //Assert
            Assert.IsTrue(actionResult.Result.IsError);
            Assert.IsTrue(actionResult.Result.ExceptionMessage != null);
        }
Exemple #2
0
        public async Task <IActionResult> CreateMarket([FromBody] MarketDetailsViewModel marketDetailsViewModel)
        {
            BaseResult <Market> createMarketResult = new BaseResult <Market>();

            if (marketDetailsViewModel == null)
            {
                createMarketResult.IsError = true;
                createMarketResult.Message = string.Format(coreHelper.Constants.ErrorMessage.EmptyModel);
                return(BadRequest(createMarketResult)); //400
            }
            string userName = base.LoggedInUserName;

            createMarketResult = await iMarket.CreateMarket(marketDetailsViewModel, userName).ConfigureAwait(false);

            if (createMarketResult.IsError && createMarketResult.ExceptionMessage != null)
            {
                return(new StatusCodeResult(500));
            }
            else if (createMarketResult.Result == null)
            {
                return(new NoContentResult());
            }
            return(Ok(createMarketResult));
        }