﻿using System.Collections.Generic;
using System.IO;
using System.Text;
using BaxterWorks.B2.Extensions;
using BaxterWorks.B2.Types;
using NUnit.Framework;

namespace BaxterWorks.B2.NUnit.Tests
{
    [TestFixture]
    public class ListFilesTest
    {
        [Test]
        public void TestListFileNames()
        {
            var client = new ServiceStackB2Api();
            List<UploadFileResponse> uploadedList = new List<UploadFileResponse>();

            var bucket = client.CreateBucket("ListFileNamesTestBucket");

            MemoryStream fileContents = new MemoryStream(Encoding.UTF8.GetBytes("Hello World"));

            var request = new FileUploadRequest
            {
                FileContents = fileContents,
                ContentSHA1 = null,
                FileName = "one.txt",
                ContentType = "text/plain"
            };

            uploadedList.Add(client.UploadFile(request));
            request.FileContents.Seek(0, SeekOrigin.Begin);

            request.FileName = "two.txt";
            uploadedList.Add(client.UploadFile(request));
            request.FileContents.Seek(0, SeekOrigin.Begin);

            request.FileName = "three.txt";
            uploadedList.Add(client.UploadFile(request));
            request.FileContents.Seek(0, SeekOrigin.Begin);

            request.FileName = "four.txt";
            uploadedList.Add(client.UploadFile(request));
            request.FileContents.Seek(0, SeekOrigin.Begin);

            var response = client.ListFileNames(new ListFileNamesRequest() {BucketId = bucket.BucketId});
            foreach (var responseFile in response.Files)
            {
                Assert.IsTrue(uploadedList.Contains(responseFile));
            }
        }


        //todo: ListFilesTest: Add Cleanup.
    }
}

