Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/source/TodoList.ConsoleApp/bin/Debug/netcoreapp2.2/todo.dll",
"args": ["i"],
"args": ["dm"],
"cwd": "${workspaceFolder}/source/TodoList.ConsoleApp",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "integratedTerminal",
Expand Down
15 changes: 15 additions & 0 deletions TodoList.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoList.Infrastructure", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoList.IntegrationTests", "tests\TodoList.IntegrationTests\TodoList.IntegrationTests.csproj", "{0A9077E0-1B39-4F02-A3F0-54A3680A7056}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoList.AcceptanceTests", "tests\TodoList.AcceptanceTests\TodoList.AcceptanceTests.csproj", "{AC22743B-52E2-49A0-9C79-09E67009F872}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -104,6 +106,18 @@ Global
{0A9077E0-1B39-4F02-A3F0-54A3680A7056}.Release|x64.Build.0 = Release|Any CPU
{0A9077E0-1B39-4F02-A3F0-54A3680A7056}.Release|x86.ActiveCfg = Release|Any CPU
{0A9077E0-1B39-4F02-A3F0-54A3680A7056}.Release|x86.Build.0 = Release|Any CPU
{AC22743B-52E2-49A0-9C79-09E67009F872}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC22743B-52E2-49A0-9C79-09E67009F872}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC22743B-52E2-49A0-9C79-09E67009F872}.Debug|x64.ActiveCfg = Debug|Any CPU
{AC22743B-52E2-49A0-9C79-09E67009F872}.Debug|x64.Build.0 = Debug|Any CPU
{AC22743B-52E2-49A0-9C79-09E67009F872}.Debug|x86.ActiveCfg = Debug|Any CPU
{AC22743B-52E2-49A0-9C79-09E67009F872}.Debug|x86.Build.0 = Debug|Any CPU
{AC22743B-52E2-49A0-9C79-09E67009F872}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC22743B-52E2-49A0-9C79-09E67009F872}.Release|Any CPU.Build.0 = Release|Any CPU
{AC22743B-52E2-49A0-9C79-09E67009F872}.Release|x64.ActiveCfg = Release|Any CPU
{AC22743B-52E2-49A0-9C79-09E67009F872}.Release|x64.Build.0 = Release|Any CPU
{AC22743B-52E2-49A0-9C79-09E67009F872}.Release|x86.ActiveCfg = Release|Any CPU
{AC22743B-52E2-49A0-9C79-09E67009F872}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{96C25576-F135-4E24-B791-2C311335760C} = {29821818-FE38-42A7-BFDB-919FDE2CD2F8}
Expand All @@ -112,5 +126,6 @@ Global
{54FC9A81-37E4-4F7B-9E56-75FA0004E0CD} = {29821818-FE38-42A7-BFDB-919FDE2CD2F8}
{555C3909-D08A-4E08-9803-23CD51DF9A04} = {29821818-FE38-42A7-BFDB-919FDE2CD2F8}
{0A9077E0-1B39-4F02-A3F0-54A3680A7056} = {FC5F711A-336E-4310-84D2-5FEAE78F07CF}
{AC22743B-52E2-49A0-9C79-09E67009F872} = {FC5F711A-336E-4310-84D2-5FEAE78F07CF}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions source/TodoList.ConsoleApp/Commands/CommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public CommandParser()
{
commands = new ICommand[]
{
new DevelopmentModeCommand(),
new InteractiveCommand(),
new DoCommand(),
new HelpCommand(),
Expand Down
24 changes: 24 additions & 0 deletions source/TodoList.ConsoleApp/Commands/DevelopmentModeCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace TodoList.ConsoleApp.Commands
{
using System;
using TodoList.ConsoleApp.Controllers;

public sealed class DevelopmentModeCommand : ICommand
{
private readonly string[] Tokens = { "-dm", "/dm", "dm", "dev-mode", "--dev-mode" };

public void Execute(TodoItemsController controller)
{
controller.DevelopmentMode();
}

public bool Match(string[] args)
{
if (args.Length != 1)
return false;

bool match = CommandArgsParser.Match(args, Tokens);
return match;
}
}
}
16 changes: 16 additions & 0 deletions source/TodoList.ConsoleApp/Controllers/TodoItemsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,21 @@ private void SetGistIdSettings(string gistId)
contents = JsonConvert.SerializeObject(configuration, Formatting.Indented);
File.WriteAllText(appsettingsPath, contents);
}

public void DevelopmentMode()
{
var appsettingsPath = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location) +
Path.DirectorySeparatorChar +
"appsettings.json";

var contents = File.ReadAllText(appsettingsPath);
var configuration = JsonConvert.DeserializeObject<JObject>(contents);

configuration["Environment"] = "Development";

contents = JsonConvert.SerializeObject(configuration, Formatting.Indented);
File.WriteAllText(appsettingsPath, contents);
}
}
}
32 changes: 18 additions & 14 deletions source/TodoList.Infrastructure/GistGateway/GistItemGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@ namespace TodoList.Infrastructure.GistGateway

public sealed class GistItemGateway : IItemGateway
{
private GitHubClient _githubClient;
private string _gistToken;
private string _gistId;
private static GitHubClient _gitHubClient;

private void CreateGitHubConnection()
private GitHubClient GitHubClient
{
_githubClient = new GitHubClient(new ProductHeaderValue("todo"));
_githubClient.Credentials = new Credentials(_gistToken);
get
{
if (_gitHubClient != null)
return _gitHubClient;

_gitHubClient = new GitHubClient(new ProductHeaderValue("todo"));
_gitHubClient.Credentials = new Credentials(_gistToken);

return _gitHubClient;
}
}

private string _gistToken;
private string _gistId;

private List<Item> EnsureItemsAreLoaded()
{
if (string.IsNullOrWhiteSpace(_gistId))
Expand All @@ -51,7 +60,7 @@ private List<Item> EnsureItemsAreLoaded()

private Gist LoadGist()
{
var gist = _githubClient
var gist = GitHubClient
.Gist
.Get(_gistId).GetAwaiter()
.GetResult();
Expand All @@ -66,7 +75,7 @@ private Gist CreateGist(List<Item> items)
newGist.Description = "todolist";
newGist.Files.Add("todolist.json", jsonContents);

var gist = _githubClient.Gist
var gist = GitHubClient.Gist
.Create(newGist)
.GetAwaiter()
.GetResult();
Expand All @@ -87,7 +96,7 @@ private void UpdateGist(List<Item> items)
var gistUpdate = new GistUpdate();
gistUpdate.Description = "todolist";
gistUpdate.Files.Add("todolist.json", gistFileUpdate);
_githubClient.Gist
GitHubClient.Gist
.Edit(_gistId, gistUpdate)
.GetAwaiter()
.GetResult();
Expand Down Expand Up @@ -135,7 +144,6 @@ private void WriteGistIdToAppSettings()
public void Add(IItem item)
{
ReadGitHubCredentialsFromAppSettings();
CreateGitHubConnection();

var items = EnsureItemsAreLoaded();
items.Add((Item) item);
Expand All @@ -145,7 +153,6 @@ public void Add(IItem item)
public void Delete(string itemId)
{
ReadGitHubCredentialsFromAppSettings();
CreateGitHubConnection();

var items = EnsureItemsAreLoaded();

Expand All @@ -162,7 +169,6 @@ public void Delete(string itemId)
public IItem Get(string itemId)
{
ReadGitHubCredentialsFromAppSettings();
CreateGitHubConnection();

var items = EnsureItemsAreLoaded();
Item item = items
Expand All @@ -174,7 +180,6 @@ public IItem Get(string itemId)
public IList<IItem> List()
{
ReadGitHubCredentialsFromAppSettings();
CreateGitHubConnection();

var items = EnsureItemsAreLoaded();
return items.Cast<IItem>().ToList();
Expand All @@ -183,7 +188,6 @@ public IList<IItem> List()
public void Update(IItem item)
{
ReadGitHubCredentialsFromAppSettings();
CreateGitHubConnection();

var items = EnsureItemsAreLoaded();

Expand Down
22 changes: 22 additions & 0 deletions tests/TodoList.AcceptanceTests/ConsoleTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace TodoList.AcceptanceTests
{
using System.Diagnostics;
using Xunit;

public sealed class ConsoleTests
{
[Fact]
public void RunInMemory()
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = "source/TodoList.ConsoleApp/bin/Debug/netcoreapp2.2/todo.dll -- dm"
}
};
process.Start();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
</ItemGroup>

</Project>