Skip to content

Commit

Permalink
Fixes #32
Browse files Browse the repository at this point in the history
  • Loading branch information
hvanbakel committed Dec 3, 2017
1 parent b4acd40 commit 4a2ffae
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Project2015To2017/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ static void Main(string[] args)
return;
}

if (!File.Exists(args[0]))
var file = new FileInfo(args[0]);
if (!Validate(file))
{
Console.WriteLine($"File {args[0]} could not be found.");
return;
}

Expand Down Expand Up @@ -81,6 +81,23 @@ static void Main(string[] args)
new ProjectWriter().Write(projectDefinition, fileInfo);
}

internal static bool Validate(FileInfo file)
{
if (!file.Exists)
{
Console.WriteLine($"File {file.FullName} could not be found.");
return false;
}

if (file.IsReadOnly)
{
Console.WriteLine($"File {file.FullName} is readonly, please make the file writable first (checkout from source control?).");
return false;
}

return true;
}

private static bool SaveBackup(string filename)
{
var output = false;
Expand Down
26 changes: 26 additions & 0 deletions Project2015To2017Tests/ProgramTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Project2015To2017;

namespace Project2015To2017Tests
{
[TestClass]
public class ProgramTest
{
[TestMethod]
public void ValidatesFileIsWritable()
{
File.SetAttributes("TestFiles\\readonly.testcsproj", FileAttributes.ReadOnly);
Assert.IsFalse(Program.Validate(new FileInfo("TestFiles\\readonly.testcsproj")));
}

[TestMethod]
public void ValidatesFileExists()
{
Assert.IsFalse(Program.Validate(new FileInfo("TestFiles\\nonexistent.testcsproj")));
}
}
}
3 changes: 3 additions & 0 deletions Project2015To2017Tests/Project2015To2017Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<None Include="TestFiles\fileinclusion.testcsproj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestFiles\readonly.testcsproj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestFiles\unittest.testcsproj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
95 changes: 95 additions & 0 deletions Project2015To2017Tests/TestFiles/readonly.testcsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{62CAD5A7-4966-4289-9203-E6843CDEE4C6}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Net46Console</RootNamespace>
<AssemblyName>Net46Console</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Owin, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.3.1.0\lib\net45\Microsoft.Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin.Host.SystemWeb, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.3.1.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="6.1.1">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Include="Class1.cs" />
<Compile Include="Program.cs" />
<Compile Include="..\FileTransformationTest.cs" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SomeOtherProject\SomeOtherProject.csproj">
<Project>{E5D98CC4-93A3-450D-B33E-F9CAD02BBD8C}</Project>
<Name>SomeOtherProject</Name>
<Aliases>global,one</Aliases>
</ProjectReference>
<ProjectReference Include="..\YetAnotherProject\YetAnotherProject.csproj">
<Project>{E5D98CC5-93A3-450D-B33E-F9CAD02BBD8C}</Project>
<Name>YetAnotherProject</Name>
<Aliases>global</Aliases>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

0 comments on commit 4a2ffae

Please sign in to comment.