<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using AppUpdater.Publisher;
using System.IO;
using AppUpdater.Manifest;
using System.Xml;

namespace AppUpdater.Tests.Publisher
{
    [TestFixture]
    public class AppPublisherTests
    {
        private AppPublisher appPublisher;
        private string sourceDir;
        private string destinationDir;

        [SetUp]
        public void Setup()
        {
            sourceDir = Path.GetTempFileName() + "_";
            destinationDir = Path.GetTempFileName() + "_";
            Directory.CreateDirectory(sourceDir);
            Directory.CreateDirectory(destinationDir);
            CreateVersionFiles();

            appPublisher = new AppPublisher();
        }

        [TearDown]
        public void TearDown()
        {
            Directory.Delete(sourceDir, true);
            Directory.Delete(destinationDir, true);
        }

        [Test]
        public void Publish_CreatesADirectoryToTheNewVersion()
        {
            appPublisher.Publish(sourceDir, destinationDir, "1.0.0");

            bool directoryExists = Directory.Exists(Path.Combine(destinationDir, "1.0.0"));
            Assert.That(directoryExists, Is.True);
        }

        [Test]
        public void Publish_WithValidInfo_CopiesTheFilesToTargetDir()
        {
            appPublisher.Publish(sourceDir, destinationDir, "1.1.0");

            Assert.That(File.Exists(Path.Combine(destinationDir, "1.1.0\\test1.txt")), Is.True);
            Assert.That(File.Exists(Path.Combine(destinationDir, "1.1.0\\another\\test2.txt")), Is.True);
        }

        [Test]
        public void Publish_WithValidInfo_GeneratesTheManifest()
        {
            string manifestFilename = Path.Combine(destinationDir, "1.1.0\\manifest.xml");

            appPublisher.Publish(sourceDir, destinationDir, "1.1.0");

            Assert.That(File.Exists(manifestFilename), Is.True);
        }

        [Test]
        public void Publish_WithValidInfo_SetsTheManifestData()
        {
            string manifestFilename = Path.Combine(destinationDir, "1.1.0\\manifest.xml");

            appPublisher.Publish(sourceDir, destinationDir, "1.1.0");

            VersionManifest manifest = VersionManifest.LoadVersionData("1.1.0", File.ReadAllText(manifestFilename));
            Assert.That(manifest.Files.Count(), Is.EqualTo(2));
            Assert.That(manifest.Files.ElementAt(0).Name, Is.EqualTo("test1.txt"));
            Assert.That(manifest.Files.ElementAt(1).Name, Is.EqualTo("another\\test2.txt"));<commit_msg>Testing the checksum and file size generated in the publisher<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using AppUpdater.Publisher;
using System.IO;
using AppUpdater.Manifest;
using System.Xml;

namespace AppUpdater.Tests.Publisher
{
    [TestFixture]
    public class AppPublisherTests
    {
        private AppPublisher appPublisher;
        private string sourceDir;
        private string destinationDir;

        [SetUp]
        public void Setup()
        {
            sourceDir = Path.GetTempFileName() + "_";
            destinationDir = Path.GetTempFileName() + "_";
            Directory.CreateDirectory(sourceDir);
            Directory.CreateDirectory(destinationDir);
            CreateVersionFiles();

            appPublisher = new AppPublisher();
        }

        [TearDown]
        public void TearDown()
        {
            Directory.Delete(sourceDir, true);
            Directory.Delete(destinationDir, true);
        }

        [Test]
        public void Publish_CreatesADirectoryToTheNewVersion()
        {
            appPublisher.Publish(sourceDir, destinationDir, "1.0.0");

            bool directoryExists = Directory.Exists(Path.Combine(destinationDir, "1.0.0"));
            Assert.That(directoryExists, Is.True);
        }

        [Test]
        public void Publish_WithValidInfo_CopiesTheFilesToTargetDir()
        {
            appPublisher.Publish(sourceDir, destinationDir, "1.1.0");

            Assert.That(File.Exists(Path.Combine(destinationDir, "1.1.0\\test1.txt")), Is.True);
            Assert.That(File.Exists(Path.Combine(destinationDir, "1.1.0\\another\\test2.txt")), Is.True);
        }

        [Test]
        public void Publish_WithValidInfo_GeneratesTheManifest()
        {
            string manifestFilename = Path.Combine(destinationDir, "1.1.0\\manifest.xml");

            appPublisher.Publish(sourceDir, destinationDir, "1.1.0");

            Assert.That(File.Exists(manifestFilename), Is.True);
        }

        [Test]
        public void Publish_WithValidInfo_SetsTheManifestData()
        {
            string manifestFilename = Path.Combine(destinationDir, "1.1.0\\manifest.xml");

            appPublisher.Publish(sourceDir, destinationDir, "1.1.0");

            VersionManifest manifest = VersionManifest.LoadVersionData("1.1.0", File.ReadAllText(manifestFilename));
            Assert.That(manifest.Files.Count(), Is.EqualTo(2));
            Assert.That(manifest.Files.ElementAt(0).Name, Is.EqualTo("test1.txt"));
            Assert.That(manifest.Files.ElementAt(0).Checksum, Is.EqualTo("B4EDFE85F28DA56CBF043E1FC1A43001F367700CCCB49DBC80F3EF455D3813DE"));
            Assert.That(manifest.Files.ElementAt(0).Size, Is.EqualTo(13));
            Assert.That(manifest.Files.ElementAt(1).Name, Is.EqualTo("another\\test2.txt"));
            Assert.That(manifest.Files.ElementAt(1).Checksum, Is.EqualTo("187B8EA2884ADA2F66FBB11CDC9B654BAFD8654471D6B35966BBCE4462AC5E66"));
            Assert.That(manifest.Files.ElementAt(1).Size, Is.EqualTo(13));
{'fraction_non_alphanumeric': 0.11574886004910558, 'fraction_numerical': 0.0270080673447913, 'mean_word_length': 2.6417624521072796, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1452353', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1627, 'n_words': 246}