public void Fail_Return_Success()
        {
            //Setup
            string ApiVersion = "V1";
            int    StatusCode = 200;
            string Message    = "OK";

            COAViewModel    viewModel         = new COAViewModel();
            ResultFormatter formatter         = new ResultFormatter(ApiVersion, StatusCode, Message);
            var             validationContext = new ValidationContext(viewModel);

            var errorData = new
            {
                WarningError = "Format Not Match"
            };

            string error     = JsonConvert.SerializeObject(errorData);
            var    exception = new ServiceValidationException(validationContext, new List <ValidationResult>()
            {
                new ValidationResult(error, new List <string>()
                {
                    "WarningError"
                })
            });

            //Act
            var result = formatter.Fail(exception);

            //Assert
            Assert.True(0 < result.Count());
        }
Пример #2
0
        public void Should_Success_Upload_Validate_Data()
        {
            COAService   service   = new COAService(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            COAViewModel viewModel = _dataUtil(service).GetNewViewModel();

            List <COAViewModel> coa = new List <COAViewModel>()
            {
                viewModel
            };
            var Response = service.UploadValidate(ref coa, null);

            Assert.True(Response.Item1);
        }
Пример #3
0
        public void Should_Fail_Upload_Validate_Too_long_Data()
        {
            COAService   service   = new COAService(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            COAViewModel viewModel = _dataUtil(service).GetNewViewModel();

            viewModel.Code = "11111.1111.1111.1111";
            List <COAViewModel> coa = new List <COAViewModel>()
            {
                viewModel
            };
            var Response = service.UploadValidate(ref coa, null);

            Assert.False(Response.Item1);
        }
Пример #4
0
        public async Task Should_Fail_Upload_Existed_Data()
        {
            COAService   service   = new COAService(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            COAViewModel viewModel = _dataUtil(service).GetNewViewModel();

            List <COAViewModel> coa = new List <COAViewModel>()
            {
                viewModel
            };
            COAModel model = _dataUtil(service).GetNewData();

            List <COAModel> coaModel = new List <COAModel>()
            {
                model
            };
            await service.UploadData(coaModel);

            var Response2 = service.UploadValidate(ref coa, null);

            Assert.False(Response2.Item1);
        }
        public void Fail_Throws_Exception()
        {
            //Setup
            string ApiVersion = "V1";
            int    StatusCode = 200;
            string Message    = "OK";

            COAViewModel    viewModel         = new COAViewModel();
            ResultFormatter formatter         = new ResultFormatter(ApiVersion, StatusCode, Message);
            var             validationContext = new ValidationContext(viewModel);
            var             exception         = new ServiceValidationException(validationContext, new List <ValidationResult>()
            {
                new ValidationResult("errorMessaage", new List <string>()
                {
                    "WarningError"
                })
            });

            //Act
            var result = formatter.Fail(exception);

            //Assert
            Assert.True(0 < result.Count());
        }
Пример #6
0
        public void Should_Success_Validate_All_Null_Data()
        {
            COAViewModel vm = new COAViewModel();

            Assert.True(vm.Validate(null).Count() > 0);
        }