コード例 #1
0
        public void Construct_ShouldAddMenuItemsProvidedBy_KataPracticeMenuItemProvider()
        {
            //---------------Set up test pack-------------------
            var provider      = Substitute.For <IKataPracticeMenuItemProvider>();
            var kataArchive   = Substitute.For <IKataArchive>();
            var commandHelper = Substitute.For <ICommandHelper>();
            var expected      = RandomValueGen.GetRandomCollection(() => new MenuItem()
            {
                Header  = RandomValueGen.GetRandomString(),
                Command = new GenerateAndLaunchKataCommand(
                    RandomValueGen.GetRandomEnum <KataName>(),
                    kataArchive,
                    commandHelper,
                    Substitute.For <IEventAggregator>())
            }, 1, 2).ToArray();

            provider.GetKataPracticeMenuItems().Returns(expected);
            var sut = Create(kataPracticeMenuItemProvider: provider);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var result = sut.MenuItems;

            //---------------Test Result -----------------------
            var kataItems = result.OfType <MenuItem>().Where(m => m.Command is GenerateAndLaunchKataCommand).ToArray();

            CollectionAssert.AreEqual(expected, kataItems);
        }
コード例 #2
0
        public void IncrementVersionsUnder_ShouldIncrementVersionWithAllUtils()
        {
            //---------------Set up test pack-------------------
            var finder  = Substitute.For <INuspecFinder>();
            var factory = Substitute.For <INuspecUtilFactory>();
            var utils   = new List <INuspecUtil>();

            factory.LoadNuspecAt(Arg.Any <string>())
            .Returns(ci =>
            {
                var util = Substitute.For <INuspecUtil>();
                utils.Add(util);
                return(util);
            });
            var path1       = RandomValueGen.GetRandomString();
            var nuspecPaths = RandomValueGen.GetRandomCollection <string>(3, 5);

            finder.NuspecPaths.Returns(nuspecPaths);
            var sut = Create(finder, factory);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            sut.IncrementVersionsUnder(path1);

            //---------------Test Result -----------------------
            nuspecPaths.ForEach(p => factory.Received().LoadNuspecAt(p));
            utils.ForEach(p => p.Received().IncrementVersion());
        }
コード例 #3
0
        public void Dispose_ShouldDisposeUnderlyingReader_AndSubsequentCallsToReadLine_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            using (var tempFile = new AutoTempFile())
            {
                File.WriteAllLines(tempFile.Path, RandomValueGen.GetRandomCollection <string>(2, 2).ToArray());
                var sut = Create(tempFile.Path);
                //---------------Assert Precondition----------------

                //---------------Execute Test ----------------------
                sut.Dispose();
                var result = sut.ReadLine();

                //---------------Test Result -----------------------
                Assert.IsNull(result);
            }
        }
コード例 #4
0
        public void IncrementVersionsUnder_ShouldCreateOneNuspecUtilPerFoundNuspecPath()
        {
            //---------------Set up test pack-------------------
            var finder      = Substitute.For <INuspecFinder>();
            var factory     = Substitute.For <INuspecUtilFactory>();
            var path1       = RandomValueGen.GetRandomString();
            var nuspecPaths = RandomValueGen.GetRandomCollection <string>(3, 5);

            finder.NuspecPaths.Returns(nuspecPaths);
            var sut = Create(finder, factory);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            sut.IncrementVersionsUnder(path1);

            //---------------Test Result -----------------------
            nuspecPaths.ForEach(p => factory.Received().LoadNuspecAt(p));
        }
コード例 #5
0
        public void Open_ShouldReturnReaderForProvidedFilePath()
        {
            //---------------Set up test pack-------------------
            using (var tempFile = new AutoTempFile())
            {
                var lines = RandomValueGen.GetRandomCollection <string>(3, 5);
                File.WriteAllBytes(tempFile.Path, lines.JoinWith("\n").AsBytes());
                var sut = Create();

                //---------------Assert Precondition----------------
                CollectionAssert.AreEqual(lines.JoinWith("\n").AsBytes(), File.ReadAllBytes(tempFile.Path));

                //---------------Execute Test ----------------------
                var newLines = RandomValueGen.GetRandomCollection <string>(4, 6);
                var writer   = sut.Open(tempFile.Path);
                newLines.ForEach(writer.AppendLine);
                writer.Persist();

                //---------------Test Result -----------------------
                var linesOnDisk = File.ReadAllBytes(tempFile.Path).ToUTF8String().Split(new[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
                CollectionAssert.AreEqual(linesOnDisk, newLines);
            }
        }
コード例 #6
0
        public void ReadLine_ShouldReadOneLineFromTheFile()
        {
            //---------------Set up test pack-------------------
            using (var tempFile = new AutoTempFile())
            {
                var lines        = RandomValueGen.GetRandomCollection <string>(3, 3);
                var linesAsBytes = Encoding.UTF8.GetBytes(string.Join(Environment.NewLine, lines));
                File.WriteAllBytes(tempFile.Path, linesAsBytes);
                var sut = Create(tempFile.Path);
                //---------------Assert Precondition----------------
                // pedantic? sure!
                CollectionAssert.AreEqual(linesAsBytes, File.ReadAllBytes(tempFile.Path));

                //---------------Execute Test ----------------------
                var result1 = sut.ReadLine();
                var result2 = sut.ReadLine();
                var result3 = sut.ReadLine();

                //---------------Test Result -----------------------
                Assert.AreEqual(lines.First(), result1);
                Assert.AreEqual(lines.Skip(1).First(), result2);
                Assert.AreEqual(lines.Skip(2).First(), result3);
            }
        }
コード例 #7
0
 private static string GetRandomVersionString()
 {
     return(string.Join(".", RandomValueGen.GetRandomCollection <int>(3, 3)));
 }
コード例 #8
0
 private string CreateRandomVersion()
 {
     return(string.Join(".", RandomValueGen.GetRandomCollection <int>(3, 3)));
 }