public void Check_Ifile_Invalid_Value()
        {
            var    mockIserv            = new Mock <IService>();
            var    outPutDtos           = new List <OutPutDTO>();
            var    outputDto            = new OutPutDTO();
            object obj                  = new object();
            var    mockIServiceProvider = new Mock <IServiceProvider>();

            mockIServiceProvider.Setup(x => x.GetService(It.IsAny <Type>())).Returns(obj);
            var mockPremiumCalculation = new Mock <IPremiumCalculation>();

            mockPremiumCalculation.Setup(x => x.PremiumCalculationAmount(It.IsAny <InputDTO>())).Returns(outputDto);
            var mockMappingService = new Mock <IMappingSerrvice>();

            mockMappingService.Setup(x => x.MapService(It.IsAny <string>())).Returns(mockPremiumCalculation.Object);
            InputData inputData = new InputData();

            byte[] bytes = null;
            inputData.CsvFile = bytes;
            mockIserv.Setup(x => x.CustomerInsuranceGetAsync(It.IsAny <InputData>())).Returns(outPutDtos);
            var mockCustomerInsuranceService = new CustomerInsuranceService(mockMappingService.Object);
            var outPut = mockCustomerInsuranceService.CustomerInsuranceGetAsync(inputData);

            Assert.AreEqual(3, outPut.Count);
        }
        public void Check_Ifile_Value()
        {
            var    mockIserv            = new Mock <IService>();
            var    outPutDtos           = new List <OutPutDTO>();
            var    outputDto            = new OutPutDTO();
            object obj                  = new object();
            var    mockIServiceProvider = new Mock <IServiceProvider>();

            mockIServiceProvider.Setup(x => x.GetService(It.IsAny <Type>())).Returns(obj);
            var mockPremiumCalculation = new Mock <IPremiumCalculation>();

            mockPremiumCalculation.Setup(x => x.PremiumCalculationAmount(It.IsAny <InputDTO>())).Returns(outputDto);
            var mockMappingService = new Mock <IMappingSerrvice>();

            mockMappingService.Setup(x => x.MapService(It.IsAny <string>())).Returns(mockPremiumCalculation.Object);
            InputData inputData = new InputData();

            byte[] bytes = System.Convert.FromBase64String("SUQsVGl0bGUsRmlyc3ROYW1lLFN1cm5hbWUsUHJvZHVjdE5hbWUsUGF5b3V0QW1vdW50LEFubnVhbFByZW1pdW0NMSxNaXNzLFNhbGx5LFNtaXRoLFN0YW5kYXJkIENvdmVyLDE5MDgyMCwxMjMuNDUNMixNcixKb2huLFNtaXRoLEVuaGFuY2VkIENvdmVyLDgzMjA1LjUsMTIwDTMsTXJzLEhlbGVuLERhbmllbHMsU3BlY2lhbCBDb3ZlciwyMDAwMDAuOTksMTQxLjINCg==");
            inputData.CsvFile = bytes;
            mockIserv.Setup(x => x.CustomerInsuranceGetAsync(It.IsAny <InputData>())).Returns(outPutDtos);
            var mockCustomerInsuranceService = new CustomerInsuranceService(mockMappingService.Object);
            var outPut = mockCustomerInsuranceService.CustomerInsuranceGetAsync(inputData);

            Assert.AreEqual(3, outPut.Count);
        }
Пример #3
0
        /// <summary>
        /// Checks basic authentication request
        /// </summary>
        /// <param name="actionContext"></param>
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            base.OnAuthorization(actionContext); // Should this be here?
            OutPutDTO outPut = new OutPutDTO();

            var owinContext   = HttpContext.Current.GetOwinContext();
            var authenticated = owinContext.Authentication.User.Identity.IsAuthenticated;
            var request       = HttpContext.Current.Request;
            var roleAccess    = roles.Equals("") ? true : owinContext.Authentication.User.IsInRole(roles);

            if (!authenticated)
            {
                // Challenge user for crednetials
                if (!request.IsAuthenticated)
                {
                    actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
                }
            }
            else
            {
                if (!roleAccess)
                {
                    actionContext.Response = new HttpResponseMessage(HttpStatusCode.Forbidden);
                }
                return;
            }
        }
        public string GetStream(OutPutDTO outPutDto)
        {
            string myTempFilePath = string.Empty;

            if (_hostingEnvironment != null)
            {
                var           objpath = _hostingEnvironment.ContentRootPath + Constant.FileTypeName;
                string        text    = File.ReadAllText(objpath);
                StringBuilder sb      = new StringBuilder();
                sb.Append(text);
                sb.Replace(Constant.CurrentDate, DateTime.Now.Date.ToString(Constant.DateFormat))
                .Replace(Constant.FullName, outPutDto.Title + " " + outPutDto.FirstName)
                .Replace(Constant.WitthSurName, outPutDto.Title + " " + outPutDto.FirstName + " " + outPutDto.Surname)
                .Replace(Constant.PoductName, outPutDto.ProductName)
                .Replace(Constant.PayOutAmount, Constant.Pound + outPutDto.PayOutAmount.ToString(CultureInfo.InvariantCulture))
                .Replace(Constant.AnnualPremiumCharge, Constant.Pound + Math.Round(outPutDto.AnnualPemium, 2).ToString())
                .Replace(Constant.CreditCharge, Constant.Pound + Math.Round(outPutDto.CreditCharge, 2).ToString())
                .Replace(Constant.TotalPremium, Constant.Pound + Math.Round(outPutDto.TotalPremium, 2).ToString())
                .Replace(Constant.InitilaMonthPremium, Constant.Pound + outPutDto.InitialMonthlyPaymentAmount.ToString(CultureInfo.InvariantCulture))
                .Replace(Constant.OtherMonthPremium, Constant.Pound + outPutDto.OtherMonthlyPaymentsAmount.ToString(CultureInfo.InvariantCulture));
                myTempFilePath        = Path.Combine(Path.GetTempPath(), outPutDto.CustomerId + "_" + outPutDto.FirstName + Constant.Extention);
                using StreamWriter sw = new StreamWriter(myTempFilePath);
                sw.WriteLine(sb);
            }
            return(myTempFilePath);
        }
Пример #5
0
        public OutPutDTO PremiumCalculationAmount(InputDTO inputDtOs)
        {
            var outPutDto = new OutPutDTO();

            outPutDto = GetPremiumResult(inputDtOs);

            return(outPutDto);
        }
Пример #6
0
        private void btnAddDetailExport_Click(object sender, EventArgs e)
        {
            int flag = 0;

            if (datagridPackEx2.RowCount <= 1)
            {
                MessageBox.Show("Không thể thêm chi tiết");
            }
            else
            {
                if (txtNewIdOutPut.Text != "" && txtCreateDateOutPut.Text != "" && txtUserOutput.Text != "")
                {
                    OutPutDTO dto = new OutPutDTO(txtNewIdOutPut.Text, txtCreateDateOutPut.Text, txtUserOutput.Text.Substring(0, 10));
                    if (bus.ThemPhieuXuat(dto))
                    {
                        for (int i = 0; i < datagridPackEx2.RowCount - 1; i++)
                        {
                            try
                            {
                                string       masp           = datagridPackEx2.Rows[i].Cells[0].Value.ToString();
                                string       mapackage      = datagridPackEx2.Rows[i].Cells[1].Value.ToString();
                                int          sl             = Int32.Parse(datagridPackEx2.Rows[i].Cells[2].Value.ToString());;
                                string       machitietphieu = txtNewIdOutPut.Text;
                                OutPutDetail dto1           = new OutPutDetail(machitietphieu, masp, mapackage, sl);
                                if (bus.ThemCTPhieuXuat(dto1))
                                {
                                    flag = 1;
                                }
                                else
                                {
                                    flag = 0;
                                }
                            }
                            catch (Exception)
                            {
                                MessageBox.Show("Đã xảy ra lỗi");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Thêm thất bại");
                    }
                }
                else
                {
                    MessageBox.Show("Không thể thêm");
                }
                if (flag == 1)
                {
                    MessageBox.Show("Thêm thành công chi tiết phiếu xuất hàng");
                }
                else
                {
                    MessageBox.Show("Thêm chi tiết xuất hàng thất bại");
                }
            }
        }
        public OutPutDTO PremiumCalculationAmount(InputDTO inputDto)
        {
            if (inputDto.PayOutAmount >= 6500000)
            {
                throw new System.Exception("Premium value should not exceed 6500000 " + inputDto.CustomerId);
            }

            var outPutDto = new OutPutDTO();

            outPutDto = GetPremiumResult(inputDto);

            return(outPutDto);
        }
Пример #8
0
        public virtual OutPutDTO GetPremiumResult(InputDTO inputDto)
        {
            var outPutDto = new OutPutDTO();

            try
            {
                outPutDto = MapObject(inputDto);
            }
            catch (Exception exception)
            {
                Logger.InsertLogs(exception);
            }

            return(outPutDto);
        }
Пример #9
0
        public void ByteLength_Positive_Negative_Check()
        {
            var       mockIserv = new Mock <IService>();
            var       outPutDto = new List <OutPutDTO>();
            OutPutDTO outPutDTO = new OutPutDTO {
                AnnualPemium = 1.13
            };
            InputData inputData = new InputData();

            mockIserv.Setup(x => x.CustomerInsuranceGetAsync(It.IsAny <InputData>())).Returns(outPutDto);
            var inputService = new InsuranceRenualController(mockIserv.Object);
            var sample       = inputService.RenualTextFiles(inputData);
            var statuscode   = ((Microsoft.AspNetCore.Mvc.StatusCodeResult)sample).StatusCode;

            Assert.AreNotEqual(200, statuscode);
        }
Пример #10
0
        public List <OutPutDTO> CustomerInsuranceGetAsync(InputData file)
        {
            if (file.CsvFile == null)
            {
                throw new ArgumentNullException();
            }
            var       stream     = new MemoryStream(file.CsvFile);
            IFormFile files      = new FormFile(stream, 0, Constant.Size, Constant.Name, Constant.Filename);
            var       outPutDtOs = new List <OutPutDTO>();
            string    filepath   = ReadFile.GetFileName(files).Result;

            try
            {
                using var reader    = new StreamReader(filepath, Encoding.Default);
                using var csvReader = new CsvReader(reader, CultureInfo.CurrentCulture);
                csvReader.Configuration.RegisterClassMap <MapObject>();
                var inputDtos = csvReader.GetRecords <InputDTO>().ToList();
                foreach (var inPutDto in inputDtos)
                {
                    OutPutDTO outPutDtO = _mappingService.MapService(inPutDto.ProductName).PremiumCalculationAmount(inPutDto);
                    outPutDtOs.Add(outPutDtO);
                }
            }
            catch (UnauthorizedAccessException e)
            {
                throw new Exception(e.Message);
            }
            catch (FieldValidationException e)
            {
                throw new Exception(e.Message);
            }
            catch (CsvHelperException e)
            {
                throw new Exception(e.Message);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            return(outPutDtOs);
        }
        public override OutPutDTO GetPremiumResult(InputDTO inputDtos)
        {
            var outPutDto   = new OutPutDTO();
            var getDiscount = GetConfigProductInfo(_productTypeDiscounts, inputDtos.ProductName);

            if (inputDtos.PayOutAmount > 6500000)
            {
                if (getDiscount > 0)
                {
                    var anualPremium = (getDiscount * inputDtos.AnnualPemium) / 100;
                    inputDtos.AnnualPemium = inputDtos.AnnualPemium - anualPremium;
                }
                else
                {
                    var anualPremium = (20 * inputDtos.AnnualPemium) / 100;
                    inputDtos.AnnualPemium = inputDtos.AnnualPemium - anualPremium;
                }
            }
            outPutDto = MapObject(inputDtos);

            return(outPutDto);
        }
Пример #12
0
        public bool ThemPhieuXuat(OutPutDTO dto)
        {
            try
            {
                _conn.Open();
                string     SQL = string.Format("INSERT INTO OutputProduct(ID, DATEOUTPUT, ID_USER) VALUES ('{0}', '{1}', '{2}')", dto.maPhieu, dto.NgayLap, dto.maNhanVien);
                SqlCommand cmd = new SqlCommand(SQL, _conn);
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                _conn.Close();
            }

            return(false);
        }
Пример #13
0
        public OutPutDTO MapObject(InputDTO inputDto)
        {
            OutPutDTO outPutDto = new OutPutDTO();

            outPutDto.CustomerId   = inputDto.CustomerId;
            outPutDto.Title        = inputDto.Title;
            outPutDto.Surname      = inputDto.Surname;
            outPutDto.FirstName    = inputDto.FirstName;
            outPutDto.ProductName  = inputDto.ProductName;
            outPutDto.PayOutAmount = inputDto.PayOutAmount;
            outPutDto.AnnualPemium = inputDto.AnnualPemium;;
            outPutDto.CreditCharge = (5 * outPutDto.AnnualPemium) / 100;
            outPutDto.TotalPremium = outPutDto.AnnualPemium + outPutDto.CreditCharge;
            double divideAverageAmount = outPutDto.TotalPremium / 12;
            double monthlyAmount       = Math.Round(divideAverageAmount, 2);
            double monthlyAmountExcess = Math.Round(divideAverageAmount, 10);
            double exceedAmount        = Math.Round((monthlyAmountExcess - monthlyAmount) * 12, 2);

            outPutDto.InitialMonthlyPaymentAmount = monthlyAmount + exceedAmount;
            outPutDto.OtherMonthlyPaymentsAmount  = monthlyAmount;

            return(outPutDto);
        }
Пример #14
0
        public bool SuaPhieuXuat(OutPutDTO dto)
        {
            try
            {
                _conn.Open();
                string     SQL = string.Format("UPDATE OutputProduct SET DATEOUTPUT = '{0}', ID_USER = '******' WHERE ID = '{2}'", dto.NgayLap, dto.maNhanVien, dto.maPhieu);
                SqlCommand cmd = new SqlCommand(SQL, _conn);
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                _conn.Close();
            }

            return(false);
        }
        public async Task <OutPutDTO> GetWeatherAsync(InputDto input)
        {
            OutPutDTO model = new OutPutDTO();

            // get city info
            string cityApiUrl = WeatherConst.HefengApiUrl + $"v2/city/lookup?location={input.City}&mode=fuzzy&key={input.Token}&gzip=n";

            var client = _clientFactory.CreateClient();

            var request = new HttpRequestMessage(HttpMethod.Get, cityApiUrl);

            var response = await client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                JObject cityObj = JObject.Parse(await response.Content.ReadAsStringAsync());
                model.CityId   = cityObj["location"][0]["id"].ToString();
                model.CityName = cityObj["location"][0]["name"].ToString();

                model.H5Url = $"https://widget-page.heweather.net/h5/index.html?bg=1&md=012345&lc={model.CityId}&key={input.Token}";

                string nowApiUrl   = $"https://devapi.heweather.net/v7/weather/now?location={model.CityId}&key={input.Token}&gzip=n";
                var    requestNow  = new HttpRequestMessage(HttpMethod.Get, nowApiUrl);
                var    responseNow = await client.SendAsync(requestNow);

                if (responseNow.IsSuccessStatusCode)
                {
                    JObject _objectNow = JObject.Parse(await responseNow.Content.ReadAsStringAsync());

                    model.Text      = _objectNow["now"]["text"].ToString();
                    model.FeelsLike = Convert.ToDouble(_objectNow["now"]["feelsLike"].ToString());
                    model.Humidity  = Convert.ToDouble(_objectNow["now"]["humidity"].ToString());
                }
            }
            return(model);
        }
Пример #16
0
 public bool ThemPhieuXuat(OutPutDTO dto)
 {
     return(dal.ThemPhieuXuat(dto));
 }
Пример #17
0
 public bool SuaPhieuXuat(OutPutDTO dto)
 {
     return(dal.SuaPhieuXuat(dto));
 }