예제 #1
0
    void Ex01()
    {
        var           fixture            = TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod");
        FixtureResult?fixtureReadyResult = default;

        fixture.FixtureReady += (_, e) => fixtureReadyResult = e.Result;
        ((FixtureContainer)Container).Add(fixture);

        FixtureResult?containerReadyResult = default;

        Container.FixtureReady += (_, e) => containerReadyResult = e.Result;

        Container.Ready();

        Expect("FixtureReady event should be raised", () => containerReadyResult != null);

        ExpectedContainerFixtureDescription = FixtureDescriptorAssertion.Of("Simple Fixture", "SimpleFixture", "Carna.TestFixtures+SimpleFixture", typeof(ContextAttribute));
        Expect($"the descriptor of the result should be as follows:{ExpectedContainerFixtureDescription.ToDescription()}", () => containerReadyResult != null && FixtureDescriptorAssertion.Of(containerReadyResult.FixtureDescriptor) == ExpectedContainerFixtureDescription);
        ExpectedContainerFixtureResult = FixtureResultAssertion.ForNullException(false, false, false, 0, 0, FixtureStatus.Ready);
        Expect($"the result should be as follows:{ExpectedContainerFixtureResult.ToDescription()}", () => containerReadyResult != null && FixtureResultAssertion.Of(containerReadyResult) == ExpectedContainerFixtureResult);

        Expect("FixtureReady event of the inner fixture should be raised", () => fixtureReadyResult != null);

        ExpectedFixtureDescription = FixtureDescriptorAssertion.Of("Fixture Method Example", "FixtureMethod", "Carna.TestFixtures+SimpleFixture.FixtureMethod", typeof(ExampleAttribute));
        Expect($"the description of the result of the inner fixture should be as follows:{ExpectedFixtureDescription.ToDescription()}", () => fixtureReadyResult != null && FixtureDescriptorAssertion.Of(fixtureReadyResult.FixtureDescriptor) == ExpectedFixtureDescription);
        ExpectedFixtureResult = FixtureResultAssertion.ForNullException(false, false, false, 0, 0, FixtureStatus.Ready);
        Expect($"the result of the inner fixture should be as follows:{ExpectedFixtureResult.ToDescription()}", () => fixtureReadyResult != null && FixtureResultAssertion.Of(fixtureReadyResult) == ExpectedFixtureResult);
    }
    void Ex02()
    {
        var fixture = TestFixtures.CreateFixture <TestFixtures.MethodFixtureSpecifiedBySomeAroundFixtureAttributes>("Ex01");

        fixture.Run(null, Substitute.For <IFixtureStepRunnerFactory>());
        Assert(3);
    }
    void Ex09()
    {
        var fixture = TestFixtures.CreateFixtureWithContainer <TestFixtures.MethodFixtureThatRequiresSta>("Ex01");
        var result  = fixture.Run(null, new FixtureStepRunnerFactory());

        Expect("the status of the result should be Passed", () => result != null && result.Status == FixtureStatus.Passed);
    }
 /// <summary>
 ///     Creates a new instance of TestFixtureStubHelper.
 /// </summary>
 public TestFixtureStubHelper()
 {
     TestFixtures.Add(new TestFixtureStubOne());
     TestFixtures.Add(new TestFixtureStubTwo());
     TestFixtures.Add(new TestFixtureStubThree());
     TestFixtures.Add(new TestFixtureStubFour());
 }
예제 #5
0
    public void Unarchive()
    {
        var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath);

        unarchiver.Unarchive(CancellationToken.Empty);

        CheckConsistency(TestFixtures.GetDirectoryPath("unarchiver-test/zip"), _dirPath);
    }
예제 #6
0
        void Ex01()
        {
            Fixture = TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod");
            Container.Add(Fixture);

            ParentContainer.EnsureParent();

            Expect("the parent of the added fixture is set to the parent fixture container", () => Fixture.ParentFixture == ParentContainer);
        }
예제 #7
0
    public void UnarchiveWithPassword()
    {
        string password = "******" + "123==";

        var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/password-zip.zip"), _dirPath, password);

        unarchiver.Unarchive(CancellationToken.Empty);

        CheckConsistency(TestFixtures.GetDirectoryPath("unarchiver-test/password-zip"), _dirPath);
    }
예제 #8
0
    public void CancelUnarchive()
    {
        var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath);

        CancellationTokenSource source = new CancellationTokenSource();

        source.Cancel();

        Assert.Catch <OperationCanceledException>(() => unarchiver.Unarchive(source));
    }
    void Ex07()
    {
        TestAroundFixtureAttribute.OnFixtureRunningCount.Value = 0;
        TestAroundFixtureAttribute.OnFixtureRunCount.Value     = 0;

        var fixture = TestFixtures.CreateFixtureWithContainer <TestFixtures.FixtureSpecifiedBySomeAroundFixtureAttributes>("Ex01");

        fixture.Run(null, new FixtureStepRunnerFactory());
        Assert(3);
    }
예제 #10
0
    void Ex04()
    {
        ((FixtureContainer)Container).AddRange(new[] {
            TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod"),
            TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod"),
            TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod")
        });

        Filter.Accept(Arg.Any <FixtureDescriptor>()).Returns(x => x.Arg <FixtureDescriptor>().Name != "FixtureMethod");

        Expect("the result should be true", () => Container.CanRun(Filter) == true);
    }
예제 #11
0
    void Ex05()
    {
        ((FixtureContainer)Container).AddRange(new[] {
            TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod"),
            TestFixtures.CreateFixture <TestFixtures.SimpleDisposableFixture>("FixtureMethod"),
            TestFixtures.CreateFixture <TestFixtures.SimpleFixtureSteppable>("FixtureMethod")
        });

        Filter.Accept(Arg.Any <FixtureDescriptor>()).Returns(x => x.Arg <FixtureDescriptor>().FullName == "Carna.TestFixtures+SimpleDisposableFixture.FixtureMethod");

        Expect("the result should be true", () => Container.CanRun(Filter) == true);
    }
예제 #12
0
    public void ProgressReporting()
    {
        var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath);

        int?lastAmount = null;
        int?lastEntry  = null;

        unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount, entryProgress) =>
        {
            if (!lastAmount.HasValue)
            {
                lastAmount = amount;
            }
            else
            {
                Assert.That(amount, Is.EqualTo(lastAmount.Value));
            }

            if (lastEntry.HasValue)
            {
                Assert.That(entry, Is.GreaterThanOrEqualTo(lastEntry.Value));
            }

            lastEntry = entry;

            Assert.That(entry, Is.GreaterThan(0));

            if (entryProgress == 1.0)
            {
                if (isFile)
                {
                    string filePath = Path.Combine(_dirPath, name);
                    Assert.That(File.Exists(filePath));
                }
                else
                {
                    string dirPath = Path.Combine(_dirPath, name);
                    Assert.That(Directory.Exists(dirPath));
                }
            }

            Assert.That(entryProgress, Is.GreaterThanOrEqualTo(0.0));
            Assert.That(entryProgress, Is.LessThanOrEqualTo(1.0));
        };

        unarchiver.Unarchive(CancellationToken.Empty);

        Assert.That(lastAmount, Is.Not.Null);
        Assert.That(lastEntry, Is.Not.Null);
        Assert.That(lastEntry.Value, Is.EqualTo(lastAmount.Value));
    }
        IEnumerable ISampleDataSource.GetData()
        {
            yield return(new
            {
                Description = "When a class requires a single thread apartment",
                Fixture = TestFixtures.CreateFixture <TestFixtures.FixtureThatRequiresSta>("Ex01")
            });

            yield return(new
            {
                Description = "When a method requires a single thread apartment",
                Fixture = TestFixtures.CreateFixture <TestFixtures.MethodFixtureThatRequiresSta>("Ex01")
            });
        }
예제 #14
0
        void Ex03()
        {
            var fixtures = new[] {
                TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod"),
                TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod"),
                TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod")
            };

            Container.AddRange(fixtures);

            ParentContainer.EnsureParent();

            Expect("the parent of each added fixture is set to the parent fixture container.", () => fixtures.All(f => f.ParentFixture == ParentContainer));
        }
예제 #15
0
    protected FixtureSpec_NormalFixtureContext()
    {
        Fixture = TestFixtures.CreateFixture(TargetFixtureType, TargetMethodName);

        Fixture.FixtureRunning     += (s, e) => FixtureRunningResult = e.Result;
        Fixture.FixtureRun         += (s, e) => FixtureRunResult = e.Result;
        Fixture.FixtureStepRunning += (s, e) => FixtureStepRunningResult = e.Result;
        Fixture.FixtureStepRun     += (s, e) => FixtureStepRunResult = e.Result;

        Filter = Substitute.For <IFixtureFilter>();

        TestFixtures.RaiseException = false;
        TestFixtures.CalledFixtureMethods.Clear();
    }
예제 #16
0
        public void ShouldDoInverseMapForValues()
        {
            // Arrange
            var testData = TestFixtures.GetTestDataForByteArrays();

            foreach (var testCase in testData)
            {
                // Act
                var r        = _mapper.Map(testCase.Input);
                var rInverse = _mapper.ReverseMap(r);

                // Assert
                Assert.True(Enumerable.SequenceEqual(testCase.Input, rInverse));
            }
        }
예제 #17
0
        public void ShouldDoInverseMapForValues()
        {
            // Arrange
            var testData = TestFixtures.GetTestDataForString();

            foreach (var test in testData)
            {
                // Act
                var r        = _mapper.Map(test.Input);
                var rInverse = _mapper.ReverseMap(r);

                // Assert
                Assert.Equal(test.Input, rInverse);
            }
        }
    public void ProgressReporting()
    {
        var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath);

        int?lastAmount = null;
        int?lastEntry  = null;

        unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount, entryProgress) =>
        {
            if (!lastAmount.HasValue)
            {
                lastAmount = amount;
            }
            Assert.AreEqual(lastAmount, amount, "Amount of extracted files cannot change during the operation.");

            if (lastEntry.HasValue)
            {
                Assert.AreEqual(lastEntry + 1, entry, "Entries are not following each other.");
            }

            lastEntry = entry;

            if (entry == 0)
            {
                Assert.IsNull(name);
                Assert.AreEqual(0.0, entryProgress);
            }
            else if (isFile)
            {
                string filePath = Path.Combine(_dirPath, name);
                Assert.IsTrue(File.Exists(filePath), string.Format("File doesn't exist - {0}", filePath));
            }
            else
            {
                string dirPath = Path.Combine(_dirPath, name);
                Assert.IsTrue(Directory.Exists(dirPath), string.Format("Directory doesn't exist - {0}", dirPath));
            }

            Assert.GreaterOrEqual(entryProgress, 0.0);
            Assert.LessOrEqual(entryProgress, 1.0);
        };

        unarchiver.Unarchive(CancellationToken.Empty);

        Assert.IsNotNull(lastAmount);
        Assert.IsNotNull(lastEntry);
        Assert.AreEqual(lastAmount, lastEntry, "Last entry must be equal to amount.");
    }
    public FixtureContainerSpec_RunFixtures()
    {
        Container = new FixtureContainer(typeof(TestFixtures.SimpleFixture));

        Container.FixtureRunning += (_, e) => FixtureRunningResult = e.Result;
        Container.FixtureRun     += (_, e) => FixtureRunResult = e.Result;

        ((FixtureContainer)Container).AddRange(new[] {
            TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod"),
            TestFixtures.CreateFixture <TestFixtures.SimpleDisposableFixture>("FixtureMethod"),
            TestFixtures.CreateFixture <TestFixtures.SimpleFixtureSteppable>("FixtureMethod")
        });

        Filter = Substitute.For <IFixtureFilter>();

        TestFixtures.CalledFixtureMethods.Clear();
    }
예제 #20
0
        public void ShouldRepeatedlyMapSameValuesToSameInputs()
        {
            // Arrange
            var testCases = TestFixtures.GetTestDataForString();

            foreach (var testCase in testCases)
            {
                for (int i = 0; i < 3; i++)
                {
                    // Act
                    var r = _mapper.Map(testCase.Input);

                    // Assert
                    Assert.Equal(testCase.ExpectedOutput, r);
                }
            }
            Assert.Equal(testCases.Length + 1, (int)_mapper.MappedObjectsCount);
        }
    public void FindLinuxApp()
    {
        var platformResolver = Substitute.For <PlatformResolver>();

        platformResolver.GetRuntimePlatform().Returns(RuntimePlatform.LinuxPlayer);

        // empty directory should be ignored
        Directory.CreateDirectory(Path.Combine(_tempDir, "directory"));

        // copy linux app
        string source = TestFixtures.GetFilePath("magicbytes-test/linux_app");
        string dest   = Path.Combine(_tempDir, "executable");

        File.Copy(source, dest);

        var    appFinder  = new AppFinder();
        string executable = appFinder.FindLinuxExecutable(_tempDir);

        Assert.AreEqual(dest, executable);
    }
예제 #22
0
    public void Unpack()
    {
        string    archivePath = TestFixtures.GetFilePath("pack1/test.pack1");
        string    metaPath    = TestFixtures.GetFilePath("pack1/test.pack1.meta");
        string    metaString  = File.ReadAllText(metaPath);
        Pack1Meta meta        = Pack1Meta.Parse(metaString);

        var pack1Unarchiver = new Pack1Unarchiver(archivePath, meta, _tempDir, Key);

        pack1Unarchiver.Unarchive(new CancellationToken());

        Assert.True(Directory.Exists(Path.Combine(_tempDir, "dir")));

        var rakefile = Path.Combine(_tempDir, "dir/Rakefile");

        Assert.True(File.Exists(rakefile));
        Assert.AreEqual("d2974b45f816b3ddaca7a984a9101707", Md5File(rakefile));

        var rubocopFile = Path.Combine(_tempDir, ".rubocop.yml");

        Assert.True(File.Exists(rubocopFile));
        Assert.AreEqual("379cc2261c048e4763969cca74974237", Md5File(rubocopFile));
    }
예제 #23
0
 public void SetUp()
 {
     _macApp     = TestFixtures.GetFilePath("magicbytes-test/mac_app");
     _windowsApp = TestFixtures.GetFilePath("magicbytes-test/windows_app");
     _linuxApp   = TestFixtures.GetFilePath("magicbytes-test/linux_app");
 }
예제 #24
0
    public void UnarchiveCorruptedArchive()
    {
        var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/corrupted-zip.zip"), _dirPath);

        Assert.Catch <Exception>(() => unarchiver.Unarchive(CancellationToken.Empty));
    }
예제 #25
0
 public FixtureSpec_CanRun()
 {
     Fixture = TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod");
     Filter  = Substitute.For <IFixtureFilter>();
 }
예제 #26
0
 public FixtureSpec_Ready()
 {
     Fixture = TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod");
 }