From 09e949b60493fe63828a0e596f791b8df74728d6 Mon Sep 17 00:00:00 2001 From: damdud Date: Wed, 4 Nov 2015 19:40:20 +0100 Subject: [PATCH] Dokonczone LAB04 --- kod/UamTTA/UamTTA.Tests/BudgetFactoryTests.cs | 86 ++++++++++++++++++- kod/UamTTA/UamTTA.Tests/UamTTA.Tests.csproj | 3 + kod/UamTTA/UamTTA/BudgetFactory.cs | 16 ++++ 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/kod/UamTTA/UamTTA.Tests/BudgetFactoryTests.cs b/kod/UamTTA/UamTTA.Tests/BudgetFactoryTests.cs index d9bb716..d566e1f 100644 --- a/kod/UamTTA/UamTTA.Tests/BudgetFactoryTests.cs +++ b/kod/UamTTA/UamTTA.Tests/BudgetFactoryTests.cs @@ -46,7 +46,59 @@ public IEnumerable MonthlyBudgetTestCases } } - [Test] + public IEnumerable 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 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) { @@ -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)); + } } } \ No newline at end of file diff --git a/kod/UamTTA/UamTTA.Tests/UamTTA.Tests.csproj b/kod/UamTTA/UamTTA.Tests/UamTTA.Tests.csproj index 8feb7b1..7921a5e 100644 --- a/kod/UamTTA/UamTTA.Tests/UamTTA.Tests.csproj +++ b/kod/UamTTA/UamTTA.Tests/UamTTA.Tests.csproj @@ -62,6 +62,9 @@ UamTTA + + +