public void CanCheckIfAppHasBeenPublished() { var fileSystemServiceMock = new Mock <IFileSystemService>(); const string solutionFolder = @"D:\Users\Alice\GraspNetCore"; const string releaseFolder = @"D:\Users\Alice\GraspNetCoreBin\Release"; const string publishFolder = @"D:\Users\Alice\GraspNetCoreBin\Publish"; var sut = new DvinApp { SolutionFolder = solutionFolder, ReleaseFolder = releaseFolder, PublishFolder = publishFolder }; fileSystemServiceMock.Setup(f => f.ListFilesInDirectory(It.IsAny <IFolder>(), It.IsAny <string>(), It.IsAny <SearchOption>())).Returns <IFolder, string, SearchOption>((f, _, _) => { return(new List <string> { f.FullName + @"\something.json" }); }); var now = DateTime.Now; fileSystemServiceMock.Setup(f => f.LastWriteTime(It.IsAny <string>())).Returns <string>(f => { return(f.StartsWith(publishFolder) ? now : now.AddMinutes(1)); }); Assert.IsFalse(sut.HasAppBeenPublishedAfterLatestSourceChanges(fileSystemServiceMock.Object)); fileSystemServiceMock.Setup(f => f.LastWriteTime(It.IsAny <string>())).Returns <string>(f => { return(f.StartsWith(publishFolder) || f.StartsWith(releaseFolder) ? now.AddMinutes(1) : now); }); Assert.IsTrue(sut.HasAppBeenPublishedAfterLatestSourceChanges(fileSystemServiceMock.Object)); }
public void CanValidatePubXml() { var fileSystemServiceMock = new Mock <IFileSystemService>(); const string solutionFolder = @"D:\Users\Alice\GraspNetCore"; const string publishFolder = @"D:\Users\Alice\GraspNetCoreBin\Publish"; var sut = new DvinApp { SolutionFolder = solutionFolder, PublishFolder = publishFolder }; fileSystemServiceMock.Setup(f => f.ListFilesInDirectory(It.IsAny <IFolder>(), It.IsAny <string>(), It.IsAny <SearchOption>())).Returns(new List <string>()); fileSystemServiceMock.Setup(f => f.FolderExists(It.IsAny <string>())).Returns(true); var errorsAndInfos = new ErrorsAndInfos(); sut.ValidatePubXml(fileSystemServiceMock.Object, errorsAndInfos); Assert.IsTrue(errorsAndInfos.Errors.Any(e => e.StartsWith("Found 0 pubxml files"))); errorsAndInfos = new ErrorsAndInfos(); fileSystemServiceMock.Setup(f => f.ListFilesInDirectory(It.IsAny <IFolder>(), It.IsAny <string>(), It.IsAny <SearchOption>())).Returns(new List <string> { "1", "2" }); sut.ValidatePubXml(fileSystemServiceMock.Object, errorsAndInfos); Assert.IsTrue(errorsAndInfos.Errors.Any(e => e.StartsWith("Found 2 pubxml files"))); errorsAndInfos = new ErrorsAndInfos(); fileSystemServiceMock.Setup(f => f.ListFilesInDirectory(It.IsAny <IFolder>(), It.IsAny <string>(), It.IsAny <SearchOption>())).Returns(new List <string> { solutionFolder + @"\Properties\publishProfile.pubxml" }); fileSystemServiceMock.Setup(f => f.ReadAllText(It.IsAny <string>())).Returns(ComposePubXml(null)); sut.ValidatePubXml(fileSystemServiceMock.Object, errorsAndInfos); Assert.IsTrue(errorsAndInfos.Errors.Any(e => e.StartsWith("publishUrl element not found"))); errorsAndInfos = new ErrorsAndInfos(); fileSystemServiceMock.Setup(f => f.ReadAllText(It.IsAny <string>())).Returns(ComposePubXml("abc")); sut.ValidatePubXml(fileSystemServiceMock.Object, errorsAndInfos); Assert.IsTrue(errorsAndInfos.Errors.Any(e => e.EndsWith("does not start with $(MSBuildThisFileDirectory)"))); errorsAndInfos = new ErrorsAndInfos(); fileSystemServiceMock.Setup(f => f.ReadAllText(It.IsAny <string>())).Returns(ComposePubXml("$(MSBuildThisFileDirectory)")); sut.ValidatePubXml(fileSystemServiceMock.Object, errorsAndInfos); Assert.IsTrue(errorsAndInfos.Errors.Any(e => e.Contains("should be $(MSBuildThisFileDirectory)"))); errorsAndInfos = new ErrorsAndInfos(); fileSystemServiceMock.Setup(f => f.ReadAllText(It.IsAny <string>())).Returns(ComposePubXml("$(MSBuildThisFileDirectory)..\\..\\GraspNetCoreBin\\Publish")); sut.ValidatePubXml(fileSystemServiceMock.Object, errorsAndInfos); Assert.IsFalse(errorsAndInfos.AnyErrors(), errorsAndInfos.ErrorsToString()); errorsAndInfos = new ErrorsAndInfos(); sut.ValidatePubXml(errorsAndInfos); Assert.IsTrue(errorsAndInfos.Errors.Any(e => e.StartsWith("Folder") && e.EndsWith("not found"))); }