Skip to content

Commit

Permalink
Added Account project, Account & Lot classes, and first of two tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AgileInstitute committed Feb 28, 2023
1 parent 1bffdfe commit c015a18
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
18 changes: 18 additions & 0 deletions LunExLab/Account/Account.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Accounts;

// import LunExService.LunEx;

public class Account {

public long TotalGain(Lot[] lots, int currentPrice) {
long total = 0;
foreach (Lot nextLot in lots) {
total += GainForLot(nextLot, currentPrice);
}
return total;
}

private long GainForLot(Lot lot, int currentPrice) {
return lot.GainAt(currentPrice);
}
}
9 changes: 9 additions & 0 deletions LunExLab/Account/Account.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
18 changes: 18 additions & 0 deletions LunExLab/Account/Lot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Accounts;

public class Lot
{
private int shares;
private long cost;

public Lot(int shares, long cost)
{
this.shares = shares;
this.cost = cost;
}

public long GainAt(int currentPrice)
{
return (shares * currentPrice) - cost;
}
}
22 changes: 22 additions & 0 deletions LunExLab/AccountTests/AccountTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Account\Account.csproj" />
</ItemGroup>

</Project>
24 changes: 24 additions & 0 deletions LunExLab/AccountTests/TotalGainTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

using Accounts;

namespace AccountTests;

using Microsoft.VisualStudio.TestTools.UnitTesting;


[TestClass]
public class TotalGainTests
{
[TestMethod]
public void WhenUsingInteger()
{
// given
var firstLot = new Lot(100, 3000L);
var latestLot = new Lot(10, 400L);
Lot[] lots = { firstLot, latestLot };
Account account = new Account();

// when/then
Assert.AreEqual(1220L, account.TotalGain(lots, 42));
}
}
12 changes: 12 additions & 0 deletions LunExLab/LunExLab.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LunExService", "LunExService\LunExService.csproj", "{CCFD3F57-923D-4665-AAAC-3475217E9ADB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccountTests", "AccountTests\AccountTests.csproj", "{E0E46080-7AAA-4D15-96DD-26A40CBA3DFA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Account", "Account\Account.csproj", "{F09891BE-9441-4234-8A61-9587D8221F42}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -12,5 +16,13 @@ Global
{CCFD3F57-923D-4665-AAAC-3475217E9ADB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CCFD3F57-923D-4665-AAAC-3475217E9ADB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CCFD3F57-923D-4665-AAAC-3475217E9ADB}.Release|Any CPU.Build.0 = Release|Any CPU
{E0E46080-7AAA-4D15-96DD-26A40CBA3DFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0E46080-7AAA-4D15-96DD-26A40CBA3DFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0E46080-7AAA-4D15-96DD-26A40CBA3DFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0E46080-7AAA-4D15-96DD-26A40CBA3DFA}.Release|Any CPU.Build.0 = Release|Any CPU
{F09891BE-9441-4234-8A61-9587D8221F42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F09891BE-9441-4234-8A61-9587D8221F42}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F09891BE-9441-4234-8A61-9587D8221F42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F09891BE-9441-4234-8A61-9587D8221F42}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

0 comments on commit c015a18

Please sign in to comment.