Пример #1
0
        public void Constructors()
        {
            var log = LogManager.GetLogger(typeof(TaskContextTest));
            var data = new Dictionary<string, object>();
            var fileSystem = new FileSystem();

            var context = new TaskContext(log);
            Assert.NotNull(context.Log);
            Assert.NotNull(context.FileSystem);
            Assert.NotNull(context.Data);
            Assert.AreEqual(log,context.Log);
            
            context = new TaskContext(log,data);
            Assert.NotNull(context.Log);
            Assert.NotNull(context.FileSystem);
            Assert.NotNull(context.Data);
            Assert.AreEqual(log,context.Log);
            Assert.AreEqual(data,context.Data);

            context = new TaskContext(log,fileSystem);
            Assert.NotNull(context.Log);
            Assert.NotNull(context.FileSystem);
            Assert.NotNull(context.Data);
            Assert.AreEqual(log,context.Log);
            Assert.AreEqual(fileSystem,context.FileSystem);

            context = new TaskContext(log,fileSystem,data);
            Assert.NotNull(context.Log);
            Assert.NotNull(context.FileSystem);
            Assert.NotNull(context.Data);
            Assert.AreEqual(log,context.Log);
            Assert.AreEqual(fileSystem,context.FileSystem);
            Assert.AreEqual(data,context.Data);
        }
        public void Run()
        {
            var data = new Dictionary<string, object>
                           {
                               { "CurrentVersion", new Version("3.0.0.0") },
                               {"Mode","release"}
                           };
            var badData = new Dictionary<string, object>
                              {
                                  { "CurrentVersion", new Exception("Lol") },
                                   {"Mode","release"}
                              };
            var log = LogManager.GetLogger(typeof(IncrementVersionNumberTask));

            var context = new TaskContext(log, data);

            var incTask = new IncrementVersionNumberTask();

            // -- RELEASE --
            // Good run
            
            Assert.DoesNotThrow(()=>incTask.Run(this,context));
            Assert.Contains("CurrentVersion",(ICollection)context.Data.Keys);
            Assert.Contains("NewVersion",(ICollection)context.Data.Keys);
            Assert.AreEqual(new Version(3,0,0,0),context.Data["CurrentVersion"]);
            Assert.AreEqual(new Version(3,0,1,0),context.Data["NewVersion"]);

            // Try no input version
            context = new TaskContext(log,new Dictionary<string, object>());
            Assert.Throws<KeyNotFoundException>(() => incTask.Run(this, context));

            // Try bad version number
            context = new TaskContext(log,badData);
            Assert.Throws<NullReferenceException>(() => incTask.Run(this, context));


            // -- TEST --
            // Good run
            context = new TaskContext(log,data);
            context.Data["Mode"] = "test";

            Assert.DoesNotThrow(()=>incTask.Run(this,context));
            Assert.Contains("CurrentVersion",(ICollection)context.Data.Keys);
            Assert.Contains("NewVersion",(ICollection)context.Data.Keys);
            Assert.AreEqual(new Version(3,0,0,0),context.Data["CurrentVersion"]);
            Assert.AreEqual(new Version(3,0,0,1),context.Data["NewVersion"]);

            // Try no input version
            context = new TaskContext(log,new Dictionary<string, object>());
            Assert.Throws<KeyNotFoundException>(() => incTask.Run(this, context));

            // Try bad version number
            context = new TaskContext(log,badData);
            context.Data["Mode"] = "test";
            Assert.Throws<NullReferenceException>(() => incTask.Run(this, context));
        }
Пример #3
0
        public void Run()
        {
            var data = new Dictionary<string, object>
                           {
                               { "WorkingDirectory", "c:\\face" },
                               {
                                   "CurrentVersionFileRelativePath",
                                   "\\brains\\neck\\CurrentVersion.txt"
                               }
                           };
            var fileSystem = A.Fake<IFileSystem>();
            var log = LogManager.GetLogger(typeof(GetVersion));

            // Do ideal pass

            A.CallTo(()=>fileSystem.File.ReadAllText(A<string>.Ignored)).Returns("3.0.0.0");
            var getVersion = A.Fake<GetVersion>(x=>x.Wrapping(new GetVersion()));
            var context = new TaskContext(log, fileSystem, data);

            A.CallTo(() => getVersion.ParseVersion(A<string>.Ignored)).Returns(new Version(3, 0, 0, 0));
            Assert.DoesNotThrow(()=>getVersion.Run(this,context));
            A.CallTo(() => fileSystem.Path.Combine(context.Data["WorkingDirectory"] as string, context.Data["CurrentVersionFileRelativePath"] as string)).MustHaveHappened(Repeated.Exactly.Once);

            Assert.Contains("CurrentVersion",(ICollection)context.Data.Keys);
            Assert.NotNull(context.Data["CurrentVersion"] as Version);
            Assert.AreEqual(new Version("3.0.0.0"), context.Data["CurrentVersion"] as Version);

            // Make sure it throws an exception if the file doesn't exist.
            A.CallTo(() => fileSystem.File.ReadAllText(A<string>.Ignored)).Throws<System.IO.FileNotFoundException>();

            Assert.Throws<System.IO.FileNotFoundException>(() => getVersion.Run(this, context));

            // Make sure a bad version throws an exception
            A.CallTo(() => fileSystem.File.ReadAllText(A<string>.Ignored)).Returns("OMG LOL NOT A VERSION");
            A.CallTo(() => getVersion.ParseVersion(A<string>.Ignored)).CallsBaseMethod();
            Assert.Throws<ArgumentException>(() => getVersion.Run(this, context));
        }