From 4746d897f544a390b36acc93910e50aeaf72732d Mon Sep 17 00:00:00 2001 From: Samuel Dufour Date: Mon, 27 Dec 2021 23:16:00 +0100 Subject: [PATCH 1/2] Remove ApprovalTest and add TexttestFixture --- csharpcore/GildedRose/GildedRose.csproj | 2 -- csharpcore/GildedRoseTests/ApprovalTest.cs | 27 ------------------ .../GildedRoseTests/GildedRoseTests.csproj | 28 +++++++++---------- .../TexttestFixture.cs} | 20 +++++++++---- 4 files changed, 28 insertions(+), 49 deletions(-) delete mode 100644 csharpcore/GildedRoseTests/ApprovalTest.cs rename csharpcore/{GildedRose/Program.cs => GildedRoseTests/TexttestFixture.cs} (80%) diff --git a/csharpcore/GildedRose/GildedRose.csproj b/csharpcore/GildedRose/GildedRose.csproj index 405ad28f27..fff78129b3 100644 --- a/csharpcore/GildedRose/GildedRose.csproj +++ b/csharpcore/GildedRose/GildedRose.csproj @@ -1,9 +1,7 @@  - Exe net6.0 - GildedRoseKata.Program diff --git a/csharpcore/GildedRoseTests/ApprovalTest.cs b/csharpcore/GildedRoseTests/ApprovalTest.cs deleted file mode 100644 index 178e66a7fe..0000000000 --- a/csharpcore/GildedRoseTests/ApprovalTest.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Xunit; -using System; -using System.IO; -using System.Text; -using ApprovalTests; -using ApprovalTests.Reporters; -using GildedRoseKata; - -namespace GildedRoseTests -{ - [UseReporter(typeof(DiffReporter))] - public class ApprovalTest - { - [Fact] - public void ThirtyDays() - { - var fakeoutput = new StringBuilder(); - Console.SetOut(new StringWriter(fakeoutput)); - Console.SetIn(new StringReader("a\n")); - - Program.Main(new string[] { }); - var output = fakeoutput.ToString(); - - Approvals.Verify(output); - } - } -} diff --git a/csharpcore/GildedRoseTests/GildedRoseTests.csproj b/csharpcore/GildedRoseTests/GildedRoseTests.csproj index 88ec090069..93a44263c6 100644 --- a/csharpcore/GildedRoseTests/GildedRoseTests.csproj +++ b/csharpcore/GildedRoseTests/GildedRoseTests.csproj @@ -1,20 +1,20 @@  - - net6.0 - false - + + Exe + net6.0 + GildedRoseTests.TexttestFixture + - - - - - - - + + + + + + - - - + + + diff --git a/csharpcore/GildedRose/Program.cs b/csharpcore/GildedRoseTests/TexttestFixture.cs similarity index 80% rename from csharpcore/GildedRose/Program.cs rename to csharpcore/GildedRoseTests/TexttestFixture.cs index 1367fe73c5..cccaf5f9e5 100644 --- a/csharpcore/GildedRose/Program.cs +++ b/csharpcore/GildedRoseTests/TexttestFixture.cs @@ -1,9 +1,12 @@ -using System; + +using GildedRoseKata; + +using System; using System.Collections.Generic; -namespace GildedRoseKata +namespace GildedRoseTests { - public class Program + public static class TexttestFixture { public static void Main(string[] args) { @@ -33,14 +36,19 @@ public static void Main(string[] args) SellIn = 5, Quality = 49 }, - // this conjured item does not work properly yet - new Item {Name = "Conjured Mana Cake", SellIn = 3, Quality = 6} + // this conjured item does not work properly yet + new Item {Name = "Conjured Mana Cake", SellIn = 3, Quality = 6} }; var app = new GildedRose(Items); + int days = 2; + if (args.Length > 0) + { + days = int.Parse(args[0]) + 1; + } - for (var i = 0; i < 31; i++) + for (var i = 0; i < days; i++) { Console.WriteLine("-------- day " + i + " --------"); Console.WriteLine("name, sellIn, quality"); From 6a43f361894edd1cb2b347f0c4c4349c0c77bacf Mon Sep 17 00:00:00 2001 From: Samuel Dufour Date: Mon, 27 Dec 2021 23:41:41 +0100 Subject: [PATCH 2/2] Add a csharpcore-Verify.xunit folder --- csharpcore-Verify.xunit/.gitignore | 300 ++++++++++++++++++ csharpcore-Verify.xunit/GildedRose.sln | 31 ++ .../GildedRose/GildedRose.cs | 89 ++++++ .../GildedRose/GildedRose.csproj | 9 + csharpcore-Verify.xunit/GildedRose/Item.cs | 9 + csharpcore-Verify.xunit/GildedRose/Program.cs | 56 ++++ .../GildedRoseTests/ApprovalTest.cs | 31 ++ .../GildedRoseTests/GildedRoseTest.cs | 18 ++ .../GildedRoseTests/GildedRoseTests.csproj | 19 ++ 9 files changed, 562 insertions(+) create mode 100644 csharpcore-Verify.xunit/.gitignore create mode 100644 csharpcore-Verify.xunit/GildedRose.sln create mode 100644 csharpcore-Verify.xunit/GildedRose/GildedRose.cs create mode 100644 csharpcore-Verify.xunit/GildedRose/GildedRose.csproj create mode 100644 csharpcore-Verify.xunit/GildedRose/Item.cs create mode 100644 csharpcore-Verify.xunit/GildedRose/Program.cs create mode 100644 csharpcore-Verify.xunit/GildedRoseTests/ApprovalTest.cs create mode 100644 csharpcore-Verify.xunit/GildedRoseTests/GildedRoseTest.cs create mode 100644 csharpcore-Verify.xunit/GildedRoseTests/GildedRoseTests.csproj diff --git a/csharpcore-Verify.xunit/.gitignore b/csharpcore-Verify.xunit/.gitignore new file mode 100644 index 0000000000..b0e5bb0c6b --- /dev/null +++ b/csharpcore-Verify.xunit/.gitignore @@ -0,0 +1,300 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Typescript v1 declaration files +typings/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs +.vscode diff --git a/csharpcore-Verify.xunit/GildedRose.sln b/csharpcore-Verify.xunit/GildedRose.sln new file mode 100644 index 0000000000..f2ce64a151 --- /dev/null +++ b/csharpcore-Verify.xunit/GildedRose.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31424.327 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GildedRose", "GildedRose\GildedRose.csproj", "{D781C52B-92C0-48BF-8414-177495DF4174}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GildedRoseTests", "GildedRoseTests\GildedRoseTests.csproj", "{CB6715CE-A283-4C70-9C1B-F58822077731}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D781C52B-92C0-48BF-8414-177495DF4174}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D781C52B-92C0-48BF-8414-177495DF4174}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D781C52B-92C0-48BF-8414-177495DF4174}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D781C52B-92C0-48BF-8414-177495DF4174}.Release|Any CPU.Build.0 = Release|Any CPU + {CB6715CE-A283-4C70-9C1B-F58822077731}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CB6715CE-A283-4C70-9C1B-F58822077731}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CB6715CE-A283-4C70-9C1B-F58822077731}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CB6715CE-A283-4C70-9C1B-F58822077731}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {02785EA4-86A5-4E57-9A9A-6998FAE1E617} + EndGlobalSection +EndGlobal diff --git a/csharpcore-Verify.xunit/GildedRose/GildedRose.cs b/csharpcore-Verify.xunit/GildedRose/GildedRose.cs new file mode 100644 index 0000000000..ed7dc42812 --- /dev/null +++ b/csharpcore-Verify.xunit/GildedRose/GildedRose.cs @@ -0,0 +1,89 @@ +using System.Collections.Generic; + +namespace GildedRoseKata +{ + public class GildedRose + { + IList Items; + public GildedRose(IList Items) + { + this.Items = Items; + } + + public void UpdateQuality() + { + for (var i = 0; i < Items.Count; i++) + { + if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + { + if (Items[i].Quality > 0) + { + if (Items[i].Name != "Sulfuras, Hand of Ragnaros") + { + Items[i].Quality = Items[i].Quality - 1; + } + } + } + else + { + if (Items[i].Quality < 50) + { + Items[i].Quality = Items[i].Quality + 1; + + if (Items[i].Name == "Backstage passes to a TAFKAL80ETC concert") + { + if (Items[i].SellIn < 11) + { + if (Items[i].Quality < 50) + { + Items[i].Quality = Items[i].Quality + 1; + } + } + + if (Items[i].SellIn < 6) + { + if (Items[i].Quality < 50) + { + Items[i].Quality = Items[i].Quality + 1; + } + } + } + } + } + + if (Items[i].Name != "Sulfuras, Hand of Ragnaros") + { + Items[i].SellIn = Items[i].SellIn - 1; + } + + if (Items[i].SellIn < 0) + { + if (Items[i].Name != "Aged Brie") + { + if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + { + if (Items[i].Quality > 0) + { + if (Items[i].Name != "Sulfuras, Hand of Ragnaros") + { + Items[i].Quality = Items[i].Quality - 1; + } + } + } + else + { + Items[i].Quality = Items[i].Quality - Items[i].Quality; + } + } + else + { + if (Items[i].Quality < 50) + { + Items[i].Quality = Items[i].Quality + 1; + } + } + } + } + } + } +} diff --git a/csharpcore-Verify.xunit/GildedRose/GildedRose.csproj b/csharpcore-Verify.xunit/GildedRose/GildedRose.csproj new file mode 100644 index 0000000000..405ad28f27 --- /dev/null +++ b/csharpcore-Verify.xunit/GildedRose/GildedRose.csproj @@ -0,0 +1,9 @@ + + + + Exe + net6.0 + GildedRoseKata.Program + + + diff --git a/csharpcore-Verify.xunit/GildedRose/Item.cs b/csharpcore-Verify.xunit/GildedRose/Item.cs new file mode 100644 index 0000000000..3d87cab4ff --- /dev/null +++ b/csharpcore-Verify.xunit/GildedRose/Item.cs @@ -0,0 +1,9 @@ +namespace GildedRoseKata +{ + public class Item + { + public string Name { get; set; } + public int SellIn { get; set; } + public int Quality { get; set; } + } +} diff --git a/csharpcore-Verify.xunit/GildedRose/Program.cs b/csharpcore-Verify.xunit/GildedRose/Program.cs new file mode 100644 index 0000000000..1367fe73c5 --- /dev/null +++ b/csharpcore-Verify.xunit/GildedRose/Program.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; + +namespace GildedRoseKata +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("OMGHAI!"); + + IList Items = new List{ + new Item {Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20}, + new Item {Name = "Aged Brie", SellIn = 2, Quality = 0}, + new Item {Name = "Elixir of the Mongoose", SellIn = 5, Quality = 7}, + new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = 0, Quality = 80}, + new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = -1, Quality = 80}, + new Item + { + Name = "Backstage passes to a TAFKAL80ETC concert", + SellIn = 15, + Quality = 20 + }, + new Item + { + Name = "Backstage passes to a TAFKAL80ETC concert", + SellIn = 10, + Quality = 49 + }, + new Item + { + Name = "Backstage passes to a TAFKAL80ETC concert", + SellIn = 5, + Quality = 49 + }, + // this conjured item does not work properly yet + new Item {Name = "Conjured Mana Cake", SellIn = 3, Quality = 6} + }; + + var app = new GildedRose(Items); + + + for (var i = 0; i < 31; i++) + { + Console.WriteLine("-------- day " + i + " --------"); + Console.WriteLine("name, sellIn, quality"); + for (var j = 0; j < Items.Count; j++) + { + System.Console.WriteLine(Items[j].Name + ", " + Items[j].SellIn + ", " + Items[j].Quality); + } + Console.WriteLine(""); + app.UpdateQuality(); + } + } + } +} diff --git a/csharpcore-Verify.xunit/GildedRoseTests/ApprovalTest.cs b/csharpcore-Verify.xunit/GildedRoseTests/ApprovalTest.cs new file mode 100644 index 0000000000..5aabda9859 --- /dev/null +++ b/csharpcore-Verify.xunit/GildedRoseTests/ApprovalTest.cs @@ -0,0 +1,31 @@ + +using GildedRoseKata; + +using System; +using System.IO; +using System.Text; +using System.Threading.Tasks; + +using VerifyXunit; + +using Xunit; + +namespace GildedRoseTests +{ + [UsesVerify] + public class ApprovalTest + { + [Fact] + public Task ThirtyDays() + { + var fakeoutput = new StringBuilder(); + Console.SetOut(new StringWriter(fakeoutput)); + Console.SetIn(new StringReader("a\n")); + + Program.Main(new string[] { }); + var output = fakeoutput.ToString(); + + return Verifier.Verify(output); + } + } +} diff --git a/csharpcore-Verify.xunit/GildedRoseTests/GildedRoseTest.cs b/csharpcore-Verify.xunit/GildedRoseTests/GildedRoseTest.cs new file mode 100644 index 0000000000..16b7dd95d1 --- /dev/null +++ b/csharpcore-Verify.xunit/GildedRoseTests/GildedRoseTest.cs @@ -0,0 +1,18 @@ +using Xunit; +using System.Collections.Generic; +using GildedRoseKata; + +namespace GildedRoseTests +{ + public class GildedRoseTest + { + [Fact] + public void foo() + { + IList Items = new List { new Item { Name = "foo", SellIn = 0, Quality = 0 } }; + GildedRose app = new GildedRose(Items); + app.UpdateQuality(); + Assert.Equal("fixme", Items[0].Name); + } + } +} diff --git a/csharpcore-Verify.xunit/GildedRoseTests/GildedRoseTests.csproj b/csharpcore-Verify.xunit/GildedRoseTests/GildedRoseTests.csproj new file mode 100644 index 0000000000..aac4b17bf9 --- /dev/null +++ b/csharpcore-Verify.xunit/GildedRoseTests/GildedRoseTests.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + false + + + + + + + + + + + + + +