public void WritesCorrectNumberOfLines()
        {
            var bank   = new MockBank();
            var output = new List <string>();
            var writer = new MockWriter(output);

            CreateFileData.CreateFile(bank, writer);

            Assert.Equal(output.Count, 9);
        }
        public void WritesCorrectFormat()
        {
            var bank   = new MockBank();
            var output = new List <string>();
            var writer = new MockWriter(output);

            CreateFileData.CreateFile(bank, writer);

            Assert.Equal(output[0], "3");
            Assert.Equal(output[1], "1001;559268 - 7528;Berglunds snabbköp;Berguvsvägen  8;Luleå;;S - 958 22;Sweden;0921 - 12 34 65");
            Assert.Equal(output[4], "4");
            Assert.Equal(output[5], "13001;1001;100");
        }
Ejemplo n.º 3
0
        private static void CreateFileAndDisplayStatistics(Bank bank)
        {
            var fileName = DateTime.Now.ToString("yyyyMMdd-HHmm") + ".txt";
            var path     = CreateFileData.GetPath(fileName);

            var writer = new Writer(path, true);

            CreateFileData.CreateFile(bank, writer);

            Console.WriteLine("Sparar till " + fileName + "...");
            Console.WriteLine("Antal kunder: " + bank.Customers.Count);
            Console.WriteLine("Antal konton: " + bank.Accounts.Count);
            Console.WriteLine("Totalt saldo: " + bank.TotalBalance);
        }
Ejemplo n.º 4
0
        // POST: api/CreateFiles
        public IHttpActionResult Post(CreateFileData value)
        {
            Console.WriteLine("CreateFilesController");
            String uuid = "";

            IEnumerable <string> headerValues;
            var nameFilter = string.Empty;

            if (Request.Headers.TryGetValues(CsConstatnts.uuid, out headerValues))
            {
                nameFilter = headerValues.FirstOrDefault();
                uuid       = nameFilter;
            }

            if (false == ConnectionsManager.IsExist(uuid))
            {
                Console.WriteLine("user not logged in");
                Dictionary <String, object> errResponse = new Dictionary <String, object>();
                errResponse.Add(CsConstatnts.error, ErrorsCode.USER_NOT_LOGGED_IN);
                return(Ok(JsonUtils.toJsonStr(errResponse)));
            }
            CreateFilesPersistance createFilesPersistance = new CreateFilesPersistance();

            String fileNumber   = value.getFileNumber();
            long   creationDate = value.getCreationDate();
            String insuredName  = value.getInsuredName();
            String customer     = value.getCustomer();
            String employee     = value.getEmployee();
            String suitNumber   = value.getSuitNumber();
            String fileStatus   = value.getFileStatus();

            Console.WriteLine($"Sercing for file: {fileNumber} {creationDate} {insuredName} {customer} {employee} {suitNumber} {fileStatus}");
            bool creatioResult = createFilesPersistance.addNewRecord(fileNumber, creationDate, insuredName,
                                                                     customer, employee, suitNumber, fileStatus);
            Dictionary <String, object> response = new Dictionary <String, object>();

            if (true == creatioResult)
            {
                response.Add(CsConstatnts.fileNumber, fileNumber);
            }
            else
            {
                response.Add(CsConstatnts.error, ErrorsCode.FILE_CREATION_FAILED);
            }
            return(Ok(JsonUtils.toJsonStr(response)));
        }
Ejemplo n.º 5
0
        public int CreateFile(CreateFileData file)
        {
            using (MooDB db = new MooDB())
            {
                string fileName = Path.GetFileName(Config.UploadFileDirectory + file.Name);
                if (File.Exists(Config.UploadFileDirectory + fileName))
                {
                    fileName = Rand.RAND.Next() + fileName;
                    if (File.Exists(Config.UploadFileDirectory + fileName))
                    {
                        throw new ArgumentException("文件名称冲突");
                    }
                }
                UploadedFile newFile = new UploadedFile
                {
                    CreatedBy = Security.CurrentUser.GetDBUser(db),
                    Description = file.Description,
                    FileName = fileName,
                    Name = file.Name
                };

                Access.Required(db, newFile, Function.CreateFile);

                File.WriteAllBytes(Config.UploadFileDirectory + fileName, Binary.Get(file.BlobID, true));

                db.SaveChanges();
                return newFile.ID;
            }
        }