{"__v":15,"_id":"54471fc9e12a270800028ae2","category":{"__v":2,"_id":"544854af4544c30800241f50","pages":["5448517a4544c30800241f3d","54471fc9e12a270800028ae2","544853c7c1b42e08005b82b8","545aeb8ade8fad080013261c","545c2b9fe93d95100059ec3c"],"project":"54471fc9e12a270800028adc","version":"54471fc9e12a270800028adf","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-10-23T01:06:55.713Z","from_sync":false,"order":0,"slug":"start-here","title":"Start Here"},"is_link":false,"project":"54471fc9e12a270800028adc","user":"54471f91beb6320800da6f75","version":{"__v":10,"_id":"54471fc9e12a270800028adf","project":"54471fc9e12a270800028adc","createdAt":"2014-10-22T03:08:57.750Z","releaseDate":"2014-10-22T03:08:57.750Z","categories":["54471fc9e12a270800028ae0","5447b9e7b96a63140077d747","5447be130319802200fc0620","5447ed118d7af31a00dd411c","5447ed230319802200fc0702","5448524c4544c30800241f41","544854504544c30800241f4d","544854af4544c30800241f50","544854e74544c30800241f51","54485557c1b42e08005b82bf"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-10-22T03:08:57.838Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"basic_auth":false,"results":{"codes":[]},"try":true,"auth":"never","params":[],"url":""},"isReference":false,"order":1,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Newbie Content!\",\n  \"body\": \"This quickstart is written for newbies!  If you are comfortable with creating projects and adding NuGet packages, you should check out the [Advanced Quickstart](doc:advanced-quickstart)!\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Create a project\"\n}\n[/block]\nLet's assume you've already got a solution, and you want to start writing specs for it!   In fact, let's assume you're going to write unit specs AND integration specs! Open that solution, then add a new Class Library project to it!\n\nFirst, let's create a solution folder (right-click on the solution, and choose \"New Solution Folder\") named Specs. \n\nNext, right-click on your Specs folder, and choose \"Add New Project.\"  In the dialog that appears, find the class library project type:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/0foW5uK8S9SKa510rSzz_image.axd\",\n        \"image.axd\",\n        \"955\",\n        \"660\",\n        \"#5cabd6\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nThe name of your project isn't too important, but I typically use the pattern \"SolutionName.UnitSpecs\" and \"SolutionName.IntegrationSpecs.\"\n\nRepeat this process for your other spec project.  Your solution should now have two spec projects:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/cig2CM33Sq63QFp6NQAV_image.axd\",\n        \"image.axd\",\n        \"315\",\n        \"363\",\n        \"#379df9\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nNow we're ready to add SpecsFor!\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Add NuGet package\"\n}\n[/block]\nSpecsFor is available as a NuGet package.  Let's go ahead and add it to your new spec project!\n\nYou could use the Visual Studio NuGet Package Manager Console, or you can use the GUI.  Let's use the Package Manager Console.\n\nIn Visual Studio, go to the View menu, then select \"Other Windows,\" then select \"Package Manager Console.\"\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/Kf6HzYMTdaXRNa2aecps_image.axd\",\n        \"image.axd\",\n        \"652\",\n        \"768\",\n        \"#80a5b0\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nThis will open the Package Manager Console within Visual Studio:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/RI3tSeiTIWnPtdcautPb_image.axd\",\n        \"image.axd\",\n        \"806\",\n        \"278\",\n        \"#057aca\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nLet's install SpecsFor into each of our spec projects.  Run this command, and specify the full name of your spec project each time:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#Don't forget to change \\\"SampleApplication1.UnitSpecs\\\" to the name of your spec project!\\nInstall-Package SpecsFor -ProjectName SampleApplication1.UnitSpecs\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/xFz8CcxwTp66qRLDhDQI_image.axd\",\n        \"image.axd\",\n        \"613\",\n        \"547\",\n        \"#a35f28\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nAfter some churn, you should have SpecsFor installed into both projects.  Over in Solution Explorer, expand each spec project, then expand their References folders.  Each folder should contain a reference to SpecsFor:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/D3RtUeTxROuz5dKDKAn8_image.axd\",\n        \"image.axd\",\n        \"247\",\n        \"275\",\n        \"#331c0e\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nAnd there you have it!  Both projects are now ready!  \n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Use ReSharper?\",\n  \"body\": \"If you use ReSharper, be sure you check out the special template package for SpecsFor!  You can find more information in this section: [ReSharper Templates](doc:resharper-templates)\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Create your first spec!\"\n}\n[/block]\nYou've got all the pieces you need, so let's write your first spec!  Create a new class named *SampleSpecs*, and drop in this implementation:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class SimpleSpecs\\n\\t{\\n\\t\\tpublic class WidgetFactory\\n\\t\\t{\\n\\t\\t\\tpublic Widget CreateWidget(string color, int size)\\n\\t\\t\\t{\\n\\t\\t\\t\\treturn new Widget\\n\\t\\t\\t\\t{\\n\\t\\t\\t\\t\\tColor = color\\n\\t\\t\\t\\t};\\n\\t\\t\\t}\\n\\t\\t}\\n\\n\\t\\tpublic class Widget\\n\\t\\t{\\n\\t\\t\\tpublic string Color { get; set; }\\n\\t\\t\\tpublic int Size { get; set; }\\n\\t\\t}\\n\\n\\t\\tpublic class when_creating_a_widget : SpecsFor<WidgetFactory>\\n\\t\\t{\\n\\t\\t\\tprivate Widget _widget;\\n\\n\\t\\t\\tprotected override void When()\\n\\t\\t\\t{\\n\\t\\t\\t\\t_widget = SUT.CreateWidget(color: \\\"Red\\\", size: 500);\\n\\t\\t\\t}\\n\\n\\t\\t\\t[Test]\\n\\t\\t\\tpublic void then_it_sets_the_color()\\n\\t\\t\\t{\\n\\t\\t\\t\\t_widget.Color.ShouldEqual(\\\"Red\\\");\\n\\t\\t\\t}\\n\\n\\t\\t\\t[Test]\\n\\t\\t\\tpublic void then_it_sets_the_size()\\n\\t\\t\\t{\\n\\t\\t\\t\\t_widget.Size.ShouldEqual(500);\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nThis snippet contains a couple of Widget-related classes and a simple spec.  Run the specs with your favorite test runner.  You should have one failing spec, and one passing spec!  There's a small bug in the WidgetFactory!  Let's fix it!  Here's the new, corrected, factory: \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\t\\tpublic class WidgetFactory\\n\\t\\t{\\n\\t\\t\\tpublic Widget CreateWidget(string color, int size)\\n\\t\\t\\t{\\n\\t\\t\\t\\treturn new Widget\\n\\t\\t\\t\\t{\\n\\t\\t\\t\\t\\tColor = color,\\n\\t\\t\\t\\t\\tSize = size\\n\\t\\t\\t\\t};\\n\\t\\t\\t}\\n\\t\\t}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\n\nCongratulations!  You now have a simple, passing spec!  You're ready to start writing specs of your own!  Continue your adventure by [Creating a basic spec](doc:create-a-basic-spec)!","excerpt":"Prepare for a crash-course introduction to SpecsFor!  This article will show you how to create a project, add SpecsFor, and create your first spec!","slug":"getting-started","type":"basic","title":"Beginner's Quickstart"}

Beginner's Quickstart

Prepare for a crash-course introduction to SpecsFor! This article will show you how to create a project, add SpecsFor, and create your first spec!

[block:callout] { "type": "info", "title": "Newbie Content!", "body": "This quickstart is written for newbies! If you are comfortable with creating projects and adding NuGet packages, you should check out the [Advanced Quickstart](doc:advanced-quickstart)!" } [/block] [block:api-header] { "type": "basic", "title": "Create a project" } [/block] Let's assume you've already got a solution, and you want to start writing specs for it! In fact, let's assume you're going to write unit specs AND integration specs! Open that solution, then add a new Class Library project to it! First, let's create a solution folder (right-click on the solution, and choose "New Solution Folder") named Specs. Next, right-click on your Specs folder, and choose "Add New Project." In the dialog that appears, find the class library project type: [block:image] { "images": [ { "image": [ "https://files.readme.io/0foW5uK8S9SKa510rSzz_image.axd", "image.axd", "955", "660", "#5cabd6", "" ] } ] } [/block] The name of your project isn't too important, but I typically use the pattern "SolutionName.UnitSpecs" and "SolutionName.IntegrationSpecs." Repeat this process for your other spec project. Your solution should now have two spec projects: [block:image] { "images": [ { "image": [ "https://files.readme.io/cig2CM33Sq63QFp6NQAV_image.axd", "image.axd", "315", "363", "#379df9", "" ] } ] } [/block] Now we're ready to add SpecsFor! [block:api-header] { "type": "basic", "title": "Add NuGet package" } [/block] SpecsFor is available as a NuGet package. Let's go ahead and add it to your new spec project! You could use the Visual Studio NuGet Package Manager Console, or you can use the GUI. Let's use the Package Manager Console. In Visual Studio, go to the View menu, then select "Other Windows," then select "Package Manager Console." [block:image] { "images": [ { "image": [ "https://files.readme.io/Kf6HzYMTdaXRNa2aecps_image.axd", "image.axd", "652", "768", "#80a5b0", "" ] } ] } [/block] This will open the Package Manager Console within Visual Studio: [block:image] { "images": [ { "image": [ "https://files.readme.io/RI3tSeiTIWnPtdcautPb_image.axd", "image.axd", "806", "278", "#057aca", "" ] } ] } [/block] Let's install SpecsFor into each of our spec projects. Run this command, and specify the full name of your spec project each time: [block:code] { "codes": [ { "code": "#Don't forget to change \"SampleApplication1.UnitSpecs\" to the name of your spec project!\nInstall-Package SpecsFor -ProjectName SampleApplication1.UnitSpecs", "language": "shell" } ] } [/block] [block:image] { "images": [ { "image": [ "https://files.readme.io/xFz8CcxwTp66qRLDhDQI_image.axd", "image.axd", "613", "547", "#a35f28", "" ] } ] } [/block] After some churn, you should have SpecsFor installed into both projects. Over in Solution Explorer, expand each spec project, then expand their References folders. Each folder should contain a reference to SpecsFor: [block:image] { "images": [ { "image": [ "https://files.readme.io/D3RtUeTxROuz5dKDKAn8_image.axd", "image.axd", "247", "275", "#331c0e", "" ] } ] } [/block] And there you have it! Both projects are now ready! [block:callout] { "type": "info", "title": "Use ReSharper?", "body": "If you use ReSharper, be sure you check out the special template package for SpecsFor! You can find more information in this section: [ReSharper Templates](doc:resharper-templates)" } [/block] [block:api-header] { "type": "basic", "title": "Create your first spec!" } [/block] You've got all the pieces you need, so let's write your first spec! Create a new class named *SampleSpecs*, and drop in this implementation: [block:code] { "codes": [ { "code": "public class SimpleSpecs\n\t{\n\t\tpublic class WidgetFactory\n\t\t{\n\t\t\tpublic Widget CreateWidget(string color, int size)\n\t\t\t{\n\t\t\t\treturn new Widget\n\t\t\t\t{\n\t\t\t\t\tColor = color\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tpublic class Widget\n\t\t{\n\t\t\tpublic string Color { get; set; }\n\t\t\tpublic int Size { get; set; }\n\t\t}\n\n\t\tpublic class when_creating_a_widget : SpecsFor<WidgetFactory>\n\t\t{\n\t\t\tprivate Widget _widget;\n\n\t\t\tprotected override void When()\n\t\t\t{\n\t\t\t\t_widget = SUT.CreateWidget(color: \"Red\", size: 500);\n\t\t\t}\n\n\t\t\t[Test]\n\t\t\tpublic void then_it_sets_the_color()\n\t\t\t{\n\t\t\t\t_widget.Color.ShouldEqual(\"Red\");\n\t\t\t}\n\n\t\t\t[Test]\n\t\t\tpublic void then_it_sets_the_size()\n\t\t\t{\n\t\t\t\t_widget.Size.ShouldEqual(500);\n\t\t\t}\n\t\t}\n\t}", "language": "csharp" } ] } [/block] This snippet contains a couple of Widget-related classes and a simple spec. Run the specs with your favorite test runner. You should have one failing spec, and one passing spec! There's a small bug in the WidgetFactory! Let's fix it! Here's the new, corrected, factory: [block:code] { "codes": [ { "code": "\t\tpublic class WidgetFactory\n\t\t{\n\t\t\tpublic Widget CreateWidget(string color, int size)\n\t\t\t{\n\t\t\t\treturn new Widget\n\t\t\t\t{\n\t\t\t\t\tColor = color,\n\t\t\t\t\tSize = size\n\t\t\t\t};\n\t\t\t}\n\t\t}", "language": "csharp" } ] } [/block] Congratulations! You now have a simple, passing spec! You're ready to start writing specs of your own! Continue your adventure by [Creating a basic spec](doc:create-a-basic-spec)!