public void FileUploadTest()
        {
            var controller = new EdocumentsController();
            controller.Request = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            var fileBase = new FileBase();
            fileBase.DocumentType = "Some Type";
            fileBase.DocumentDescription = "Document Description";
            fileBase.EmailId = "*****@*****.**";
            fileBase.IsPublicViewable = true;
            fileBase.ParentSystem = "Customer Portal";
            fileBase.ParentSource = "Shipment";

            var FName = @"D:\newUpload.txt";
            //string filePath = Path.GetFullPath(FName);
            //string directoryPath = Path.GetDirectoryName(FName);
            //FileStream fileStream = new FileStream(@"C:\Users\admin\Desktop\new  8.txt", FileMode.Open,FileAccess.Read, FileShare.None);
            byte[] b1 = System.Text.Encoding.UTF8.GetBytes(FName);
            // convert string to stream
            byte[] byteArray = Encoding.UTF8.GetBytes(FName);
            //byte[] byteArray = Encoding.ASCII.GetBytes(contents);
            Stream stream;
            try
            {
                stream = new MemoryStream(byteArray);
            }
            catch (Exception ex)
            {

                throw ex;
            }

            Mock<HttpPostedFileBase> uploadedFile = new Mock<HttpPostedFileBase>();
            uploadedFile
            .Setup(f => f.ContentLength)
            .Returns(100000);

            uploadedFile
                .Setup(f => f.FileName)
                .Returns("new  8.txt");

            uploadedFile
                .Setup(f => f.ContentType)
                .Returns("text/plain");

            uploadedFile
                .Setup(f => f.InputStream)
                .Returns(stream);
            fileBase.PostedFileBase = uploadedFile.Object;
            var actual = controller.PostUploadFiles(fileBase);
        }
        public IHttpActionResult PostUploadFiles(FileBase fileBase)
        {
            try
            {
                HttpPostedFileBase theFile = fileBase.PostedFileBase;
                if (theFile.ContentLength != 0)
                {
                    var objFile = new Dms();
                    var file = new File();
                    var buffer = new byte[theFile.ContentLength];
                    fileBase.PostedFileBase.InputStream.Read(buffer, 0, fileBase.PostedFileBase.ContentLength);
                    var stream = new System.IO.MemoryStream(buffer);
                    MemoryStream objFile1 = new MemoryStream();
                    file = objFile.FileUpload(ConfigurationManager.AppSettings["ClientId"],
                                                ConfigurationManager.AppSettings["Clientsecret"],
                                                theFile.FileName,
                                                theFile.FileName,
                                                theFile.ContentType,
                                                stream,
                                                ConfigurationManager.ConnectionStrings["BPM"].ToString()
                                                );
                    if (file != null)
                    {
                        //ObjCPService.FileTableInsert(new CPservice.ecubeDocument
                        //{
                        //    ParentCode = guId,
                        //    // ParentCode = "",//  replace with shipment No
                        //    DateCreated = DateTime.Now,
                        //    DocType = Request.QueryString["DocType"],
                        //    DocName = Request.QueryString["DocDesc"],
                        //    DocumentURL = file.DownloadUrl,
                        //    DocReferenceID = file.Id,
                        //    FileName = file.OriginalFilename.Substring(file.OriginalFilename.LastIndexOf("\\") + 1),
                        //    //FileContentBytes = buffer,
                        //    FileExtension = file.FileExtension,
                        //    UploadedBy = Session["EmailId"].ToString(), //Session["UserId"].ToString(),
                        //    PublicViewable = "Y",
                        //    ParentSystem = "CP",//eCube
                        //    ParentSource = "Shipment",
                        //    ContentType = file.FileExtension,
                        //    SizeInKB = Convert.ToInt64(Math.Round(ConvertBytesToMegabytes(Convert.ToInt64(file.FileSize)), 4))
                        //});
                        var documents = new eDrive_Document
                        {
                            DocCode = "",
                            FileName = file.OriginalFilename,
                            FileExtension = file.FileExtension,
                            SizeinKb = Convert.ToInt64(Math.Round(ConvertBytesToMegabytes(Convert.ToInt64(file.FileSize)), 4)),
                            ContentType = file.FileExtension,
                            IsPublic = true,
                            IsAuto = true,
                            IsDeleted = false,
                            ParentSystem = fileBase.ParentSystem,
                            ParentSource = fileBase.ParentSource,
                            ParentCode= "Parent Code",
                            IsQuarantine=true,
                            GoogleReferenceId = file.Id,
                            GoogleURL = file.DownloadUrl,
                            CreatedBy = "Admin",
                            CreatedDate=DateTime.Now,
                            ModifiedBy="Admin",
                            DateModified = DateTime.Now
                        };
                        _db.eDrive_Document.Add(documents);
                        _db.SaveChanges();
                    }

                }

                return Ok();
            }
            catch (Exception e)
            {
                throw e;
            }
        }