Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

Commit

Permalink
added ioc container
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend committed Jan 8, 2016
1 parent 9c90e4b commit 1baf27b
Show file tree
Hide file tree
Showing 81 changed files with 1,054 additions and 408 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ An automatic blueprint and savegames installer for ParkitectNexus.
https://parkitectnexus.com


Copyright 2015 ParkitectNexus, Tim Potze
Copyright 2016 ParkitectNexus, Tim Potze

You are forbidden to distribute, modify or sublicense any part of the source code or binaries of this project.
2 changes: 2 additions & 0 deletions src/ParkitectNexus.Client-linux/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,7 @@ protected void VisitModWebsite (object o, ButtonPressEventArgs args)
{
if (_selectedMod == null) return;
Process.Start($"https://client.parkitectnexus.com/redirect/{_selectedMod.GetParkitectMod.Repository}");

}

}
4 changes: 2 additions & 2 deletions src/ParkitectNexus.Client-linux/ModLoaderUtil.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ParkitectNexusClient
// Copyright 2015 Parkitect, Tim Potze
// ParkitectNexusClient
// Copyright 2016 Parkitect, Tim Potze

using System;
using System.IO;
Expand Down
1 change: 0 additions & 1 deletion src/ParkitectNexus.Client-linux/gtk-gui/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ protected virtual void Build ()
this.Show ();
this.DeleteEvent += new global::Gtk.DeleteEventHandler (this.OnDeleteEvent);
this.btnInstallMod.Clicked += new global::System.EventHandler (this.InstallMod);
this.eventViewParkitectNexus.ButtonPressEvent += new global::Gtk.ButtonPressEventHandler (this.VisitModWebsite);
this.btnCheckUpdate.Clicked += new global::System.EventHandler (this.CheckForUpdates);
this.btnUninstall.Clicked += new global::System.EventHandler (this.UninstallMod);
this.button1500.Clicked += new global::System.EventHandler (this.Visit_Home_Website);
Expand Down
1 change: 0 additions & 1 deletion src/ParkitectNexus.Client-linux/gtk-gui/gui.stetic
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@
<child>
<widget class="Gtk.EventBox" id="eventViewParkitectNexus">
<property name="MemberName" />
<signal name="ButtonPressEvent" handler="VisitModWebsite" after="yes" />
<child>
<widget class="Gtk.Label" id="lblViewOnParkitectNexusWebsite">
<property name="MemberName" />
Expand Down
4 changes: 2 additions & 2 deletions src/ParkitectNexus.Client-mac/Settings/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ParkitectNexusClient
// Copyright 2015 Parkitect, Tim Potze
// ParkitectNexusClient
// Copyright 2016 Parkitect, Tim Potze

using System.Reflection;
using System.Resources;
Expand Down
4 changes: 2 additions & 2 deletions src/ParkitectNexus.Client-mac/Settings/ClientSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ParkitectNexusClient
// Copyright 2015 Parkitect, Tim Potze
// ParkitectNexusClient
// Copyright 2016 Parkitect, Tim Potze

using ParkitectNexus.Data.Settings;

Expand Down
4 changes: 2 additions & 2 deletions src/ParkitectNexus.Client-mac/UpdateInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ParkitectNexusClient
// Copyright 2015 Parkitect, Tim Potze
// ParkitectNexusClient
// Copyright 2016 Parkitect, Tim Potze

using Newtonsoft.Json;

Expand Down
4 changes: 2 additions & 2 deletions src/ParkitectNexus.Client-mac/UpdateUtil.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ParkitectNexusClient
// Copyright 2015 Parkitect, Tim Potze
// ParkitectNexusClient
// Copyright 2016 Parkitect, Tim Potze

using System;
using System.Diagnostics;
Expand Down
10 changes: 8 additions & 2 deletions src/ParkitectNexus.Client.Windows/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using ParkitectNexus.Data.Game;
using ParkitectNexus.Data.Game.Windows;
using ParkitectNexus.Data.Web;
using ParkitectNexus.Data;

namespace ParkitectNexus.Client.Windows
{
Expand All @@ -17,9 +18,14 @@ public partial class MainForm : MetroForm

public MainForm()
{
IParkitect parkitect = new WindowsParkitect();
//configure map
StructureMap.Registry registry = ObjectFactory.ConfigureStructureMap();
ObjectFactory.SetUpContainer(registry);


IParkitect parkitect = ObjectFactory.Container.GetInstance<IParkitect>();
IParkitectNexusWebsite website = new ParkitectNexusWebsite();
IParkitectOnlineAssetRepository assetRepository = new ParkitectOnlineAssetRepository(website);
IParkitectOnlineAssetRepository assetRepository = ObjectFactory.Container.GetInstance<IParkitectOnlineAssetRepository>();

InitializeComponent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,31 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="MetroFramework, Version=1.3.5.0, Culture=neutral, PublicKeyToken=5f91a84759bf584a, processorArchitecture=MSIL">
<HintPath>..\packages\MetroModernUI.1.3.5.0\lib\net45\MetroFramework.dll</HintPath>
<HintPath>..\..\packages\MetroModernUI.1.3.5.0\lib\net45\MetroFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MetroFramework.Design, Version=1.3.5.0, Culture=neutral, PublicKeyToken=5f91a84759bf584a, processorArchitecture=MSIL">
<HintPath>..\packages\MetroModernUI.1.3.5.0\lib\net45\MetroFramework.Design.dll</HintPath>
<HintPath>..\..\packages\MetroModernUI.1.3.5.0\lib\net45\MetroFramework.Design.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MetroFramework.Fonts, Version=1.3.5.0, Culture=neutral, PublicKeyToken=5f91a84759bf584a, processorArchitecture=MSIL">
<HintPath>..\packages\MetroModernUI.1.3.5.0\lib\net45\MetroFramework.Fonts.dll</HintPath>
<HintPath>..\..\packages\MetroModernUI.1.3.5.0\lib\net45\MetroFramework.Fonts.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ParkitectNexus.AssetMagic, Version=0.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ParkitectNexus.AssetMagic.0.1.1.0\lib\net452\ParkitectNexus.AssetMagic.dll</HintPath>
<HintPath>..\..\packages\ParkitectNexus.AssetMagic.0.1.1.0\lib\net452\ParkitectNexus.AssetMagic.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="StructureMap, Version=4.0.1.318, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\structuremap.4.0.1.318\lib\net40\StructureMap.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="StructureMap.Net4, Version=4.0.1.318, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\structuremap.4.0.1.318\lib\net40\StructureMap.Net4.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
1 change: 1 addition & 0 deletions src/ParkitectNexus.Client.Windows/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<package id="MetroModernUI" version="1.3.5.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
<package id="ParkitectNexus.AssetMagic" version="0.1.1.0" targetFramework="net452" />
<package id="structuremap" version="4.0.1.318" targetFramework="net452" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand Down
12 changes: 3 additions & 9 deletions src/ParkitectNexus.Data.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// ParkitectNexusClient
// Copyright 2016 Parkitect, Tim Potze

using System.Reflection;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.

[assembly: AssemblyTitle("ParkitectNexus.Data.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
Expand All @@ -20,11 +17,9 @@
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.

[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM

[assembly: Guid("a940be61-a6c6-49b4-945b-ac557b00cf6f")]

// Version information for an assembly consists of the following four values:
Expand All @@ -37,6 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
19 changes: 8 additions & 11 deletions src/ParkitectNexus.Data.Test/Web/ParkitectNexusUrlTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// ParkitectNexusClient
// Copyright 2016 Parkitect, Tim Potze

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ParkitectNexus.Data.Game;
using ParkitectNexus.Data.Web;

namespace ParkitectNexus.Data.Test.Web
Expand All @@ -25,11 +22,11 @@ public void TryParseTestMod()
//assert
Assert.IsTrue(result1.Name == "Ambient Occlusion");
Assert.IsTrue(result1.FileHash == "ParkitectNexus/AmbientOcclusion");
Assert.IsTrue(result1.AssetType == ParkitectAssetType.Mod);
Assert.IsTrue(result1.AssetType == Game.ParkitectAssetType.Mod);

Assert.IsTrue(result2.Name == "Cheat mod");
Assert.IsTrue(result2.FileHash == "nozols/ParkitectCheats");
Assert.IsTrue(result2.AssetType == ParkitectAssetType.Mod);
Assert.IsTrue(result2.AssetType == Game.ParkitectAssetType.Mod);
}

[TestMethod]
Expand All @@ -47,11 +44,11 @@ public void TryParseBlueprint()
//assert
Assert.IsTrue(result1.Name == "Dropper");
Assert.IsTrue(result1.FileHash == "3ed8ad1d70");
Assert.IsTrue(result1.AssetType == ParkitectAssetType.Blueprint);
Assert.IsTrue(result1.AssetType == Game.ParkitectAssetType.Blueprint);

Assert.IsTrue(result2.Name == "Ski Racer");
Assert.IsTrue(result2.FileHash == "2cfc80d929");
Assert.IsTrue(result2.AssetType == ParkitectAssetType.Blueprint);
Assert.IsTrue(result2.AssetType == Game.ParkitectAssetType.Blueprint);
}

[TestMethod]
Expand All @@ -69,11 +66,11 @@ public void TryParseSaveGame()
//assert
Assert.IsTrue(result1.Name == "Gigantic multi-themed park.");
Assert.IsTrue(result1.FileHash == "a4a24d1acf");
Assert.IsTrue(result1.AssetType == ParkitectAssetType.Savegame);
Assert.IsTrue(result1.AssetType == Game.ParkitectAssetType.Savegame);

Assert.IsTrue(result2.Name == "Log Hill");
Assert.IsTrue(result2.FileHash == "03567c46bb");
Assert.IsTrue(result2.AssetType == ParkitectAssetType.Savegame);
Assert.IsTrue(result2.AssetType == Game.ParkitectAssetType.Savegame);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// ParkitectNexusClient
// Copyright 2016 Parkitect, Tim Potze

using System.Threading.Tasks;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using ParkitectNexus.Data.Web;
using System.Threading.Tasks;
using Moq.Protected;
using Octokit;
using ParkitectNexus.Data.Game;
using ParkitectNexus.Data.Web;

namespace ParkitectNexus.Data.Test.Web
{
[TestClass]
Expand All @@ -20,30 +16,24 @@ public async Task ResolveDownloadInfoBlueprintTest()
//arrange
var assetRepository = new Mock<ParkitectOnlineAssetRepository>(new ParkitectNexusWebsite());
assetRepository.As<IParkitectOnlineAssetRepository>();
assetRepository.Protected()
.Setup<Task<RepositoryTag>>("GetLatestModTag", ItExpr.IsNull<string>(), ItExpr.IsNull<GitHubClient>())
.Returns(
new Task<RepositoryTag>(
() => new RepositoryTag("test_name", new GitReference(), "zip_url", "tar_ball_url")));
assetRepository.Protected().Setup<Task<RepositoryTag>>("GetLatestModTag", ItExpr.IsNull<string>(), ItExpr.IsNull<GitHubClient>()).Returns(new Task<RepositoryTag>(() => new RepositoryTag("test_name", new GitReference(), "zip_url", "tar_ball_url")));

ParkitectOnlineAssetRepository onlineAssetRepository = assetRepository.Object;
ParkitectOnlineAssetRepository onlineAssetRepository = (ParkitectOnlineAssetRepository)assetRepository.Object;

var parkitectNexusURL = new Mock<IParkitectNexusUrl>();

//parkitectnexus://Basic+Long+Wooden+Coaster/blueprint/27cff6bd3e
parkitectNexusURL.Setup(x => x.FileHash).Returns("27cff6bd3e");
parkitectNexusURL.Setup(x => x.Name).Returns("Basic+Long+Wooden+Coaster");
parkitectNexusURL.Setup(x => x.AssetType).Returns(ParkitectAssetType.Blueprint);
parkitectNexusURL.Setup(x => x.AssetType).Returns(Game.ParkitectAssetType.Blueprint);

//act
var result = await onlineAssetRepository.ResolveDownloadInfo(parkitectNexusURL.Object);
var result = await onlineAssetRepository.ResolveDownloadInfo((IParkitectNexusUrl)parkitectNexusURL.Object);


//assert
assetRepository.Protected()
.Verify("GetLatestModTag", Times.Never(), ItExpr.IsAny<string>(), ItExpr.IsAny<GitHubClient>());
Assert.IsTrue(result.Url == "http://staging.parkitectnexus.com/download/27cff6bd3e" ||
result.Url == "http://parkitectnexus.com/download/27cff6bd3e");
assetRepository.Protected().Verify("GetLatestModTag", Times.Never(), ItExpr.IsAny<string>(), ItExpr.IsAny<GitHubClient>());
Assert.IsTrue(result.Url == "http://staging.parkitectnexus.com/download/27cff6bd3e" || result.Url == "http://parkitectnexus.com/download/27cff6bd3e");
}

[TestMethod]
Expand All @@ -52,59 +42,49 @@ public async Task ResolveDownloadInfoDownloadSavegameTest()
//arrange
var assetRepository = new Mock<ParkitectOnlineAssetRepository>(new ParkitectNexusWebsite());
assetRepository.As<IParkitectOnlineAssetRepository>();
assetRepository.Protected()
.Setup<Task<RepositoryTag>>("GetLatestModTag", ItExpr.IsNull<string>(), ItExpr.IsNull<GitHubClient>())
.Returns(
new Task<RepositoryTag>(
() => new RepositoryTag("test_name", new GitReference(), "zip_url", "tar_ball_url")));
assetRepository.Protected().Setup<Task<RepositoryTag>>("GetLatestModTag", ItExpr.IsNull<string>(), ItExpr.IsNull<GitHubClient>()).Returns(new Task<RepositoryTag>(() => new RepositoryTag("test_name", new GitReference(), "zip_url", "tar_ball_url")));

ParkitectOnlineAssetRepository onlineAssetRepository = assetRepository.Object;
ParkitectOnlineAssetRepository onlineAssetRepository = (ParkitectOnlineAssetRepository)assetRepository.Object;

var parkitectNexusURL = new Mock<IParkitectNexusUrl>();

//parkitectnexus://Basic+Long+Wooden+Coaster/blueprint/27cff6bd3e
parkitectNexusURL.Setup(x => x.FileHash).Returns("27cff6bd3e");
parkitectNexusURL.Setup(x => x.Name).Returns("Basic+Long+Wooden+Coaster");
parkitectNexusURL.Setup(x => x.AssetType).Returns(ParkitectAssetType.Blueprint);
parkitectNexusURL.Setup(x => x.AssetType).Returns(Game.ParkitectAssetType.Blueprint);

//act
var result = await onlineAssetRepository.ResolveDownloadInfo(parkitectNexusURL.Object);
var result = await onlineAssetRepository.ResolveDownloadInfo((IParkitectNexusUrl)parkitectNexusURL.Object);


//assert
assetRepository.Protected()
.Verify("GetLatestModTag", Times.Never(), ItExpr.IsAny<string>(), ItExpr.IsAny<GitHubClient>());
Assert.IsTrue(result.Url == "http://staging.parkitectnexus.com/download/27cff6bd3e" ||
result.Url == "http://parkitectnexus.com/download/27cff6bd3e");
assetRepository.Protected().Verify("GetLatestModTag", Times.Never(), ItExpr.IsAny<string>(), ItExpr.IsAny<GitHubClient>());
Assert.IsTrue(result.Url == "http://staging.parkitectnexus.com/download/27cff6bd3e" || result.Url == "http://parkitectnexus.com/download/27cff6bd3e");
}

[TestMethod]
public async Task ResolveDownloadInfoModTest()
{

//arrange
var assetRepository = new Mock<ParkitectOnlineAssetRepository>(new ParkitectNexusWebsite());
assetRepository.As<IParkitectOnlineAssetRepository>();
assetRepository.Protected()
.Setup<Task<RepositoryTag>>("GetLatestModTag", ItExpr.IsAny<string>(), ItExpr.IsAny<GitHubClient>())
.ReturnsAsync(new RepositoryTag("test_name", new GitReference(), "zip_url", "tar_ball_url"));
assetRepository.Protected().Setup<Task<RepositoryTag>>("GetLatestModTag", ItExpr.IsAny<string>(), ItExpr.IsAny<GitHubClient>()).ReturnsAsync(new RepositoryTag("test_name", new GitReference(), "zip_url", "tar_ball_url"));

ParkitectOnlineAssetRepository onlineAssetRepository = assetRepository.Object;
ParkitectOnlineAssetRepository onlineAssetRepository = (ParkitectOnlineAssetRepository)assetRepository.Object;

var parkitectNexusURL = new Mock<IParkitectNexusUrl>();

//parkitectnexus://Tropical+Trees+Pack/mod/Renaleteto/parkitect-tropical-trees-pack
parkitectNexusURL.Setup(x => x.FileHash).Returns("Renaleteto/parkitect-tropical-trees-pack");
parkitectNexusURL.Setup(x => x.Name).Returns("Tropical+Trees+Pack");
parkitectNexusURL.Setup(x => x.AssetType).Returns(ParkitectAssetType.Mod);
parkitectNexusURL.Setup(x => x.AssetType).Returns(Game.ParkitectAssetType.Mod);

//act
var result = await onlineAssetRepository.ResolveDownloadInfo(parkitectNexusURL.Object);
var result = await onlineAssetRepository.ResolveDownloadInfo((IParkitectNexusUrl)parkitectNexusURL.Object);

//assert
assetRepository.Protected()
.Verify("GetLatestModTag", Times.Once(),
ItExpr.Is<string>(x => x == "Renaleteto/parkitect-tropical-trees-pack"),
ItExpr.IsAny<GitHubClient>());
assetRepository.Protected().Verify("GetLatestModTag",Times.Once(), ItExpr.Is<string>(x => x == "Renaleteto/parkitect-tropical-trees-pack"), ItExpr.IsAny<GitHubClient>());
Assert.IsTrue(result.Url == "zip_url");
Assert.IsTrue(result.Tag == "test_name");
Assert.IsTrue(result.Repository == "Renaleteto/parkitect-tropical-trees-pack");
Expand All @@ -113,13 +93,14 @@ public async Task ResolveDownloadInfoModTest()
[TestMethod]
public void IsValidFileHashTest()
{

//assert
Assert.IsTrue(ParkitectOnlineAssetRepository.IsValidFileHash("27cff6bd3e", ParkitectAssetType.Savegame));
Assert.IsFalse(ParkitectOnlineAssetRepository.IsValidFileHash("27cfdddf6bd3e", ParkitectAssetType.Savegame));
Assert.IsFalse(ParkitectOnlineAssetRepository.IsValidFileHash("2$7cff6bd3e", ParkitectAssetType.Savegame));
Assert.IsTrue(ParkitectOnlineAssetRepository.IsValidFileHash("27cff6bd3e", Game.ParkitectAssetType.Savegame));
Assert.IsFalse(ParkitectOnlineAssetRepository.IsValidFileHash("27cfdddf6bd3e", Game.ParkitectAssetType.Savegame));
Assert.IsFalse(ParkitectOnlineAssetRepository.IsValidFileHash("2$7cff6bd3e", Game.ParkitectAssetType.Savegame));

Assert.IsTrue(ParkitectOnlineAssetRepository.IsValidFileHash("Renaleteto/parkitect-tropical-trees-pack",
ParkitectAssetType.Mod));
Assert.IsTrue(ParkitectOnlineAssetRepository.IsValidFileHash("Renaleteto/parkitect-tropical-trees-pack", Game.ParkitectAssetType.Mod));
}

}
}
}
Loading

0 comments on commit 1baf27b

Please sign in to comment.