Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dokonczone LAB04 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
86 changes: 85 additions & 1 deletion kod/UamTTA/UamTTA.Tests/BudgetFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,59 @@ public IEnumerable<DateTime[]> MonthlyBudgetTestCases
}
}

[Test]
public IEnumerable<DateTime[]> QuarterlyBudgetTestCases
{
get
{
yield return new[] { new DateTime(2015, 8, 2), new DateTime(2015, 11, 1) };
yield return new[] { new DateTime(2015, 10, 15), new DateTime(2016, 1, 14) };
yield return new[] { new DateTime(2015, 10, 1), new DateTime(2015, 12, 31) };
yield return new[] { new DateTime(2015, 1, 1), new DateTime(2015, 3, 31) };
yield return new[] { new DateTime(2016, 4, 1), new DateTime(2016, 6, 30) };
yield return new[] { new DateTime(2015, 7, 1), new DateTime(2015, 9, 30) };
yield return new[] { new DateTime(2015, 10, 5), new DateTime(2016, 1, 4) };
yield return new[] { new DateTime(2015, 11, 13), new DateTime(2016, 2, 12) };
yield return new[] { new DateTime(2015, 12, 1), new DateTime(2016, 2, 29) };
yield return new[] { new DateTime(2014, 12, 1), new DateTime(2015, 2, 28) };
yield return new[] { new DateTime(2015, 4, 17), new DateTime(2015, 7, 16) };
yield return new[] { new DateTime(2015, 11, 1), new DateTime(2016, 1, 31) };
yield return new[] { new DateTime(2014, 11, 13), new DateTime(2015, 2, 12) };
yield return new[] { new DateTime(2015, 1, 13), new DateTime(2015, 4, 12) };
yield return new[] { new DateTime(2015, 2, 13), new DateTime(2015, 5, 12) };
yield return new[] { new DateTime(2015, 3, 13), new DateTime(2015, 6, 12) };
yield return new[] { new DateTime(2015, 4, 13), new DateTime(2015, 7, 12) };
yield return new[] { new DateTime(2015, 5, 13), new DateTime(2015, 8, 12) };
yield return new[] { new DateTime(2015, 6, 13), new DateTime(2015, 9, 12) };
yield return new[] { new DateTime(2015, 7, 13), new DateTime(2015, 10, 12) };
yield return new[] { new DateTime(2015, 8, 13), new DateTime(2015, 11, 12) };
yield return new[] { new DateTime(2015, 9, 13), new DateTime(2015, 12, 12) };
yield return new[] { new DateTime(2015, 10, 13), new DateTime(2016, 1, 12) };
yield return new[] { new DateTime(2015, 11, 13), new DateTime(2016, 2, 12) };
yield return new[] { new DateTime(2015, 12, 13), new DateTime(2016, 3, 12) };

}
}

public IEnumerable<DateTime[]> YearlyBudgetTestCases
{
get
{
yield return new[] { new DateTime(2015, 10, 2), new DateTime(2016, 10, 1) };
yield return new[] { new DateTime(2015, 10, 15), new DateTime(2016, 10, 14) };
yield return new[] { new DateTime(2014, 10, 1), new DateTime(2015, 9, 30) };
yield return new[] { new DateTime(2015, 1, 1), new DateTime(2015, 12, 31) };
yield return new[] { new DateTime(2014, 7, 12), new DateTime(2015, 7, 11) };
yield return new[] { new DateTime(2015, 4, 1), new DateTime(2016, 3, 31) };
yield return new[] { new DateTime(2015, 3, 11), new DateTime(2016, 3, 10) };
yield return new[] { new DateTime(2016, 1, 1), new DateTime(2016, 12, 31) };
yield return new[] { new DateTime(2016, 2, 1), new DateTime(2017, 1, 31) };
yield return new[] { new DateTime(2016, 3, 1), new DateTime(2017, 2, 28) };
yield return new[] { new DateTime(2015, 3, 1), new DateTime(2016, 2, 29) };
yield return new[] { new DateTime(2014, 3, 1), new DateTime(2015, 2, 28) };
}
}

[Test]
[TestCaseSource(nameof(MonthlyBudgetTestCases))]
public void Can_Create_Monthly_Budget_From_Template(DateTime expectedStartDate, DateTime expectedEndDate)
{
Expand All @@ -61,5 +113,37 @@ public void Can_Create_Monthly_Budget_From_Template(DateTime expectedStartDate,
Assert.That(budget.ValidFrom, Is.EqualTo(expectedStartDate));
Assert.That(budget.ValidTo, Is.EqualTo(expectedEndDate));
}

[Test]
[TestCaseSource(nameof(QuarterlyBudgetTestCases))]
public void Can_Create_Quarterly_Budget_From_Template(DateTime expectedStartDate, DateTime expectedEndDate)
{
//Arrange
var template = new BudgetTemplate(Duration.Quarterly, "Quarterly Budget");

//Act
Budget budget = _budgetFactory.CreateBudget(template, expectedStartDate);

//Assert
Assert.That(budget, Is.Not.Null);
Assert.That(budget.ValidFrom, Is.EqualTo(expectedStartDate));
Assert.That(budget.ValidTo, Is.EqualTo(expectedEndDate));
}

[Test]
[TestCaseSource(nameof(YearlyBudgetTestCases))]
public void Can_Create_Yearly_Budget_From_Template(DateTime expectedStartDate, DateTime expectedEndDate)
{
//Arrange
var template = new BudgetTemplate(Duration.Yearly, "Yearly Budget");

//Act
Budget budget = _budgetFactory.CreateBudget(template, expectedStartDate);

//Assert
Assert.That(budget, Is.Not.Null);
Assert.That(budget.ValidFrom, Is.EqualTo(expectedStartDate));
Assert.That(budget.ValidTo, Is.EqualTo(expectedEndDate));
}
}
}
3 changes: 3 additions & 0 deletions kod/UamTTA/UamTTA.Tests/UamTTA.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<Name>UamTTA</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</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.
Expand Down
16 changes: 16 additions & 0 deletions kod/UamTTA/UamTTA/BudgetFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ public Budget CreateBudget(BudgetTemplate template, DateTime startDate)
break;

case Duration.Quarterly:
endDate = AddQuarter(startDate);
break;

case Duration.Yearly:
endDate = AddYear(startDate);
break;

default:
Expand All @@ -44,5 +46,19 @@ private static DateTime AddMonth(DateTime startDate)
endDate = endDate.AddDays(-1);
return endDate;
}

private static DateTime AddQuarter(DateTime startDate)
{
DateTime endDate = startDate.AddMonths(3);
endDate = endDate.AddDays(-1);
return endDate;
}

private static DateTime AddYear(DateTime startDate)
{
DateTime endDate = startDate.AddYears(1);
endDate = endDate.AddDays(-1);
return endDate;
}
}
}