public void ProcessFile() { var fileSystem = A.Fake <IFileSystem>(); A.CallTo(() => fileSystem.Path).Returns(A.Fake <PathBase>(x => x.Wrapping(new PathWrapper()))); var context = A.Fake <ITaskContext>(x => x.Wrapping(new TaskContext(A.Fake <ILog>(), fileSystem))); var task = new IncrementVersionNumbersInFiles(); const string CurrentVersion = "3.0.0.0"; const string CurrentReleaseVersion = "3.0.0.0"; const string CurrentTestVersion = "3.0.0.0"; const string NewVersion = "3.0.0.1"; const string NoVersion = "asldkfjaw faowkjef awoeijf a;sodkfjaw oeifjaw\nfawo\teifj\tawoef"; //const string NoVersionResult = NoVersion; const string HasVersion = "falskdjfawoeka wef\n\r\n\tlaskdjfaoweifjaw awoiefjaw" + CurrentVersion + "fjowiejf\n"; var HasVersionResult = HasVersion.Replace(CurrentVersion, NewVersion); var passFile = A.Fake <FileInfoBase>(); context.Data["WorkingDirectory"] = "c:\\asdf\\"; context.Data["Mode"] = "test"; A.CallTo(() => passFile.FullName).Returns(task.GetUpdateFiles(context).First()); var a = task.GetUpdateFiles(context).First(); Debug.WriteLine(a); A.CallTo(() => passFile.Name).Returns(new FileInfo(task.GetUpdateFiles(context).First()).Name); var fileContents = ""; A.CallTo(() => fileSystem.File.WriteAllText(A <string> .Ignored, A <string> .Ignored)) .Invokes(new Action <string, string>((s, s1) => fileContents = s1)); // has version fileContents = ""; A.CallTo(() => fileSystem.File.ReadAllText(A <string> .Ignored)).Returns(HasVersion); Assert.DoesNotThrow(() => task.ProcessFile(context, passFile, CurrentVersion, CurrentReleaseVersion, CurrentTestVersion, NewVersion)); A.CallTo(() => fileSystem.File.WriteAllText(A <string> .Ignored, A <string> .Ignored)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => fileSystem.File.ReadAllText(A <string> .Ignored)).MustHaveHappened(Repeated.Exactly.Once); Assert.AreEqual(HasVersionResult, fileContents); // no version fileContents = ""; A.CallTo(() => fileSystem.File.ReadAllText(A <string> .Ignored)).Returns(NoVersion); Assert.DoesNotThrow(() => task.ProcessFile(context, passFile, CurrentVersion, CurrentReleaseVersion, CurrentTestVersion, NewVersion)); A.CallTo(() => fileSystem.File.WriteAllText(A <string> .Ignored, A <string> .Ignored)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => fileSystem.File.ReadAllText(A <string> .Ignored)).MustHaveHappened(Repeated.Exactly.Times(2)); Assert.AreEqual("", fileContents); }
public void SkipTest() { var config = DomainConfigurationFactory.Create(); config.Types.Register(typeof(Base)); config.Types.Register(typeof(Skip)); config.Types.Register(typeof(VersionBehavior.Model.Version)); config.Types.Register(typeof(HasVersion)); config.Types.Register(typeof(HasSkipVersion)); var domain = Domain.Build(config); var skipTypeInfo = domain.Model.Types[typeof(Skip)]; var hasVersionTypeInfo = domain.Model.Types[typeof(HasVersion)]; var hasSkipVersionTypeInfo = domain.Model.Types[typeof(HasSkipVersion)]; Assert.AreEqual(2, skipTypeInfo.GetVersionColumns().Count); Assert.AreEqual(2, hasVersionTypeInfo.GetVersionColumns().Count); Assert.AreEqual(2, hasSkipVersionTypeInfo.GetVersionColumns().Count); using (var session = domain.OpenSession()) { var versions = new VersionSet(); var updatedVersions = new VersionSet(); Skip skip; HasVersion hasVersion; using (VersionCapturer.Attach(session, versions)) using (var t = session.OpenTransaction()) { skip = new Skip() { Content = "Content", Tag = "Tag", Description = "Desription", NotVersion = "NotVersion" }; hasVersion = new HasVersion { Content = "Content", Tag = "Tag", Version = { Major = 10, Minor = 100, Meta = 1000 } }; t.Complete(); } using (VersionCapturer.Attach(session, updatedVersions)) using (VersionValidator.Attach(session, versions)) using (var t = session.OpenTransaction()) { skip.Content = "AnotherContent"; skip.Content = "AnotherContetnCorrect"; hasVersion.Content = "AnotherContent"; hasVersion.Content = "AnotherContetnCorrect"; t.Complete(); } AssertEx.Throws <VersionConflictException>(() => { using (VersionValidator.Attach(session, versions)) using (var t = session.OpenTransaction()) { skip.Tag = "AnotherTag"; hasVersion.Tag = "AnotherTag"; t.Complete(); } }); using (VersionValidator.Attach(session, updatedVersions)) using (var t = session.OpenTransaction()) { skip.Tag = "AnotherTag"; hasVersion.Tag = "AnotherTag"; t.Complete(); } } var allVersions = new VersionSet(); using (var session = domain.OpenSession()) using (VersionCapturer.Attach(session, allVersions)) using (VersionValidator.Attach(session, allVersions)) { Skip skip; HasVersion hasVersion; using (var t = session.OpenTransaction()) { skip = new Skip() { Content = "Content", Tag = "Tag", Description = "Desription", NotVersion = "NotVersion" }; hasVersion = new HasVersion { Content = "Content", Tag = "Tag", Version = { Major = 10, Minor = 100, Meta = 1000 } }; t.Complete(); } using (var t = session.OpenTransaction()) { skip.Content = "AnotherContent"; skip.Content = "AnotherContetnCorrect"; hasVersion.Content = "AnotherContent"; hasVersion.Content = "AnotherContetnCorrect"; t.Complete(); } using (var t = session.OpenTransaction()) { skip.Tag = "AnotherTag"; hasVersion.Tag = "AnotherTag"; t.Complete(); } } }