using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using skyscraper5.Skyscraper;
using skyscraper8.Skyscraper.Scraper.Storage.Tar;

namespace skyscraper8.Tests;

[TestClass]
public class IntegrationTests
{
    [TestMethod]
    public void CreateTarArchive()
    {
        string filename = String.Format("{0}.tar", DateTime.Now.ToUnixTime());
        FileInfo fi = new FileInfo(filename);
        FileStream fileStream = fi.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
        fi.Refresh();
        Assert.IsTrue(fi.Exists);
        
        Random rng = new Random();
        
        TarArchive tar = new TarArchive(fileStream);
        for (int i = 0; i < 42; i++)
        {
            filename = String.Format("{0}.bin", i);

            int randomSize = rng.Next(4096);
            byte[] buffer = new byte[randomSize];
            rng.NextBytes(buffer);
            
            tar.WriteEntry(filename, buffer);
        }
    }
}