├── samples └── SpecsForSamples │ ├── WindowsAuthSampleApp │ ├── Views │ │ ├── _ViewStart.cshtml │ │ ├── Home │ │ │ ├── About.cshtml │ │ │ ├── Contact.cshtml │ │ │ └── Index.cshtml │ │ ├── Shared │ │ │ ├── Error.cshtml │ │ │ └── _Layout.cshtml │ │ └── Web.config │ ├── Global.asax │ ├── favicon.ico │ ├── Scripts │ │ └── _references.js │ ├── Models │ │ └── HomePageViewModel.cs │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.ttf │ │ └── glyphicons-halflings-regular.woff │ ├── App_Start │ │ ├── FilterConfig.cs │ │ ├── RouteConfig.cs │ │ └── BundleConfig.cs │ ├── Global.asax.cs │ ├── Content │ │ └── Site.css │ ├── Controllers │ │ └── HomeController.cs │ ├── packages.config │ ├── Web.Debug.config │ ├── Web.Release.config │ └── Properties │ │ └── AssemblyInfo.cs │ ├── SpecsForWebHelpers.Web │ ├── Global.asax │ ├── Models │ │ ├── SayHelloForm.cs │ │ └── SayHelloViewModel.cs │ ├── README.md │ ├── Helpers │ │ ├── VersionHelper.cs │ │ └── BootstrapHelpers.cs │ ├── Global.asax.cs │ ├── Filters │ │ └── MattOnlyAttribute.cs │ ├── packages.config │ ├── Domain │ │ └── CurrentUser.cs │ ├── App_Start │ │ └── RouteConfig.cs │ ├── Controllers │ │ └── HomeController.cs │ ├── Web.Debug.config │ ├── Web.Release.config │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Views │ │ └── web.config │ ├── Beginners.Domain │ ├── MockingBasics │ │ ├── IEngineFactory.cs │ │ ├── RealEngineFactory.cs │ │ ├── CarFactory.cs │ │ ├── Car.cs │ │ └── Engine.cs │ ├── Calculator.cs │ ├── Warehouse.cs │ └── Properties │ │ └── AssemblyInfo.cs │ ├── Beginners.Specs │ ├── PartialMatching │ │ ├── ITrainYard.cs │ │ ├── LuggageTicket.cs │ │ ├── TrainCar.cs │ │ ├── ShouldLookLikeSpecs.cs │ │ ├── PartialMatchingWithSome.cs │ │ └── LooksLikeSpecs.cs │ ├── Beginners.csproj.DotSettings │ ├── Beginners.Specs.csproj.DotSettings │ ├── CalculatorSpecs.cs │ ├── packages.config │ ├── ContainerConfiguration │ │ └── ContainerConfigurationSpecs.cs │ ├── MockingBasics │ │ └── CarFactorySpecs.cs │ ├── SimpleSpecs.cs │ ├── GivenWhenThen │ │ └── GivenWhenThenExampleSpecs.cs │ └── Properties │ │ └── AssemblyInfo.cs │ ├── Conventions.Basics │ ├── Domain │ │ ├── Foo.cs │ │ ├── HelloService.cs │ │ ├── FooFactory.cs │ │ └── HelloConsumer.cs │ ├── RealHelloServiceBehavior.cs │ ├── MockHelloServiceBehavior.cs │ ├── Specs │ │ ├── FooSpecs.cs │ │ ├── HelloSpecs.cs │ │ └── FooFactorySpecs.cs │ ├── LogExecutionTimeBehavior.cs │ ├── TransactionScopeWrapperBehavior.cs │ ├── packages.config │ ├── Configuration.cs │ ├── DummyDataProviderBehavior.cs │ └── Properties │ │ └── AssemblyInfo.cs │ ├── SpecsForWebHelpers.Specs │ ├── app.config │ ├── packages.config │ ├── Fakes │ │ └── ConfiguringBehaviorDemos.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Filters │ │ └── MattOnlyAttributeSpecsWithHelpers.cs │ ├── Controllers │ │ ├── HomeControllerSpecsWithHelpers.cs │ │ └── HomeControllerSpecsWithoutHelpers.cs │ └── Helpers │ │ └── BootstrapHelperSpecsWithHelpers.cs │ ├── PartialMatching │ ├── packages.config │ ├── Properties │ │ └── AssemblyInfo.cs │ └── FuzzyMatchingExampleSpecs.cs │ └── WindowsAuthSampleApp.Specs │ ├── SpecConfig.cs │ ├── Controllers │ └── HomeControllerSpecs.cs │ ├── app.config │ ├── packages.config │ └── Properties │ └── AssemblyInfo.cs ├── SpecsFor.Demo ├── Domain │ ├── IValidator.cs │ ├── IPublisher.cs │ ├── OrderSubmitted.cs │ ├── IInventory.cs │ ├── Order.cs │ ├── OrderResult.cs │ ├── InvoiceSubmissionResult.cs │ ├── Invoice.cs │ ├── InvoiceSubmittedEvent.cs │ ├── Car.cs │ ├── ValidatingOrderProcessor.cs │ ├── InvoiceProcessor.cs │ └── OrderProcessor.cs ├── app.config ├── packages.config ├── OldSchoolTests │ └── OrderProcessorSpecs.cs ├── Properties │ └── AssemblyInfo.cs ├── PlainBDD │ └── OrderProcessorSpecs.cs └── BDD.Inheritance │ └── OrderProcessorSpecs.cs ├── .idea └── .idea.SpecsFor │ └── .idea │ ├── encodings.xml │ ├── vcs.xml │ ├── indexLayout.xml │ └── .gitignore ├── SpecsFor.Core ├── IContext.cs ├── SpecInitException.cs ├── WhenSpecificationException.cs ├── GivenSpecificationException.cs ├── IAutoMocker.cs ├── tools │ └── Install.ps1 ├── Configuration │ ├── ISpecsForConfigurationExpression.cs │ ├── Model │ │ ├── IBehaviorStack.cs │ │ ├── IConditionalBehavior.cs │ │ └── ConditionalBehavior.cs │ ├── Behavior.cs │ ├── ConditionalInitializer.cs │ └── SpecsForConfigurationExpression.cs ├── Validation │ ├── ISpecValidator.cs │ └── NUnitSpecValidator.cs ├── ShouldExtensions │ ├── ExpectedObjectExtensions.cs │ ├── StringExtensions.cs │ ├── Any.cs │ ├── ContainsExtensions.cs │ ├── Looks.cs │ ├── EnumerableExtensions.cs │ ├── Matcher.cs │ └── Some.cs ├── ISpecs.cs ├── MoqExtensions.cs ├── SpecificationException.cs └── SpecsFor.Core.csproj ├── SpecsFor.Lamar.Tests ├── TestObjects │ ├── IFoo.cs │ └── MyTestSut.cs ├── ComposingContext │ ├── TestDomain │ │ ├── ILikeMagic.cs │ │ ├── MyTestLogger.cs │ │ ├── ProvideMagicByInterface.cs │ │ ├── DoNotProvideMagic.cs │ │ ├── Widget.cs │ │ ├── ProvideMagicByTypeName.cs │ │ ├── ProvideMagicByConcreteType.cs │ │ └── ProvideMagicForEveryone.cs │ ├── ComposingContextConfig.cs │ └── StackingContext │ │ └── StackingContextConfig.cs ├── SpecsFor.Lamar.Tests.csproj └── ShouldExtensions │ ├── StringExtensionsSpecs.cs │ ├── ContainsExtensionsSpecs.cs │ ├── EnumerableExtensionsSpecs.cs │ ├── ExpectedObjectExtensionsSpecs.cs │ └── PartialMatchingWithListsSpecs.cs ├── SpecsFor.Autofac.Tests ├── TestObjects │ ├── IFoo.cs │ ├── MyTestSut.cs │ └── MyAutofacModule.cs ├── ComposingContext │ ├── TestDomain │ │ ├── ILikeMagic.cs │ │ ├── ProvideMagicByInterface.cs │ │ ├── DoNotProvideMagic.cs │ │ ├── ProvideMagicByTypeName.cs │ │ ├── MyTestLogger.cs │ │ ├── ProvideMagicByConcreteType.cs │ │ ├── Widget.cs │ │ └── ProvideMagicForEveryone.cs │ ├── ComposingContextConfig.cs │ └── StackingContext │ │ ├── StackingContextConfig.cs │ │ └── StackingContextSpecs.cs ├── SpecsFor.Autofac.Tests.csproj └── ShouldExtensions │ ├── StringExtensionsSpecs.cs │ ├── ContainsExtensionsSpecs.cs │ ├── EnumerableExtensionsSpecs.cs │ ├── PartialMatchingWithListsSpecs.cs │ └── ExpectedObjectExtensionsSpecs.cs ├── SpecsFor.StructureMap.Tests ├── TestObjects │ ├── IFoo.cs │ └── MyTestSut.cs ├── ComposingContext │ ├── TestDomain │ │ ├── ILikeMagic.cs │ │ ├── MyTestLogger.cs │ │ ├── ProvideMagicByInterface.cs │ │ ├── DoNotProvideMagic.cs │ │ ├── ProvideMagicByTypeName.cs │ │ ├── ProvideMagicByConcreteType.cs │ │ ├── Widget.cs │ │ └── ProvideMagicForEveryone.cs │ ├── ComposingContextConfig.cs │ └── StackingContext │ │ └── StackingContextConfig.cs ├── SpecsFor.StructureMap.Tests.csproj └── ShouldExtensions │ ├── StringExtensionsSpecs.cs │ ├── ContainsExtensionsSpecs.cs │ ├── EnumerableExtensionsSpecs.cs │ ├── ExpectedObjectExtensionsSpecs.cs │ └── PartialMatchingWithListsSpecs.cs ├── SpecsFor.StructureMap ├── MoqAutoMocker.cs ├── SpecsFor.cs ├── MoqServiceLocator.cs ├── StructureMapAutoMocker.cs ├── SpecsFor.StructureMap.csproj └── MoqFactory.cs ├── SpecsFor.Lamar ├── SpecsFor.cs ├── LamarAutoMocker.cs └── SpecsFor.Lamar.csproj ├── SpecsFor.sln.DotSettings ├── .gitignore ├── packages └── repositories.config ├── SpecsFor.ncrunchsolution ├── SpecsFor.Autofac ├── AutofacAutoMocker.cs ├── SpecsFor.Autofac.csproj └── SpecsFor.cs ├── LICENSE.md ├── ResharperTemplates ├── SpecsFor.Templates.nuspec └── SpecsFor.Templates.Resharper9.nuspec ├── metapackage └── specsfor-metapackage.nuspec └── publish-packages.ps1 /samples/SpecsForSamples/WindowsAuthSampleApp/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/IValidator.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Demo.Domain 2 | { 3 | public interface IValidator 4 | { 5 | bool Validate(T obj); 6 | } 7 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/IPublisher.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Demo.Domain 2 | { 3 | public interface IPublisher 4 | { 5 | void Publish(TEvent @event); 6 | } 7 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="SpecsForWebHelpers.Web.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="WindowsAuthSampleApp.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MattHoneycutt/SpecsFor/HEAD/samples/SpecsForSamples/WindowsAuthSampleApp/favicon.ico -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/OrderSubmitted.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Demo.Domain 2 | { 3 | public class OrderSubmitted 4 | { 5 | public string OrderNumber { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Scripts/_references.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MattHoneycutt/SpecsFor/HEAD/samples/SpecsForSamples/WindowsAuthSampleApp/Scripts/_references.js -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/IInventory.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Demo.Domain 2 | { 3 | public interface IInventory 4 | { 5 | bool IsQuantityAvailable(string partNumber, int quantity); 6 | } 7 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/Order.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Demo.Domain 2 | { 3 | public class Order 4 | { 5 | public string PartNumber { get; set; } 6 | 7 | public int Quantity { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Models/SayHelloForm.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsForWebHelpers.Web.Models 2 | { 3 | public class SayHelloForm 4 | { 5 | public string Name { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /.idea/.idea.SpecsFor/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/.idea.SpecsFor/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Models/SayHelloViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsForWebHelpers.Web.Models 2 | { 3 | public class SayHelloViewModel 4 | { 5 | public string Name { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Models/HomePageViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace WindowsAuthSampleApp.Models 2 | { 3 | public class HomePageViewModel 4 | { 5 | public string UserName { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/OrderResult.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Demo.Domain 2 | { 3 | public class OrderResult 4 | { 5 | public bool WasAccepted { get; set; } 6 | 7 | public string OrderNumber { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Domain/MockingBasics/IEngineFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Beginners.Domain.MockingBasics 2 | { 3 | public interface IEngineFactory 4 | { 5 | Engine GetEngine(string engineType); 6 | } 7 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MattHoneycutt/SpecsFor/HEAD/samples/SpecsForSamples/WindowsAuthSampleApp/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MattHoneycutt/SpecsFor/HEAD/samples/SpecsForSamples/WindowsAuthSampleApp/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MattHoneycutt/SpecsFor/HEAD/samples/SpecsForSamples/WindowsAuthSampleApp/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Domain/Calculator.cs: -------------------------------------------------------------------------------- 1 | namespace Beginners.Domain 2 | { 3 | public class Calculator 4 | { 5 | public int Add(int x, int y) 6 | { 7 | return x + y; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /SpecsFor.Core/IContext.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Core 2 | { 3 | public interface IContext 4 | { 5 | void Initialize(ISpecs state); 6 | } 7 | 8 | public interface IContext 9 | { 10 | void Initialize(ISpecs state); 11 | } 12 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Domain/Warehouse.cs: -------------------------------------------------------------------------------- 1 | using Beginners.Domain.MockingBasics; 2 | 3 | namespace Beginners.Domain 4 | { 5 | public class Warehouse 6 | { 7 | public Engine[] Engines { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Views/Home/About.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "About"; 3 | } 4 |

@ViewBag.Title.

5 |

@ViewBag.Message

6 | 7 |

Use this area to provide additional information.

8 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/PartialMatching/ITrainYard.cs: -------------------------------------------------------------------------------- 1 | namespace Beginners.PartialMatching 2 | { 3 | public interface ITrainYard 4 | { 5 | void StoreCar(TrainCar trainCar); 6 | void RetrieveLuggage(LuggageTicket ticket); 7 | } 8 | } -------------------------------------------------------------------------------- /.idea/.idea.SpecsFor/.idea/indexLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SpecsFor.Core/SpecInitException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Core 4 | { 5 | public class SpecInitException : SpecificationException 6 | { 7 | public SpecInitException(Exception[] exceptions) : base("Init", exceptions) 8 | { 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/Domain/Foo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Conventions.Basics.Domain 4 | { 5 | public class Foo 6 | { 7 | public Guid Id { get; set; } 8 | 9 | public string Name { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/InvoiceSubmissionResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Demo.Domain 4 | { 5 | public class InvoiceSubmissionResult 6 | { 7 | public bool Accepted { get; set; } 8 | 9 | public DateTime AcceptedDate { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/TestObjects/IFoo.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Lamar.Tests.TestObjects; 2 | 3 | public interface IFoo 4 | { 5 | int Bar(int x); 6 | } 7 | 8 | public class Foo : IFoo 9 | { 10 | public int Bar(int x) 11 | { 12 | return x * 3; 13 | } 14 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/PartialMatching/LuggageTicket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Beginners.PartialMatching 4 | { 5 | public class LuggageTicket 6 | { 7 | public string IssuedTo { get; set; } 8 | public DateTime Issued { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /SpecsFor.Core/WhenSpecificationException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Core 4 | { 5 | public class WhenSpecificationException : SpecificationException 6 | { 7 | public WhenSpecificationException(Exception[] exceptions) : base("When", exceptions) 8 | { 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /SpecsFor.Core/GivenSpecificationException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Core 4 | { 5 | public class GivenSpecificationException : SpecificationException 6 | { 7 | public GivenSpecificationException(Exception[] exceptions) : base("Given", exceptions) 8 | { 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /SpecsFor.Core/IAutoMocker.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | 3 | namespace SpecsFor.Core 4 | { 5 | public interface IAutoMocker 6 | { 7 | TSut CreateSUT() where TSut : class; 8 | 9 | Mock GetMockFor() where T : class; 10 | 11 | void ConfigureContainer(); 12 | } 13 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model System.Web.Mvc.HandleErrorInfo 2 | 3 | @{ 4 | ViewBag.Title = "Error"; 5 | } 6 | 7 |

Error.

8 |

An error occurred while processing your request.

9 | 10 | -------------------------------------------------------------------------------- /SpecsFor.Core/tools/Install.ps1: -------------------------------------------------------------------------------- 1 | param($rootPath, $toolsPath, $package, $project) 2 | 3 | # In NuGet 1.6+, this command will automatically add any necessary binding redirects, even to a class libary project. 4 | Add-BindingRedirect $project.Name 5 | 6 | $DTE.ItemOperations.Navigate("http://specsfor.com/installed.cshtml") -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/README.md: -------------------------------------------------------------------------------- 1 | # THIS APP IS NON-FUNCTIONAL! 2 | 3 | This app's only purpose is to give the specs something to test. The app has no real views, so don't try to run it. 4 | 5 | Instead, take a look at the spec project to see what you can do with SpecsFor<Web> Helpers! -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/TestObjects/IFoo.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Autofac.Tests.TestObjects 2 | { 3 | public interface IFoo 4 | { 5 | int Bar(int x); 6 | } 7 | 8 | public class Foo : IFoo 9 | { 10 | public int Bar(int x) 11 | { 12 | return x * 3; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/TestObjects/IFoo.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.StructureMap.Tests.TestObjects 2 | { 3 | public interface IFoo 4 | { 5 | int Bar(int x); 6 | } 7 | 8 | public class Foo : IFoo 9 | { 10 | public int Bar(int x) 11 | { 12 | return x * 3; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /SpecsFor.Core/Configuration/ISpecsForConfigurationExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Core.Configuration 4 | { 5 | public interface ISpecsForConfigurationExpression where T : class 6 | { 7 | void EnrichWith() where TEnricher : Behavior, new(); 8 | 9 | void CreateClassUnderTestUsing(Func initializer); 10 | } 11 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap/MoqAutoMocker.cs: -------------------------------------------------------------------------------- 1 | using StructureMap.AutoMocking; 2 | 3 | namespace SpecsFor.StructureMap 4 | { 5 | public class MoqAutoMocker : AutoMocker where T : class 6 | { 7 | public MoqAutoMocker() : base(new MoqServiceLocator()) 8 | { 9 | ServiceLocator = new MoqServiceLocator(); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Mvc; 3 | 4 | namespace WindowsAuthSampleApp 5 | { 6 | public class FilterConfig 7 | { 8 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 9 | { 10 | filters.Add(new HandleErrorAttribute()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.idea/.idea.SpecsFor/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Rider ignored files 5 | /.idea.SpecsFor.iml 6 | /contentModel.xml 7 | /projectSettingsUpdater.xml 8 | /modules.xml 9 | # Editor-based HTTP Client requests 10 | /httpRequests/ 11 | # Datasource local storage ignored files 12 | /dataSources/ 13 | /dataSources.local.xml 14 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Domain/MockingBasics/RealEngineFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Beginners.Domain.MockingBasics 2 | { 3 | public class RealEngineFactory : IEngineFactory 4 | { 5 | public Engine GetEngine(string engineType) 6 | { 7 | return new Engine 8 | { 9 | Maker = "Real Engines, Inc", 10 | Type = engineType 11 | }; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar/SpecsFor.cs: -------------------------------------------------------------------------------- 1 | using Lamar; 2 | using SpecsFor.Core; 3 | 4 | namespace SpecsFor.Lamar; 5 | 6 | public class SpecsFor : SpecsForBase where T : class 7 | { 8 | public virtual void ConfigureContainer(Container container) 9 | { 10 | } 11 | 12 | protected override IAutoMocker CreateAutoMocker() 13 | { 14 | return new LamarAutoMocker(this); 15 | } 16 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/TestObjects/MyTestSut.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Autofac.Tests.TestObjects 2 | { 3 | public class MyTestSut 4 | { 5 | private readonly IFoo _foo; 6 | 7 | public MyTestSut(IFoo foo) 8 | { 9 | _foo = foo; 10 | } 11 | 12 | public int TimesTwo(int x) 13 | { 14 | return _foo.Bar(x) * 2; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/TestObjects/MyTestSut.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Lamar.Tests.TestObjects 2 | { 3 | public class MyTestSut 4 | { 5 | private readonly IFoo _foo; 6 | 7 | public MyTestSut(IFoo foo) 8 | { 9 | _foo = foo; 10 | } 11 | 12 | public int TimesTwo(int x) 13 | { 14 | return _foo.Bar(x) * 2; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/Domain/HelloService.cs: -------------------------------------------------------------------------------- 1 | namespace Conventions.Basics.Domain 2 | { 3 | public interface IHelloService 4 | { 5 | string SayHello(); 6 | } 7 | 8 | public class HelloService : IHelloService 9 | { 10 | public string SayHello() 11 | { 12 | return "Hello from HelloService!"; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/TestObjects/MyTestSut.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.StructureMap.Tests.TestObjects 2 | { 3 | public class MyTestSut 4 | { 5 | private readonly IFoo _foo; 6 | 7 | public MyTestSut(IFoo foo) 8 | { 9 | _foo = foo; 10 | } 11 | 12 | public int TimesTwo(int x) 13 | { 14 | return _foo.Bar(x) * 2; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /SpecsFor.sln.DotSettings: -------------------------------------------------------------------------------- 1 | 2 | SUT -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/Domain/FooFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Conventions.Basics.Domain 4 | { 5 | public class FooFactory 6 | { 7 | public Foo Create(string name = "Unnamed") 8 | { 9 | return new Foo 10 | { 11 | Id = Guid.NewGuid(), 12 | Name = name 13 | }; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/Invoice.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Demo.Domain 2 | { 3 | public class Invoice 4 | { 5 | public string BillingName { get; set; } 6 | 7 | public string BillingAddress { get; set; } 8 | 9 | public string BillingCity { get; set; } 10 | 11 | public string BillingZip { get; set; } 12 | 13 | public decimal Amount { get; set; } 14 | 15 | public string Description { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/InvoiceSubmittedEvent.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Demo.Domain 2 | { 3 | public class InvoiceSubmittedEvent 4 | { 5 | public string BillingName { get; set; } 6 | 7 | public string BillingAddress { get; set; } 8 | 9 | public string BillingCity { get; set; } 10 | 11 | public string BillingZip { get; set; } 12 | 13 | public decimal Amount { get; set; } 14 | 15 | public string Description { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Domain/MockingBasics/CarFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Beginners.Domain.MockingBasics 2 | { 3 | public class CarFactory 4 | { 5 | private readonly IEngineFactory _engineFactory; 6 | 7 | public CarFactory(IEngineFactory engineFactory) 8 | { 9 | _engineFactory = engineFactory; 10 | } 11 | 12 | public Car BuildMuscleCar() 13 | { 14 | return new Car(_engineFactory.GetEngine("V8")); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /SpecsFor.Core/Validation/ISpecValidator.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("SpecsFor.Tests")] 4 | [assembly: InternalsVisibleTo("SpecsFor.Autofac.Tests")] 5 | [assembly: InternalsVisibleTo("SpecsFor.StructureMap.Tests")] 6 | [assembly: InternalsVisibleTo("SpecsFor.Lamar.Tests")] 7 | namespace SpecsFor.Core.Validation 8 | { 9 | internal interface ISpecValidator 10 | { 11 | void ValidateSpec(ISpecs spec); 12 | } 13 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap/SpecsFor.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core; 2 | using StructureMap; 3 | 4 | namespace SpecsFor.StructureMap 5 | { 6 | public class SpecsFor : SpecsForBase where T : class 7 | { 8 | public virtual void ConfigureContainer(Container container) 9 | { 10 | } 11 | 12 | protected override IAutoMocker CreateAutoMocker() 13 | { 14 | return new StructureMapAutoMocker(this); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Helpers/VersionHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace SpecsForWebHelpers.Web.Helpers 4 | { 5 | public static class VersionHelper 6 | { 7 | public static string GetVersionString(this HtmlHelper helper) 8 | { 9 | if (helper.ViewContext.HttpContext.IsDebuggingEnabled) 10 | { 11 | return "1.0.0.0-DEBUG"; 12 | } 13 | else 14 | { 15 | return "1.0.0.0"; 16 | } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/Beginners.csproj.DotSettings: -------------------------------------------------------------------------------- 1 | 2 | True -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/PartialMatching/TrainCar.cs: -------------------------------------------------------------------------------- 1 | namespace Beginners.PartialMatching 2 | { 3 | public class TrainCar 4 | { 5 | public Person Conductor { get; set; } 6 | 7 | public string Name { get; set; } 8 | 9 | public int MaxPassengers { get; set; } 10 | 11 | public int YearBuilt { get; set; } 12 | } 13 | 14 | public class Person 15 | { 16 | public string FirstName { get; set; } 17 | 18 | public string LastName { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/Beginners.Specs.csproj.DotSettings: -------------------------------------------------------------------------------- 1 | 2 | True -------------------------------------------------------------------------------- /SpecsFor.Core/ShouldExtensions/ExpectedObjectExtensions.cs: -------------------------------------------------------------------------------- 1 | using ExpectedObjects; 2 | 3 | namespace SpecsFor.Core.ShouldExtensions 4 | { 5 | public static class ExpectedObjectExtensions 6 | { 7 | public static void ShouldLookLike(this T actual, T expected) 8 | { 9 | expected.ToExpectedObject().ShouldEqual(actual); 10 | } 11 | 12 | public static void ShouldLookLikePartial(this T actual, object expected) 13 | { 14 | expected.ToExpectedObject().ShouldMatch(actual); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/Domain/HelloConsumer.cs: -------------------------------------------------------------------------------- 1 | namespace Conventions.Basics.Domain 2 | { 3 | public class HelloConsumer 4 | { 5 | private readonly IHelloService _helloService; 6 | 7 | public HelloConsumer(IHelloService helloService) 8 | { 9 | _helloService = helloService; 10 | } 11 | 12 | public string GetHelloMessage() 13 | { 14 | return _helloService.SayHello(); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Specs/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/TestObjects/MyAutofacModule.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | 3 | namespace SpecsFor.Autofac.Tests.TestObjects 4 | { 5 | public class MyAutofacModule : Module 6 | { 7 | protected override void Load(ContainerBuilder builder) 8 | { 9 | builder.RegisterType().As(); 10 | } 11 | } 12 | 13 | public class SpecialFooTimesTen : IFoo 14 | { 15 | public int Bar(int x) 16 | { 17 | return x * 10; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ComposingContext/TestDomain/ILikeMagic.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace SpecsFor.Autofac.Tests.ComposingContext.TestDomain 4 | { 5 | public interface ILikeMagic 6 | { 7 | List CalledByDuringGiven { get; set; } 8 | List CalledByAfterSpec { get; set; } 9 | List CalledByAfterTest { get; set; } 10 | List CalledByBeforeTest { get; set; } 11 | List CalledByApplyAfterClassUnderTestInitialized { get; set; } 12 | List CalledBySpecInit { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /SpecsFor.Core/Configuration/Model/IBehaviorStack.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Core.Configuration.Model 4 | { 5 | internal interface IBehaviorStack 6 | { 7 | void ApplySpecInitTo(ISpecs specs); 8 | void ApplyAfterClassUnderTestInitializedTo(ISpecs specs); 9 | void ApplyGivenTo(ISpecs specs); 10 | void ApplyAfterGivenTo(ISpecs specs); 11 | void ApplyAfterSpecTo(ISpecs specs); 12 | void ApplyAfterTestTo(ISpecs specs); 13 | void ApplyBeforeTestTo(ISpecs specs); 14 | Func GetInitializationMethodFor(ISpecs specs); 15 | } 16 | } -------------------------------------------------------------------------------- /SpecsFor.Core/ISpecs.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | 3 | namespace SpecsFor.Core 4 | { 5 | public interface ISpecs 6 | { 7 | Mock GetMockFor() where TMock : class; 8 | 9 | IAutoMocker CreateAutoMocker(); 10 | 11 | IAutoMocker Mocker { get; } 12 | 13 | void InitializeClassUnderTest(); 14 | 15 | void Given(); 16 | 17 | void When(); 18 | 19 | void AfterSpec(); 20 | 21 | void AfterTest(); 22 | 23 | void BeforeTest(); 24 | } 25 | 26 | public interface ISpecs : ISpecs 27 | { 28 | T SUT { get; set; } 29 | } 30 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ComposingContext/TestDomain/ILikeMagic.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Lamar.Tests.ComposingContext.TestDomain; 2 | 3 | public interface ILikeMagic 4 | { 5 | List CalledByDuringGiven { get; set; } 6 | List CalledByAfterGiven { get; set; } 7 | List CalledByAfterSpec { get; set; } 8 | List CalledByAfterTest { get; set; } 9 | List CalledByBeforeTest { get; set; } 10 | List CalledByApplyAfterClassUnderTestInitialized { get; set; } 11 | List CalledBySpecInit { get; set; } 12 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Domain/MockingBasics/Car.cs: -------------------------------------------------------------------------------- 1 | namespace Beginners.Domain.MockingBasics 2 | { 3 | public class Car 4 | { 5 | public Engine Engine { get; set; } 6 | 7 | public bool IsStopped { get; set; } 8 | 9 | public Car(Engine engine) 10 | { 11 | Engine = engine; 12 | IsStopped = true; 13 | } 14 | 15 | public void Start() 16 | { 17 | Engine.Start(); 18 | IsStopped = false; 19 | } 20 | 21 | public void Stop() 22 | { 23 | Engine.Stop(); 24 | IsStopped = true; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /SpecsFor.Core/MoqExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Moq.Language; 4 | using Moq.Language.Flow; 5 | 6 | namespace SpecsFor.Core 7 | { 8 | public static class MoqExtensions 9 | { 10 | //Makes it a little cleaner to stub out something that returns an IQueryable using an array. 11 | public static IReturnsResult Returns(this IReturns> returns, IEnumerable value) where TMock : class 12 | { 13 | return returns.Returns(value.AsQueryable()); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/PartialMatching/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace SpecsForWebHelpers.Web 9 | { 10 | public class MvcApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | AreaRegistration.RegisterAllAreas(); 15 | RouteConfig.RegisterRoutes(RouteTable.Routes); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Domain/MockingBasics/Engine.cs: -------------------------------------------------------------------------------- 1 | namespace Beginners.Domain.MockingBasics 2 | { 3 | public class Engine 4 | { 5 | public int YearBuilt { get; set; } 6 | public string Maker { get; set; } 7 | public string Type { get; set; } 8 | public bool IsStopped { get; set; } 9 | 10 | public Engine() 11 | { 12 | IsStopped = true; 13 | } 14 | 15 | public void Start() 16 | { 17 | IsStopped = false; 18 | } 19 | 20 | public void Stop() 21 | { 22 | IsStopped = true; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /SpecsFor.Core/ShouldExtensions/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using NUnit.Framework; 3 | 4 | namespace SpecsFor.Core.ShouldExtensions 5 | { 6 | public static class StringExtensions 7 | { 8 | public static void ShouldContainAll(this string actual, params string[] expected) 9 | { 10 | if (!expected.All(e => actual.Contains(e))) 11 | { 12 | var message = string.Format("Expected string containing all of '{0}'. \r\n Actual was '{1}'.", 13 | string.Join(", ", expected), actual); 14 | 15 | Assert.Fail(message); 16 | } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/Car.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Demo.Domain 2 | { 3 | public class Car 4 | { 5 | private readonly IEngine _engine; 6 | private readonly ITransmission _transmission; 7 | 8 | public Car(IEngine engine, ITransmission transmission) 9 | { 10 | _engine = engine; 11 | _transmission = transmission; 12 | } 13 | 14 | public void TurnKey() 15 | { 16 | _engine.Start(); 17 | } 18 | } 19 | 20 | public interface ITransmission 21 | { 22 | string Gear { get; set; } 23 | } 24 | 25 | public interface IEngine 26 | { 27 | void Start(); 28 | } 29 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/RealHelloServiceBehavior.cs: -------------------------------------------------------------------------------- 1 | using Conventions.Basics.Domain; 2 | using SpecsFor; 3 | using SpecsFor.Configuration; 4 | 5 | namespace Conventions.Basics 6 | { 7 | public interface INeedRealHelloService : ISpecs 8 | { 9 | } 10 | 11 | public class RealHelloServiceBehavior : Behavior 12 | { 13 | public override void SpecInit(INeedRealHelloService instance) 14 | { 15 | instance.MockContainer.Inject(new HelloService()); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Views/Home/Contact.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "Contact"; 3 | } 4 |

@ViewBag.Title.

5 |

@ViewBag.Message

6 | 7 |
8 | One Microsoft Way
9 | Redmond, WA 98052-6399
10 | P: 11 | 425.555.0100 12 |
13 | 14 |
15 | Support: Support@example.com
16 | Marketing: Marketing@example.com 17 |
-------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/CalculatorSpecs.cs: -------------------------------------------------------------------------------- 1 | using Beginners.Domain; 2 | using SpecsFor; 3 | using NUnit.Framework; 4 | using Should; 5 | 6 | namespace Beginners 7 | { 8 | public class CalculatorSpecs 9 | { 10 | public class when_adding_two_numbers : SpecsFor 11 | { 12 | private int _result; 13 | 14 | protected override void When() 15 | { 16 | _result = SUT.Add(1, 2); 17 | } 18 | 19 | [Test] 20 | public void then_the_result_should_be_three() 21 | { 22 | _result.ShouldEqual(3); 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Filters/MattOnlyAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | using SpecsForWebHelpers.Web.Domain; 3 | 4 | namespace SpecsForWebHelpers.Web.Filters 5 | { 6 | public class MattOnlyAttribute : ActionFilterAttribute 7 | { 8 | public ICurrentUser CurrentUser { get; set; } 9 | 10 | public override void OnActionExecuting(ActionExecutingContext filterContext) 11 | { 12 | if (CurrentUser.UserName != "Matt") 13 | { 14 | filterContext.Result = 15 | new ViewResult { ViewName = "YouAreNotMatt" }; 16 | } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #Deployment files 2 | Deploy/Package 3 | Deploy/*.nupkg 4 | Deploy/Archive 5 | #ignore thumbnails created by windows 6 | Thumbs.db 7 | #Ignore files build by Visual Studio 8 | *.obj 9 | *.exe 10 | *.pdb 11 | *.user 12 | *.aps 13 | *.pch 14 | *.vspscc 15 | *_i.c 16 | *_p.c 17 | *.ncb 18 | *.suo 19 | *.tlb 20 | *.tlh 21 | *.bak 22 | *.cache 23 | *.ilk 24 | *.log 25 | [Bb]in 26 | [Dd]ebug*/ 27 | *.lib 28 | *.sbr 29 | obj/ 30 | [Rr]elease*/ 31 | _ReSharper*/ 32 | [Tt]est[Rr]esult* 33 | *.db3 34 | *.zip 35 | *.ncrunchproject 36 | packages/ 37 | ResharperTemplates/*.nupkg 38 | .vs 39 | *.nupkg 40 | -------------------------------------------------------------------------------- /SpecsFor.Core/Configuration/Model/IConditionalBehavior.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Core.Configuration.Model 4 | { 5 | internal interface IConditionalBehavior 6 | { 7 | bool CanBeAppliedTo(Type targetType); 8 | void ApplyGivenTo(object specs); 9 | void ApplyAfterGivenTo(object specs); 10 | void ApplyAfterSpecTo(object specs); 11 | void ApplySpecInitTo(object specs); 12 | void ApplyAfterTestTo(object specs); 13 | void ApplyBeforeTestTo(object specs); 14 | void ApplyAfterClassUnderTestInitializedTo(object specs); 15 | } 16 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ComposingContext/TestDomain/ILikeMagic.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace SpecsFor.StructureMap.Tests.ComposingContext.TestDomain 4 | { 5 | public interface ILikeMagic 6 | { 7 | List CalledByDuringGiven { get; set; } 8 | List CalledByAfterGiven { get; set; } 9 | List CalledByAfterSpec { get; set; } 10 | List CalledByAfterTest { get; set; } 11 | List CalledByBeforeTest { get; set; } 12 | List CalledByApplyAfterClassUnderTestInitialized { get; set; } 13 | List CalledBySpecInit { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SpecsFor.Core/Configuration/Behavior.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Core.Configuration 2 | { 3 | public abstract class Behavior where T : class 4 | { 5 | public virtual void SpecInit(T instance) 6 | { 7 | } 8 | 9 | public virtual void ClassUnderTestInitialized(T instance) 10 | { 11 | } 12 | 13 | public virtual void Given(T instance) 14 | { 15 | } 16 | 17 | public virtual void AfterGiven(T instance) 18 | { 19 | } 20 | 21 | public virtual void AfterSpec(T instance) 22 | { 23 | } 24 | 25 | public virtual void AfterTest(T instance) 26 | { 27 | } 28 | 29 | public virtual void BeforeTest(T instance) 30 | { 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /SpecsFor.Core/Configuration/ConditionalInitializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Core.Configuration 4 | { 5 | internal class ConditionalInitializer 6 | { 7 | private readonly Func _predicate; 8 | private readonly Func _initializer; 9 | 10 | public ConditionalInitializer(Func predicate, Func initializer) 11 | { 12 | _predicate = predicate; 13 | _initializer = initializer; 14 | } 15 | 16 | public bool CanCreate(Type targetType) 17 | { 18 | return _predicate(targetType); 19 | } 20 | 21 | public Func Initializer() 22 | { 23 | return _initializer; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/SpecsFor.Autofac.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/MockHelloServiceBehavior.cs: -------------------------------------------------------------------------------- 1 | using Conventions.Basics.Domain; 2 | using SpecsFor; 3 | using SpecsFor.Configuration; 4 | 5 | namespace Conventions.Basics 6 | { 7 | public interface INeedMockHelloService : ISpecs 8 | { 9 | } 10 | 11 | public class MockHelloServiceBehavior : Behavior 12 | { 13 | public override void SpecInit(INeedMockHelloService instance) 14 | { 15 | instance.GetMockFor() 16 | .Setup(x => x.SayHello()) 17 | .Returns("Hello from Moq instance!"); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Optimization; 7 | using System.Web.Routing; 8 | 9 | namespace WindowsAuthSampleApp 10 | { 11 | public class MvcApplication : System.Web.HttpApplication 12 | { 13 | protected void Application_Start() 14 | { 15 | AreaRegistration.RegisterAllAreas(); 16 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 17 | RouteConfig.RegisterRoutes(RouteTable.Routes); 18 | BundleConfig.RegisterBundles(BundleTable.Bundles); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/SpecsFor.StructureMap.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace WindowsAuthSampleApp 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/Specs/FooSpecs.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Conventions.Basics.Domain; 3 | using NUnit.Framework; 4 | using Should; 5 | using SpecsFor; 6 | 7 | namespace Conventions.Basics.Specs 8 | { 9 | public class FooSpecs 10 | { 11 | public class when_a_spec_has_the_right_marker_interface 12 | : SpecsFor, INeedDummyData 13 | { 14 | public IEnumerable Foos { get; set; } 15 | 16 | [Test] 17 | public void then_it_injects_some_foos() 18 | { 19 | Foos.ShouldNotBeEmpty(); 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Content/Site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Set padding to keep content from hitting the edges */ 7 | .body-content { 8 | padding-left: 15px; 9 | padding-right: 15px; 10 | } 11 | 12 | /* Override the default bootstrap behavior where horizontal description lists 13 | will truncate terms that are too long to fit in the left column 14 | */ 15 | .dl-horizontal dt { 16 | white-space: normal; 17 | } 18 | 19 | /* Set width on the form input elements since they're 100% wide by default */ 20 | input, 21 | select, 22 | textarea { 23 | max-width: 280px; 24 | } 25 | -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/ValidatingOrderProcessor.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Demo.Domain 2 | { 3 | public class ValidatingOrderProcessor : OrderProcessor 4 | { 5 | private readonly IValidator _validator; 6 | 7 | public ValidatingOrderProcessor(IValidator validator, IInventory inventory, IPublisher publisher) 8 | : base(inventory, publisher) 9 | { 10 | _validator = validator; 11 | } 12 | 13 | public override OrderResult Process(Order order) 14 | { 15 | if (_validator.Validate(order)) 16 | { 17 | return base.Process(order); 18 | } 19 | else 20 | { 21 | return new OrderResult {WasAccepted = false}; 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/SpecsFor.Lamar.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /packages/repositories.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | using WindowsAuthSampleApp.Models; 3 | 4 | namespace WindowsAuthSampleApp.Controllers 5 | { 6 | public class HomeController : Controller 7 | { 8 | public ActionResult Index() 9 | { 10 | return View(new HomePageViewModel 11 | { 12 | UserName = User.Identity.Name 13 | }); 14 | } 15 | 16 | public ActionResult About() 17 | { 18 | ViewBag.Message = "Your application description page."; 19 | 20 | return View(); 21 | } 22 | 23 | public ActionResult Contact() 24 | { 25 | ViewBag.Message = "Your contact page."; 26 | 27 | return View(); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Domain/CurrentUser.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | 3 | namespace SpecsForWebHelpers.Web.Domain 4 | { 5 | public interface ICurrentUser 6 | { 7 | string UserName { get; } 8 | void SetName(string name); 9 | } 10 | 11 | public class CurrentUser : ICurrentUser 12 | { 13 | private readonly HttpSessionStateBase _session; 14 | 15 | public CurrentUser(HttpSessionStateBase session) 16 | { 17 | _session = session; 18 | } 19 | 20 | public string UserName 21 | { 22 | get { return (string)(_session["name"] ?? "Unknown"); } 23 | } 24 | 25 | public void SetName(string name) 26 | { 27 | _session["name"] = name; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/LogExecutionTimeBehavior.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using SpecsFor; 4 | using SpecsFor.Configuration; 5 | 6 | namespace Conventions.Basics 7 | { 8 | public class LogExecutionTimeBehavior : Behavior 9 | { 10 | private Stopwatch _stopwatch; 11 | 12 | public override void SpecInit(ISpecs instance) 13 | { 14 | _stopwatch = Stopwatch.StartNew(); 15 | } 16 | 17 | public override void AfterSpec(ISpecs instance) 18 | { 19 | _stopwatch.Stop(); 20 | 21 | Console.WriteLine($"{instance.GetType().Name} - {_stopwatch.Elapsed}"); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap/MoqServiceLocator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using StructureMap.AutoMocking; 3 | 4 | namespace SpecsFor.StructureMap 5 | { 6 | public class MoqServiceLocator : ServiceLocator 7 | { 8 | private readonly MoqFactory _moqs = new MoqFactory(); 9 | 10 | public T Service() where T : class 11 | { 12 | return (T) _moqs.CreateMock(typeof (T)); 13 | } 14 | 15 | public object Service(Type serviceType) 16 | { 17 | return _moqs.CreateMock(serviceType); 18 | } 19 | 20 | public T PartialMock(params object[] args) where T : class 21 | { 22 | return (T) _moqs.CreateMockThatCallsBase(typeof (T), args); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/TransactionScopeWrapperBehavior.cs: -------------------------------------------------------------------------------- 1 | using System.Transactions; 2 | using SpecsFor; 3 | using SpecsFor.Configuration; 4 | 5 | namespace Conventions.Basics 6 | { 7 | public interface INeedATransaction : ISpecs 8 | { 9 | } 10 | 11 | public class TransactionScopeWrapperBehavior : Behavior 12 | { 13 | private TransactionScope _scope; 14 | 15 | public override void SpecInit(INeedATransaction instance) 16 | { 17 | _scope = new TransactionScope(); 18 | } 19 | 20 | public override void AfterSpec(INeedATransaction instance) 21 | { 22 | _scope.Dispose(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace SpecsForWebHelpers.Web 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp.Specs/SpecConfig.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Mvc; 3 | 4 | namespace WindowsAuthSampleApp.Specs 5 | { 6 | [SetUpFixture] 7 | public class SpecConfig 8 | { 9 | private SpecsForIntegrationHost _host; 10 | 11 | [SetUp] 12 | public void Setup() 13 | { 14 | var config = new SpecsForMvcConfig(); 15 | config.UseIISExpress() 16 | .ApplicationHostConfigurationFile(@"applicationhost.config") 17 | .With(Project.Named("WindowsAuthSampleApp")); 18 | 19 | config.UseBrowser(BrowserDriver.InternetExplorer); 20 | 21 | _host = new SpecsForIntegrationHost(config); 22 | _host.Start(); 23 | } 24 | 25 | [TearDown] 26 | public void TearDown() 27 | { 28 | _host.Shutdown(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ComposingContext/TestDomain/ProvideMagicByInterface.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core.Configuration; 2 | 3 | namespace SpecsFor.Autofac.Tests.ComposingContext.TestDomain 4 | { 5 | public class ProvideMagicByInterface : Behavior 6 | { 7 | public override void Given(ILikeMagic instance) 8 | { 9 | instance.CalledByDuringGiven.Add(GetType().Name); 10 | } 11 | 12 | public override void AfterSpec(ILikeMagic instance) 13 | { 14 | instance.CalledByAfterSpec.Add(GetType().Name); 15 | } 16 | 17 | public override void AfterTest(ILikeMagic instance) 18 | { 19 | instance.CalledByAfterTest.Add(GetType().Name); 20 | } 21 | 22 | public override void BeforeTest(ILikeMagic instance) 23 | { 24 | instance.CalledByBeforeTest.Add(GetType().Name); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ShouldExtensions/StringExtensionsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.ShouldExtensions; 3 | 4 | namespace SpecsFor.Autofac.Tests.ShouldExtensions 5 | { 6 | public class StringExtensionsSpecs 7 | { 8 | public class when_checking_for_multiple_strings : SpecsFor 9 | { 10 | protected override void InitializeClassUnderTest() 11 | { 12 | SUT = "Test1 Test2 Test3"; 13 | } 14 | 15 | [Test] 16 | public void then_it_passes_when_the_string_contains_all_the_arguments() 17 | { 18 | SUT.ShouldContainAll("Test1", "Test2", "Test3"); 19 | } 20 | 21 | [Test] 22 | public void then_it_throws_if_the_string_is_missing_any_argument() 23 | { 24 | Assert.Throws(() => SUT.ShouldContainAll("Test1", "Test4")); 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/Configuration.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor; 3 | using SpecsFor.Configuration; 4 | 5 | namespace Conventions.Basics 6 | { 7 | [SetUpFixture] 8 | public class Configuration : SpecsForConfiguration 9 | { 10 | public Configuration() 11 | { 12 | WhenTestingAnything().EnrichWith(); 13 | 14 | WhenTesting().EnrichWith(); 15 | 16 | WhenTesting().EnrichWith(); 17 | WhenTesting().EnrichWith(); 18 | 19 | WhenTesting().EnrichWith(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ShouldExtensions/StringExtensionsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.ShouldExtensions; 3 | 4 | namespace SpecsFor.StructureMap.Tests.ShouldExtensions 5 | { 6 | public class StringExtensionsSpecs 7 | { 8 | public class when_checking_for_multiple_strings : SpecsFor 9 | { 10 | protected override void InitializeClassUnderTest() 11 | { 12 | SUT = "Test1 Test2 Test3"; 13 | } 14 | 15 | [Test] 16 | public void then_it_passes_when_the_string_contains_all_the_arguments() 17 | { 18 | SUT.ShouldContainAll("Test1", "Test2", "Test3"); 19 | } 20 | 21 | [Test] 22 | public void then_it_throws_if_the_string_is_missing_any_argument() 23 | { 24 | Assert.Throws(() => SUT.ShouldContainAll("Test1", "Test4")); 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /SpecsFor.Core/ShouldExtensions/Any.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Core.ShouldExtensions 4 | { 5 | public static class Any 6 | { 7 | public static T ValueOf() 8 | { 9 | Matcher.Create(null, "Any value of type " + typeof(T).FullName); 10 | 11 | return default(T); 12 | } 13 | 14 | public static T NonDefaultValueOf() where T : struct 15 | { 16 | Matcher.Create(x => !Equals(x, default(T)), "Non-default value of " + typeof(T).FullName); 17 | 18 | return default(T); 19 | } 20 | 21 | public static T NonNullValueOf() 22 | { 23 | if (default(T) != null) 24 | throw new InvalidOperationException("You cannot use this method with a non-nullable type."); 25 | 26 | Matcher.Create(x => x != null, "Non-null value of " + typeof(T).FullName); 27 | 28 | return default(T); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ComposingContext/TestDomain/DoNotProvideMagic.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core; 2 | using SpecsFor.Core.Configuration; 3 | 4 | namespace SpecsFor.Autofac.Tests.ComposingContext.TestDomain 5 | { 6 | public class DoNotProvideMagic : Behavior 7 | { 8 | public override void Given(ISpecs instance) 9 | { 10 | ((ILikeMagic)instance).CalledByDuringGiven.Add(GetType().Name); 11 | } 12 | 13 | public override void AfterSpec(ISpecs instance) 14 | { 15 | ((ILikeMagic)instance).CalledByAfterSpec.Add(GetType().Name); 16 | } 17 | 18 | public override void AfterTest(ISpecs instance) 19 | { 20 | ((ILikeMagic)instance).CalledByAfterTest.Add(GetType().Name); 21 | } 22 | 23 | public override void BeforeTest(ISpecs instance) 24 | { 25 | ((ILikeMagic)instance).CalledByBeforeTest.Add(GetType().Name); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ComposingContext/TestDomain/ProvideMagicByTypeName.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core; 2 | using SpecsFor.Core.Configuration; 3 | 4 | namespace SpecsFor.Autofac.Tests.ComposingContext.TestDomain 5 | { 6 | public class ProvideMagicByTypeName : Behavior 7 | { 8 | public override void Given(ISpecs instance) 9 | { 10 | ((ILikeMagic)instance).CalledByDuringGiven.Add(GetType().Name); 11 | } 12 | 13 | public override void AfterSpec(ISpecs instance) 14 | { 15 | ((ILikeMagic)instance).CalledByAfterSpec.Add(GetType().Name); 16 | } 17 | 18 | public override void AfterTest(ISpecs instance) 19 | { 20 | ((ILikeMagic)instance).CalledByAfterTest.Add(GetType().Name); 21 | } 22 | 23 | public override void BeforeTest(ISpecs instance) 24 | { 25 | ((ILikeMagic)instance).CalledByBeforeTest.Add(GetType().Name); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp.Specs/Controllers/HomeControllerSpecs.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Principal; 2 | using WindowsAuthSampleApp.Controllers; 3 | using WindowsAuthSampleApp.Models; 4 | using NUnit.Framework; 5 | using Should; 6 | using SpecsFor; 7 | using SpecsFor.Mvc; 8 | 9 | namespace WindowsAuthSampleApp.Specs.Controllers 10 | { 11 | public class HomeControllerSpecs 12 | { 13 | public class when_viewing_the_home_page : SpecsFor 14 | { 15 | protected override void When() 16 | { 17 | SUT.NavigateTo(c => c.Index()); 18 | } 19 | 20 | [Test] 21 | public void then_it_has_the_name_of_the_logged_in_user() 22 | { 23 | SUT.FindDisplayFor() 24 | .DisplayFor(x => x.UserName).Text.ShouldEqual(WindowsIdentity.GetCurrent().Name); 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ComposingContext/TestDomain/MyTestLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using SpecsFor.Core; 4 | using SpecsFor.Core.Configuration; 5 | 6 | namespace SpecsFor.Autofac.Tests.ComposingContext.TestDomain 7 | { 8 | //TODO: Put in the demo project 9 | public class MyTestLogger : Behavior 10 | { 11 | private Stopwatch _stopwatch; 12 | 13 | public override void Given(ISpecs instance) 14 | { 15 | _stopwatch = Stopwatch.StartNew(); 16 | } 17 | 18 | public override void AfterSpec(ISpecs instance) 19 | { 20 | Console.WriteLine(_stopwatch.Elapsed.TotalSeconds); 21 | } 22 | 23 | public override void AfterTest(ISpecs instance) 24 | { 25 | Console.WriteLine("After test"); 26 | } 27 | 28 | public override void BeforeTest(ISpecs instance) 29 | { 30 | Console.WriteLine("Before test"); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ComposingContext/ComposingContextConfig.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Autofac.Tests.ComposingContext.TestDomain; 3 | using SpecsFor.Core.Configuration; 4 | 5 | namespace SpecsFor.Autofac.Tests.ComposingContext 6 | { 7 | [SetUpFixture] 8 | public class ComposingContextConfig : SpecsForConfiguration 9 | { 10 | public ComposingContextConfig() 11 | { 12 | WhenTesting().EnrichWith(); 13 | WhenTesting>().EnrichWith(); 14 | WhenTesting(t => t.Name.Contains("running_tests_decorated")).EnrichWith(); 15 | WhenTesting(t => t.Name.Contains("junk that does not exist")).EnrichWith(); 16 | WhenTestingAnything().EnrichWith(); 17 | WhenTestingAnything().EnrichWith(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ComposingContext/TestDomain/MyTestLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using SpecsFor.Core; 4 | using SpecsFor.Core.Configuration; 5 | 6 | namespace SpecsFor.StructureMap.Tests.ComposingContext.TestDomain 7 | { 8 | //TODO: Put in the demo project 9 | public class MyTestLogger : Behavior 10 | { 11 | private Stopwatch _stopwatch; 12 | 13 | public override void Given(ISpecs instance) 14 | { 15 | _stopwatch = Stopwatch.StartNew(); 16 | } 17 | 18 | public override void AfterSpec(ISpecs instance) 19 | { 20 | Console.WriteLine(_stopwatch.Elapsed.TotalSeconds); 21 | } 22 | 23 | public override void AfterTest(ISpecs instance) 24 | { 25 | Console.WriteLine("After test"); 26 | } 27 | 28 | public override void BeforeTest(ISpecs instance) 29 | { 30 | Console.WriteLine("Before test"); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /SpecsFor.Core/Configuration/SpecsForConfigurationExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Core.Configuration 4 | { 5 | public class SpecsForConfigurationExpression : ISpecsForConfigurationExpression where TSpec : class 6 | { 7 | private readonly SpecsForConfiguration _config; 8 | private readonly Func _predicate; 9 | 10 | public SpecsForConfigurationExpression(SpecsForConfiguration config, Func predicate) 11 | { 12 | _config = config; 13 | _predicate = predicate; 14 | } 15 | 16 | public void EnrichWith() where TEnricher : Behavior, new() 17 | { 18 | _config.AddBehavior(_predicate); 19 | } 20 | 21 | //TODO: Need some tests. 22 | public void CreateClassUnderTestUsing(Func initializer) 23 | { 24 | _config.AddInitializer(_predicate, initializer); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ComposingContext/TestDomain/MyTestLogger.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using SpecsFor.Core; 3 | using SpecsFor.Core.Configuration; 4 | 5 | namespace SpecsFor.Lamar.Tests.ComposingContext.TestDomain; 6 | 7 | //TODO: Put in the demo project 8 | public class MyTestLogger : Behavior 9 | { 10 | private Stopwatch _stopwatch; 11 | 12 | public override void Given(ISpecs instance) 13 | { 14 | _stopwatch = Stopwatch.StartNew(); 15 | } 16 | 17 | public override void AfterSpec(ISpecs instance) 18 | { 19 | Console.WriteLine(_stopwatch.Elapsed.TotalSeconds); 20 | } 21 | 22 | public override void AfterTest(ISpecs instance) 23 | { 24 | Console.WriteLine("After test"); 25 | } 26 | 27 | public override void BeforeTest(ISpecs instance) 28 | { 29 | Console.WriteLine("Before test"); 30 | } 31 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar/LamarAutoMocker.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using SpecsFor.Core; 3 | 4 | namespace SpecsFor.Lamar; 5 | 6 | public class LamarAutoMocker : IAutoMocker where TSut : class 7 | { 8 | public SpecsForAutoMocker MoqAutoMocker { get; } 9 | 10 | private readonly SpecsFor _specsFor; 11 | 12 | public LamarAutoMocker(ISpecs specsFor) 13 | { 14 | _specsFor = (SpecsFor)specsFor; 15 | 16 | MoqAutoMocker = new SpecsForAutoMocker(); 17 | } 18 | 19 | T IAutoMocker.CreateSUT() 20 | { 21 | return MoqAutoMocker.ClassUnderTest as T; 22 | } 23 | 24 | public Mock GetMockFor() where T : class 25 | { 26 | return Mock.Get(MoqAutoMocker.Get()); 27 | } 28 | 29 | public void ConfigureContainer() 30 | { 31 | _specsFor.ConfigureContainer(MoqAutoMocker.Container); 32 | } 33 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ComposingContext/TestDomain/ProvideMagicByConcreteType.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core.Configuration; 2 | 3 | namespace SpecsFor.Autofac.Tests.ComposingContext.TestDomain 4 | { 5 | public class ProvideMagicByConcreteType : Behavior> 6 | { 7 | public override void Given(SpecsFor instance) 8 | { 9 | ((ILikeMagic)instance).CalledByDuringGiven.Add(GetType().Name); 10 | } 11 | 12 | public override void AfterSpec(SpecsFor instance) 13 | { 14 | ((ILikeMagic)instance).CalledByAfterSpec.Add(GetType().Name); 15 | } 16 | 17 | public override void AfterTest(SpecsFor instance) 18 | { 19 | ((ILikeMagic)instance).CalledByAfterTest.Add(GetType().Name); 20 | } 21 | 22 | public override void BeforeTest(SpecsFor instance) 23 | { 24 | ((ILikeMagic)instance).CalledByBeforeTest.Add(GetType().Name); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ShouldExtensions/StringExtensionsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.ShouldExtensions; 3 | 4 | namespace SpecsFor.Lamar.Tests.ShouldExtensions; 5 | 6 | public class StringExtensionsSpecs 7 | { 8 | public class when_checking_for_multiple_strings : SpecsFor 9 | { 10 | protected override void InitializeClassUnderTest() 11 | { 12 | SUT = "Test1 Test2 Test3"; 13 | } 14 | 15 | [Test] 16 | public void then_it_passes_when_the_string_contains_all_the_arguments() 17 | { 18 | SUT.ShouldContainAll("Test1", "Test2", "Test3"); 19 | } 20 | 21 | [Test] 22 | public void then_it_throws_if_the_string_is_missing_any_argument() 23 | { 24 | Assert.Throws(() => SUT.ShouldContainAll("Test1", "Test4")); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ComposingContext/ComposingContextConfig.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.Configuration; 3 | using SpecsFor.StructureMap.Tests.ComposingContext.TestDomain; 4 | 5 | namespace SpecsFor.StructureMap.Tests.ComposingContext 6 | { 7 | [SetUpFixture] 8 | public class ComposingContextConfig : SpecsForConfiguration 9 | { 10 | public ComposingContextConfig() 11 | { 12 | WhenTesting().EnrichWith(); 13 | WhenTesting>().EnrichWith(); 14 | WhenTesting(t => t.Name.Contains("running_tests_decorated")).EnrichWith(); 15 | WhenTesting(t => t.Name.Contains("junk that does not exist")).EnrichWith(); 16 | WhenTestingAnything().EnrichWith(); 17 | WhenTestingAnything().EnrichWith(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ComposingContext/ComposingContextConfig.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.Configuration; 3 | using SpecsFor.Lamar.Tests.ComposingContext.TestDomain; 4 | 5 | namespace SpecsFor.Lamar.Tests.ComposingContext; 6 | 7 | [SetUpFixture] 8 | public class ComposingContextConfig : SpecsForConfiguration 9 | { 10 | public ComposingContextConfig() 11 | { 12 | WhenTesting().EnrichWith(); 13 | WhenTesting>().EnrichWith(); 14 | WhenTesting(t => t.Name.Contains("running_tests_decorated")).EnrichWith(); 15 | WhenTesting(t => t.Name.Contains("junk that does not exist")).EnrichWith(); 16 | WhenTestingAnything().EnrichWith(); 17 | WhenTestingAnything().EnrichWith(); 18 | } 19 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/InvoiceProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Demo.Domain 4 | { 5 | public class InvoiceProcessor 6 | { 7 | private readonly IPublisher _publisher; 8 | 9 | public InvoiceProcessor(IPublisher publisher) 10 | { 11 | _publisher = publisher; 12 | } 13 | 14 | public InvoiceSubmissionResult SubmitInvoice(Invoice invoice) 15 | { 16 | _publisher.Publish(new InvoiceSubmittedEvent 17 | { 18 | BillingAddress = invoice.BillingAddress, 19 | BillingCity = invoice.BillingCity, 20 | BillingName = invoice.BillingName, 21 | BillingZip = invoice.BillingZip, 22 | Amount = invoice.Amount, 23 | Description = invoice.Description 24 | }); 25 | 26 | return new InvoiceSubmissionResult{Accepted = true, AcceptedDate = DateTime.Today}; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ComposingContext/TestDomain/Widget.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace SpecsFor.Autofac.Tests.ComposingContext.TestDomain 4 | { 5 | public class Widget : ILikeMagic 6 | { 7 | public List CalledByDuringGiven { get; set; } 8 | public List CalledByAfterSpec { get; set; } 9 | public List CalledByAfterTest { get; set; } 10 | public List CalledByBeforeTest { get; set; } 11 | public List CalledByApplyAfterClassUnderTestInitialized { get; set; } 12 | public List CalledBySpecInit { get; set; } 13 | 14 | public Widget() 15 | { 16 | CalledBySpecInit = new List(); 17 | CalledByApplyAfterClassUnderTestInitialized = new List(); 18 | CalledByDuringGiven = new List(); 19 | CalledByAfterSpec = new List(); 20 | CalledByAfterTest = new List(); 21 | CalledByBeforeTest = new List(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ComposingContext/TestDomain/ProvideMagicByInterface.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core.Configuration; 2 | 3 | namespace SpecsFor.StructureMap.Tests.ComposingContext.TestDomain 4 | { 5 | public class ProvideMagicByInterface : Behavior 6 | { 7 | public override void Given(ILikeMagic instance) 8 | { 9 | instance.CalledByDuringGiven.Add(GetType().Name); 10 | } 11 | 12 | public override void AfterGiven(ILikeMagic instance) 13 | { 14 | instance.CalledByAfterGiven.Add(GetType().Name); 15 | } 16 | 17 | public override void AfterSpec(ILikeMagic instance) 18 | { 19 | instance.CalledByAfterSpec.Add(GetType().Name); 20 | } 21 | 22 | public override void AfterTest(ILikeMagic instance) 23 | { 24 | instance.CalledByAfterTest.Add(GetType().Name); 25 | } 26 | 27 | public override void BeforeTest(ILikeMagic instance) 28 | { 29 | instance.CalledByBeforeTest.Add(GetType().Name); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ComposingContext/TestDomain/ProvideMagicByInterface.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core.Configuration; 2 | 3 | namespace SpecsFor.Lamar.Tests.ComposingContext.TestDomain; 4 | 5 | public class ProvideMagicByInterface : Behavior 6 | { 7 | public override void Given(ILikeMagic instance) 8 | { 9 | instance.CalledByDuringGiven.Add(GetType().Name); 10 | } 11 | 12 | public override void AfterGiven(ILikeMagic instance) 13 | { 14 | instance.CalledByAfterGiven.Add(GetType().Name); 15 | } 16 | 17 | public override void AfterSpec(ILikeMagic instance) 18 | { 19 | instance.CalledByAfterSpec.Add(GetType().Name); 20 | } 21 | 22 | public override void AfterTest(ILikeMagic instance) 23 | { 24 | instance.CalledByAfterTest.Add(GetType().Name); 25 | } 26 | 27 | public override void BeforeTest(ILikeMagic instance) 28 | { 29 | instance.CalledByBeforeTest.Add(GetType().Name); 30 | } 31 | } -------------------------------------------------------------------------------- /SpecsFor.ncrunchsolution: -------------------------------------------------------------------------------- 1 | 2 | 1 3 | True 4 | true 5 | true 6 | UseDynamicAnalysis 7 | UseStaticAnalysis 8 | UseStaticAnalysis 9 | UseStaticAnalysis 10 | Run all tests automatically:BFRydWU=;Run all tests manually:BUZhbHNl;Run impacted tests automatically, others manually (experimental!):CklzSW1wYWN0ZWQ=;Run pinned tests automatically, others manually:CElzUGlubmVk 11 | 12 | 13 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/ContainerConfiguration/ContainerConfigurationSpecs.cs: -------------------------------------------------------------------------------- 1 | using Beginners.Domain.MockingBasics; 2 | using NUnit.Framework; 3 | using Should; 4 | using SpecsFor; 5 | using StructureMap; 6 | 7 | namespace Beginners.ContainerConfiguration 8 | { 9 | public class ContainerConfigurationSpecs 10 | { 11 | public class when_a_concrete_type_is_registered_in_the_container : SpecsFor 12 | { 13 | private Car _car; 14 | 15 | protected override void ConfigureContainer(IContainer container) 16 | { 17 | container.Configure(cfg => 18 | { 19 | cfg.For().Use(); 20 | }); 21 | } 22 | 23 | protected override void When() 24 | { 25 | _car = SUT.BuildMuscleCar(); 26 | } 27 | 28 | [Test] 29 | public void then_the_cars_engine_was_made_by_the_real_engine_factory() 30 | { 31 | _car.Engine.Maker.ShouldEqual("Real Engines, Inc"); 32 | } 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/DummyDataProviderBehavior.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Conventions.Basics.Domain; 4 | using SpecsFor; 5 | using SpecsFor.Configuration; 6 | 7 | namespace Conventions.Basics 8 | { 9 | public interface INeedDummyData : ISpecs 10 | { 11 | IEnumerable Foos { get; set; } 12 | } 13 | 14 | public class DummyDataProviderBehavior : Behavior 15 | { 16 | public override void Given(INeedDummyData instance) 17 | { 18 | instance.Foos = new[] 19 | { 20 | new Foo {Id = Guid.NewGuid(), Name = "Foo 1"}, 21 | new Foo {Id = Guid.NewGuid(), Name = "Foo 2"}, 22 | new Foo {Id = Guid.NewGuid(), Name = "Foo 3"}, 23 | new Foo {Id = Guid.NewGuid(), Name = "Foo 4"}, 24 | new Foo {Id = Guid.NewGuid(), Name = "Foo 5"}, 25 | }; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap/StructureMapAutoMocker.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using SpecsFor.Core; 3 | 4 | namespace SpecsFor.StructureMap 5 | { 6 | public class StructureMapAutoMocker : IAutoMocker where TSut : class 7 | { 8 | public MoqAutoMocker MoqAutoMocker { get; } 9 | 10 | private readonly SpecsFor _specsFor; 11 | 12 | public StructureMapAutoMocker(ISpecs specsFor) 13 | { 14 | _specsFor = (SpecsFor)specsFor; 15 | 16 | MoqAutoMocker = new MoqAutoMocker(); 17 | } 18 | 19 | T IAutoMocker.CreateSUT() 20 | { 21 | return MoqAutoMocker.ClassUnderTest as T; 22 | } 23 | 24 | public Mock GetMockFor() where T : class 25 | { 26 | return Mock.Get(MoqAutoMocker.Get()); 27 | } 28 | 29 | public void ConfigureContainer() 30 | { 31 | _specsFor.ConfigureContainer(MoqAutoMocker.Container); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/MockingBasics/CarFactorySpecs.cs: -------------------------------------------------------------------------------- 1 | using Beginners.Domain.MockingBasics; 2 | using NUnit.Framework; 3 | using Should; 4 | using SpecsFor; 5 | 6 | namespace Beginners.MockingBasics 7 | { 8 | public class CarFactorySpecs 9 | { 10 | public class when_creating_a_muscle_car : SpecsFor 11 | { 12 | private Car _car; 13 | 14 | protected override void Given() 15 | { 16 | GetMockFor() 17 | .Setup(x => x.GetEngine("V8")) 18 | .Returns(new Engine()); 19 | } 20 | 21 | protected override void When() 22 | { 23 | _car = SUT.BuildMuscleCar(); 24 | } 25 | 26 | [Test] 27 | public void then_it_creates_a_car_with_an_engine() 28 | { 29 | _car.Engine.ShouldNotBeNull(); 30 | } 31 | 32 | [Test] 33 | public void then_it_calls_the_engine_factory() 34 | { 35 | GetMockFor() 36 | .Verify(x => x.GetEngine("V8")); 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/Specs/HelloSpecs.cs: -------------------------------------------------------------------------------- 1 | using Conventions.Basics.Domain; 2 | using NUnit.Framework; 3 | using Should; 4 | using SpecsFor; 5 | 6 | namespace Conventions.Basics.Specs 7 | { 8 | public class HelloSpecs 9 | { 10 | public class when_using_the_real_hello_service 11 | : SpecsFor, INeedRealHelloService 12 | { 13 | [Test] 14 | public void then_it_returns_the_real_string() 15 | { 16 | SUT.GetHelloMessage().ShouldEqual("Hello from HelloService!"); 17 | } 18 | } 19 | 20 | public class when_using_the_mock_hello_service 21 | : SpecsFor, INeedMockHelloService 22 | { 23 | [Test] 24 | public void then_it_returns_the_mock_string() 25 | { 26 | SUT.GetHelloMessage().ShouldEqual("Hello from Moq instance!"); 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac/AutofacAutoMocker.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using Autofac.Extras.Moq; 3 | using SpecsFor.Core; 4 | 5 | namespace SpecsFor.Autofac 6 | { 7 | public class AutofacAutoMocker : IAutoMocker where TSut : class 8 | { 9 | public AutoMock InternalMocker { get; private set; } 10 | 11 | private readonly SpecsFor _specsFor; 12 | 13 | public AutofacAutoMocker(ISpecs specsFor) 14 | { 15 | _specsFor = (SpecsFor)specsFor; 16 | 17 | InternalMocker = _specsFor.CreateInternalMocker(); 18 | } 19 | 20 | public TSut CreateSUT() where TSut : class 21 | { 22 | return InternalMocker.Create(); 23 | } 24 | 25 | public Mock GetMockFor() where T : class 26 | { 27 | return InternalMocker.Mock(); 28 | } 29 | 30 | public void ConfigureContainer() 31 | { 32 | _specsFor.ConfigureMocker(InternalMocker); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ComposingContext/TestDomain/DoNotProvideMagic.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core; 2 | using SpecsFor.Core.Configuration; 3 | 4 | namespace SpecsFor.StructureMap.Tests.ComposingContext.TestDomain 5 | { 6 | public class DoNotProvideMagic : Behavior 7 | { 8 | public override void Given(ISpecs instance) 9 | { 10 | ((ILikeMagic)instance).CalledByDuringGiven.Add(GetType().Name); 11 | } 12 | 13 | public override void AfterGiven(ISpecs instance) 14 | { 15 | ((ILikeMagic)instance).CalledByAfterGiven.Add(GetType().Name); 16 | } 17 | 18 | public override void AfterSpec(ISpecs instance) 19 | { 20 | ((ILikeMagic)instance).CalledByAfterSpec.Add(GetType().Name); 21 | } 22 | 23 | public override void AfterTest(ISpecs instance) 24 | { 25 | ((ILikeMagic)instance).CalledByAfterTest.Add(GetType().Name); 26 | } 27 | 28 | public override void BeforeTest(ISpecs instance) 29 | { 30 | ((ILikeMagic)instance).CalledByBeforeTest.Add(GetType().Name); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/PartialMatching/ShouldLookLikeSpecs.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using NUnit.Framework; 3 | using SpecsFor; 4 | using SpecsFor.ShouldExtensions; 5 | 6 | namespace Beginners.PartialMatching 7 | { 8 | public class ShouldLookLikeSpecs 9 | { 10 | public class when_partially_comparing_a_simple_object : SpecsFor 11 | { 12 | [Test] 13 | public void then_the_objects_are_equal_if_the_specified_properties_are_equal() 14 | { 15 | var person = new Person {FirstName = "John", LastName = "Smith"}; 16 | person.ShouldLookLike(() => new Person 17 | { 18 | LastName = "Smith" 19 | }); 20 | } 21 | 22 | [Test] 23 | public void then_the_objects_are_equal_if_the_matcher_is_satisfied() 24 | { 25 | var person = new Person { FirstName = "John", LastName = "Smith" }; 26 | person.ShouldLookLike(() => new Person 27 | { 28 | LastName = It.Is(s => s.StartsWith("S")) 29 | }); 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/Domain/OrderProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Demo.Domain 4 | { 5 | public class OrderProcessor 6 | { 7 | private readonly IInventory _inventory; 8 | private readonly IPublisher _publisher; 9 | 10 | public OrderProcessor(IInventory inventory, IPublisher publisher) 11 | { 12 | _inventory = inventory; 13 | _publisher = publisher; 14 | } 15 | 16 | public virtual OrderResult Process(Order order) 17 | { 18 | var result = new OrderResult(); 19 | 20 | if (order.Quantity < 0) 21 | { 22 | return result; 23 | } 24 | 25 | var available = _inventory.IsQuantityAvailable(order.PartNumber, order.Quantity); 26 | 27 | if (available) 28 | { 29 | result.WasAccepted = true; 30 | 31 | var orderNumber = Guid.NewGuid().ToString(); 32 | 33 | _publisher.Publish(new OrderSubmitted { OrderNumber = orderNumber }); 34 | 35 | result.OrderNumber = orderNumber; 36 | } 37 | 38 | return result; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ComposingContext/TestDomain/ProvideMagicByTypeName.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core; 2 | using SpecsFor.Core.Configuration; 3 | 4 | namespace SpecsFor.StructureMap.Tests.ComposingContext.TestDomain 5 | { 6 | public class ProvideMagicByTypeName : Behavior 7 | { 8 | public override void Given(ISpecs instance) 9 | { 10 | ((ILikeMagic)instance).CalledByDuringGiven.Add(GetType().Name); 11 | } 12 | 13 | public override void AfterGiven(ISpecs instance) 14 | { 15 | ((ILikeMagic)instance).CalledByAfterGiven.Add(GetType().Name); 16 | } 17 | 18 | public override void AfterSpec(ISpecs instance) 19 | { 20 | ((ILikeMagic)instance).CalledByAfterSpec.Add(GetType().Name); 21 | } 22 | 23 | public override void AfterTest(ISpecs instance) 24 | { 25 | ((ILikeMagic)instance).CalledByAfterTest.Add(GetType().Name); 26 | } 27 | 28 | public override void BeforeTest(ISpecs instance) 29 | { 30 | ((ILikeMagic)instance).CalledByBeforeTest.Add(GetType().Name); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp.Specs/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /SpecsFor.Demo/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Helpers/BootstrapHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | using System.Web.Mvc; 4 | using HtmlTags; 5 | using Microsoft.Web.Mvc; 6 | 7 | namespace SpecsForWebHelpers.Web.Helpers 8 | { 9 | public static class BootstrapHelpers 10 | { 11 | public static HtmlTag BootstrapButton( 12 | this HtmlHelper helper, string text) 13 | { 14 | return new HtmlTag("button") 15 | .Attr("type", "submit") 16 | .AddClasses("btn", "btn-primary") 17 | .Text(text); 18 | } 19 | 20 | public static HtmlTag BootstrapActionLinkButton( 21 | this HtmlHelper helper, 22 | Expression> action, 23 | string label) 24 | where TController : Controller 25 | { 26 | var targetUrl = helper.BuildUrlFromExpression(action); 27 | var tag = new HtmlTag("a"); 28 | tag.Attr("href", targetUrl); 29 | tag.AddClasses("btn", "btn-primary"); 30 | tag.Text(label); 31 | 32 | return tag; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ComposingContext/TestDomain/DoNotProvideMagic.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core; 2 | using SpecsFor.Core.Configuration; 3 | 4 | namespace SpecsFor.Lamar.Tests.ComposingContext.TestDomain; 5 | 6 | public class DoNotProvideMagic : Behavior 7 | { 8 | public override void Given(ISpecs instance) 9 | { 10 | ((ILikeMagic)instance).CalledByDuringGiven.Add(GetType().Name); 11 | } 12 | 13 | public override void AfterGiven(ISpecs instance) 14 | { 15 | ((ILikeMagic)instance).CalledByAfterGiven.Add(GetType().Name); 16 | } 17 | 18 | public override void AfterSpec(ISpecs instance) 19 | { 20 | ((ILikeMagic)instance).CalledByAfterSpec.Add(GetType().Name); 21 | } 22 | 23 | public override void AfterTest(ISpecs instance) 24 | { 25 | ((ILikeMagic)instance).CalledByAfterTest.Add(GetType().Name); 26 | } 27 | 28 | public override void BeforeTest(ISpecs instance) 29 | { 30 | ((ILikeMagic)instance).CalledByBeforeTest.Add(GetType().Name); 31 | } 32 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ComposingContext/TestDomain/Widget.cs: -------------------------------------------------------------------------------- 1 | namespace SpecsFor.Lamar.Tests.ComposingContext.TestDomain; 2 | 3 | public class Widget : ILikeMagic 4 | { 5 | public List CalledByDuringGiven { get; set; } 6 | public List CalledByAfterGiven { get; set; } 7 | public List CalledByAfterSpec { get; set; } 8 | public List CalledByAfterTest { get; set; } 9 | public List CalledByBeforeTest { get; set; } 10 | public List CalledByApplyAfterClassUnderTestInitialized { get; set; } 11 | public List CalledBySpecInit { get; set; } 12 | 13 | public Widget() 14 | { 15 | CalledBySpecInit = new List(); 16 | CalledByApplyAfterClassUnderTestInitialized = new List(); 17 | CalledByDuringGiven = new List(); 18 | CalledByAfterGiven = new List(); 19 | CalledByAfterSpec = new List(); 20 | CalledByAfterTest = new List(); 21 | CalledByBeforeTest = new List(); 22 | } 23 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ComposingContext/TestDomain/ProvideMagicByTypeName.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core; 2 | using SpecsFor.Core.Configuration; 3 | 4 | namespace SpecsFor.Lamar.Tests.ComposingContext.TestDomain; 5 | 6 | public class ProvideMagicByTypeName : Behavior 7 | { 8 | public override void Given(ISpecs instance) 9 | { 10 | ((ILikeMagic)instance).CalledByDuringGiven.Add(GetType().Name); 11 | } 12 | 13 | public override void AfterGiven(ISpecs instance) 14 | { 15 | ((ILikeMagic)instance).CalledByAfterGiven.Add(GetType().Name); 16 | } 17 | 18 | public override void AfterSpec(ISpecs instance) 19 | { 20 | ((ILikeMagic)instance).CalledByAfterSpec.Add(GetType().Name); 21 | } 22 | 23 | public override void AfterTest(ISpecs instance) 24 | { 25 | ((ILikeMagic)instance).CalledByAfterTest.Add(GetType().Name); 26 | } 27 | 28 | public override void BeforeTest(ISpecs instance) 29 | { 30 | ((ILikeMagic)instance).CalledByBeforeTest.Add(GetType().Name); 31 | } 32 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ComposingContext/TestDomain/ProvideMagicByConcreteType.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core.Configuration; 2 | 3 | namespace SpecsFor.StructureMap.Tests.ComposingContext.TestDomain 4 | { 5 | public class ProvideMagicByConcreteType : Behavior> 6 | { 7 | public override void Given(SpecsFor instance) 8 | { 9 | ((ILikeMagic)instance).CalledByDuringGiven.Add(GetType().Name); 10 | } 11 | 12 | public override void AfterGiven(SpecsFor instance) 13 | { 14 | ((ILikeMagic)instance).CalledByAfterGiven.Add(GetType().Name); 15 | } 16 | 17 | public override void AfterSpec(SpecsFor instance) 18 | { 19 | ((ILikeMagic)instance).CalledByAfterSpec.Add(GetType().Name); 20 | } 21 | 22 | public override void AfterTest(SpecsFor instance) 23 | { 24 | ((ILikeMagic)instance).CalledByAfterTest.Add(GetType().Name); 25 | } 26 | 27 | public override void BeforeTest(SpecsFor instance) 28 | { 29 | ((ILikeMagic)instance).CalledByBeforeTest.Add(GetType().Name); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ComposingContext/TestDomain/Widget.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace SpecsFor.StructureMap.Tests.ComposingContext.TestDomain 4 | { 5 | public class Widget : ILikeMagic 6 | { 7 | public List CalledByDuringGiven { get; set; } 8 | public List CalledByAfterGiven { get; set; } 9 | public List CalledByAfterSpec { get; set; } 10 | public List CalledByAfterTest { get; set; } 11 | public List CalledByBeforeTest { get; set; } 12 | public List CalledByApplyAfterClassUnderTestInitialized { get; set; } 13 | public List CalledBySpecInit { get; set; } 14 | 15 | public Widget() 16 | { 17 | CalledBySpecInit = new List(); 18 | CalledByApplyAfterClassUnderTestInitialized = new List(); 19 | CalledByDuringGiven = new List(); 20 | CalledByAfterGiven = new List(); 21 | CalledByAfterSpec = new List(); 22 | CalledByAfterTest = new List(); 23 | CalledByBeforeTest = new List(); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/SimpleSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Should; 3 | using SpecsFor; 4 | 5 | namespace Beginners 6 | { 7 | public class SimpleSpecs 8 | { 9 | public class WidgetFactory 10 | { 11 | public Widget CreateWidget(string color, int size) 12 | { 13 | return new Widget 14 | { 15 | Color = color, 16 | Size = size 17 | }; 18 | } 19 | } 20 | 21 | public class Widget 22 | { 23 | public string Color { get; set; } 24 | public int Size { get; set; } 25 | } 26 | 27 | public class when_creating_a_widget : SpecsFor 28 | { 29 | private Widget _widget; 30 | 31 | protected override void When() 32 | { 33 | _widget = SUT.CreateWidget(color: "Red", size: 500); 34 | } 35 | 36 | [Test] 37 | public void then_it_sets_the_color() 38 | { 39 | _widget.Color.ShouldEqual("Red"); 40 | } 41 | 42 | [Test] 43 | public void then_it_sets_the_size() 44 | { 45 | _widget.Size.ShouldEqual(500); 46 | } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ComposingContext/TestDomain/ProvideMagicByConcreteType.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core.Configuration; 2 | 3 | namespace SpecsFor.Lamar.Tests.ComposingContext.TestDomain; 4 | 5 | public class ProvideMagicByConcreteType : Behavior> 6 | { 7 | public override void Given(SpecsFor instance) 8 | { 9 | ((ILikeMagic)instance).CalledByDuringGiven.Add(GetType().Name); 10 | } 11 | 12 | public override void AfterGiven(SpecsFor instance) 13 | { 14 | ((ILikeMagic)instance).CalledByAfterGiven.Add(GetType().Name); 15 | } 16 | 17 | public override void AfterSpec(SpecsFor instance) 18 | { 19 | ((ILikeMagic)instance).CalledByAfterSpec.Add(GetType().Name); 20 | } 21 | 22 | public override void AfterTest(SpecsFor instance) 23 | { 24 | ((ILikeMagic)instance).CalledByAfterTest.Add(GetType().Name); 25 | } 26 | 27 | public override void BeforeTest(SpecsFor instance) 28 | { 29 | ((ILikeMagic)instance).CalledByBeforeTest.Add(GetType().Name); 30 | } 31 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/GivenWhenThen/GivenWhenThenExampleSpecs.cs: -------------------------------------------------------------------------------- 1 | using Beginners.Domain.MockingBasics; 2 | using NUnit.Framework; 3 | using Should; 4 | using SpecsFor; 5 | 6 | namespace Beginners.GivenWhenThen 7 | { 8 | public class GivenWhenThenExampleSpecs 9 | { 10 | public class given_a_car_is_started_when_a_car_is_stopped : SpecsFor 11 | { 12 | protected override void Given() 13 | { 14 | //Given: establish state, in this case, that the car is started. 15 | SUT.Start(); 16 | } 17 | 18 | protected override void When() 19 | { 20 | //When: perform an action, in this case, stopping the car. 21 | SUT.Stop(); 22 | } 23 | 24 | //Note that there can be (and usually are) multiple 'Then' test cases. 25 | [Test] 26 | public void then_the_car_is_stopped() 27 | { 28 | //Then: the car is stopped. 29 | SUT.IsStopped.ShouldBeTrue(); 30 | } 31 | 32 | [Test] 33 | public void then_the_engine_is_stopped() 34 | { 35 | //Then: the engine is stopped. 36 | SUT.Engine.IsStopped.ShouldBeTrue(); 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ComposingContext/StackingContext/StackingContextConfig.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Autofac.Tests.ComposingContext.TestDomain; 3 | using SpecsFor.Core.Configuration; 4 | 5 | namespace SpecsFor.Autofac.Tests.ComposingContext.StackingContext 6 | { 7 | [SetUpFixture] 8 | public class StackingContextConfig : SpecsForConfiguration 9 | { 10 | public StackingContextConfig() 11 | { 12 | WhenTesting().EnrichWith(); 13 | } 14 | } 15 | 16 | public class NestedMagicProvider : Behavior 17 | { 18 | public override void Given(ILikeMagic instance) 19 | { 20 | instance.CalledByDuringGiven.Add(this.GetType().Name); 21 | } 22 | 23 | public override void AfterSpec(ILikeMagic instance) 24 | { 25 | instance.CalledByAfterSpec.Add(this.GetType().Name); 26 | } 27 | 28 | public override void AfterTest(ILikeMagic instance) 29 | { 30 | instance.CalledByAfterTest.Add(this.GetType().Name); 31 | } 32 | 33 | public override void BeforeTest(ILikeMagic instance) 34 | { 35 | instance.CalledByBeforeTest.Add(this.GetType().Name); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2011-2013 Matt Honeycutt - http://trycatchfail.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ComposingContext/TestDomain/ProvideMagicForEveryone.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core; 2 | using SpecsFor.Core.Configuration; 3 | 4 | namespace SpecsFor.Autofac.Tests.ComposingContext.TestDomain 5 | { 6 | public class ProvideMagicForEveryone : Behavior 7 | { 8 | public override void Given(ISpecs instance) 9 | { 10 | ((ILikeMagic) instance).CalledByDuringGiven.Add(GetType().Name); 11 | } 12 | 13 | public override void AfterSpec(ISpecs instance) 14 | { 15 | ((ILikeMagic)instance).CalledByAfterSpec.Add(GetType().Name); 16 | } 17 | 18 | public override void AfterTest(ISpecs instance) 19 | { 20 | ((ILikeMagic)instance).CalledByAfterTest.Add(GetType().Name); 21 | } 22 | 23 | public override void BeforeTest(ISpecs instance) 24 | { 25 | ((ILikeMagic)instance).CalledByBeforeTest.Add(GetType().Name); 26 | } 27 | 28 | public override void ClassUnderTestInitialized(ISpecs instance) 29 | { 30 | ((ILikeMagic)instance).CalledByApplyAfterClassUnderTestInitialized.Add(GetType().Name); 31 | } 32 | 33 | public override void SpecInit(ISpecs instance) 34 | { 35 | ((ILikeMagic)instance).CalledBySpecInit.Add(GetType().Name); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ShouldExtensions/ContainsExtensionsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.ShouldExtensions; 3 | 4 | namespace SpecsFor.Autofac.Tests.ShouldExtensions 5 | { 6 | public class ContainsExtensionsSpecs : SpecsFor 7 | { 8 | protected override void InitializeClassUnderTest() 9 | { 10 | SUT = new[] { "Test 1", "Test 2", "Test 3" }; 11 | } 12 | 13 | [Test] 14 | public void ShouldContains_does_not_throw_if_list_contains_matching_item() 15 | { 16 | Assert.DoesNotThrow(() => SUT.ShouldContain(s => s.EndsWith("2"))); 17 | } 18 | 19 | [Test] 20 | public void ShouldNotContains_throws_if_list_contains_matching_item() 21 | { 22 | Assert.Throws(() => SUT.ShouldNotContain(s => s.EndsWith("2"))); 23 | } 24 | 25 | [Test] 26 | public void ShouldContains_throws_if_list_does_not_contain_matching_item() 27 | { 28 | Assert.Throws(() => SUT.ShouldContain(s => s.EndsWith("98"))); 29 | } 30 | 31 | [Test] 32 | public void ShouldNotContains_does_not_throw_if_list_does_not_contain_matching_item() 33 | { 34 | Assert.DoesNotThrow(() => SUT.ShouldNotContain(s => s.EndsWith("98"))); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Specs/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ResharperTemplates/SpecsFor.Templates.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SpecsFor.Templates 5 | SpecsFor File & Live Templates 6 | 1.0.0 7 | Matt Honeycutt 8 | Matt Honeycutt 9 | https://github.com/MattHoneycutt/SpecsFor/blob/master/LICENSE.md 10 | http://specsfor.com/ 11 | false 12 | File and live templates for use with the SpecsFor testing framework. 13 | • Initial release! 14 | resharper specsfor testing 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ShouldExtensions/ContainsExtensionsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.ShouldExtensions; 3 | 4 | namespace SpecsFor.StructureMap.Tests.ShouldExtensions 5 | { 6 | public class ContainsExtensionsSpecs : SpecsFor 7 | { 8 | protected override void InitializeClassUnderTest() 9 | { 10 | SUT = new[] { "Test 1", "Test 2", "Test 3" }; 11 | } 12 | 13 | [Test] 14 | public void ShouldContains_does_not_throw_if_list_contains_matching_item() 15 | { 16 | Assert.DoesNotThrow(() => SUT.ShouldContain(s => s.EndsWith("2"))); 17 | } 18 | 19 | [Test] 20 | public void ShouldNotContains_throws_if_list_contains_matching_item() 21 | { 22 | Assert.Throws(() => SUT.ShouldNotContain(s => s.EndsWith("2"))); 23 | } 24 | 25 | [Test] 26 | public void ShouldContains_throws_if_list_does_not_contain_matching_item() 27 | { 28 | Assert.Throws(() => SUT.ShouldContain(s => s.EndsWith("98"))); 29 | } 30 | 31 | [Test] 32 | public void ShouldNotContains_does_not_throw_if_list_does_not_contain_matching_item() 33 | { 34 | Assert.DoesNotThrow(() => SUT.ShouldNotContain(s => s.EndsWith("98"))); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ShouldExtensions/ContainsExtensionsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.ShouldExtensions; 3 | 4 | namespace SpecsFor.Lamar.Tests.ShouldExtensions; 5 | 6 | public class ContainsExtensionsSpecs : SpecsFor 7 | { 8 | protected override void InitializeClassUnderTest() 9 | { 10 | SUT = new[] { "Test 1", "Test 2", "Test 3" }; 11 | } 12 | 13 | [Test] 14 | public void ShouldContains_does_not_throw_if_list_contains_matching_item() 15 | { 16 | Assert.DoesNotThrow(() => SUT.ShouldContain(s => s.EndsWith("2"))); 17 | } 18 | 19 | [Test] 20 | public void ShouldNotContains_throws_if_list_contains_matching_item() 21 | { 22 | Assert.Throws(() => SUT.ShouldNotContain(s => s.EndsWith("2"))); 23 | } 24 | 25 | [Test] 26 | public void ShouldContains_throws_if_list_does_not_contain_matching_item() 27 | { 28 | Assert.Throws(() => SUT.ShouldContain(s => s.EndsWith("98"))); 29 | } 30 | 31 | [Test] 32 | public void ShouldNotContains_does_not_throw_if_list_does_not_contain_matching_item() 33 | { 34 | Assert.DoesNotThrow(() => SUT.ShouldNotContain(s => s.EndsWith("98"))); 35 | } 36 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/App_Start/BundleConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Optimization; 3 | 4 | namespace WindowsAuthSampleApp 5 | { 6 | public class BundleConfig 7 | { 8 | // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 9 | public static void RegisterBundles(BundleCollection bundles) 10 | { 11 | bundles.Add(new ScriptBundle("~/bundles/jquery").Include( 12 | "~/Scripts/jquery-{version}.js")); 13 | 14 | bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( 15 | "~/Scripts/jquery.validate*")); 16 | 17 | // Use the development version of Modernizr to develop with and learn from. Then, when you're 18 | // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. 19 | bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( 20 | "~/Scripts/modernizr-*")); 21 | 22 | bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( 23 | "~/Scripts/bootstrap.js", 24 | "~/Scripts/respond.js")); 25 | 26 | bundles.Add(new StyleBundle("~/Content/css").Include( 27 | "~/Content/bootstrap.css", 28 | "~/Content/site.css")); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /SpecsFor.Core/ShouldExtensions/ContainsExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using NUnit.Framework; 6 | 7 | namespace SpecsFor.Core.ShouldExtensions 8 | { 9 | public static class ContainsExtensions 10 | { 11 | public static void ShouldContain(this IEnumerable list, Expression> filter) 12 | { 13 | if (list.Count(filter.Compile()) == 0) 14 | { 15 | Assert.Fail("Expected list containing item matching {0}, but item was not found.", filter); 16 | } 17 | } 18 | 19 | public static void ShouldNotContain(this IEnumerable list, Expression> filter) 20 | { 21 | if (list.Any(filter.Compile())) 22 | { 23 | Assert.Fail("Expected list not containing item matching {0}, but found a matching item.", filter); 24 | } 25 | } 26 | 27 | public static bool ContainsMatch(this IEnumerable list, Expression> initializer) where T : class 28 | { 29 | if (list == null) return false; 30 | 31 | foreach (var item in list) 32 | { 33 | if (item.LooksLike(initializer)) 34 | return true; 35 | } 36 | 37 | return false; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /SpecsFor.Core/ShouldExtensions/Looks.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | using ExpectedObjects; 4 | using Moq; 5 | 6 | namespace SpecsFor.Core.ShouldExtensions 7 | { 8 | public static class Looks 9 | { 10 | public static T Like(T obj) 11 | { 12 | var expected = obj.ToExpectedObject(); 13 | return It.Is(t => expected.Equals(t)); 14 | } 15 | 16 | public static T Like(Expression> initializer) where T : class 17 | { 18 | return It.Is(t => ShouldMatch(initializer, t)); 19 | } 20 | 21 | 22 | public static T LikePartialOf(object partial) 23 | { 24 | var expected = partial.ToExpectedObject(); 25 | 26 | return It.Is(t => ShouldMatch(expected, t)); 27 | } 28 | 29 | private static bool ShouldMatch(Expression> initializer, T o) where T : class 30 | { 31 | try 32 | { 33 | o.ShouldLookLike(initializer); 34 | } 35 | catch (Exception) 36 | { 37 | return false; 38 | } 39 | 40 | return true; 41 | } 42 | 43 | private static bool ShouldMatch(ExpectedObject expected, object o) 44 | { 45 | try 46 | { 47 | expected.ShouldMatch(o); 48 | return true; 49 | } 50 | catch (Exception) 51 | { 52 | return false; 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /SpecsFor.Core/SpecificationException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace SpecsFor.Core 5 | { 6 | public class SpecificationException : ApplicationException 7 | { 8 | protected SpecificationException(string stage, Exception[] exceptions) 9 | : base("An error occurred during the spec '" + stage + "' phase. \r\n" + BuildMessage(exceptions)) 10 | { 11 | Exceptions = exceptions; 12 | } 13 | 14 | private static string BuildMessage(Exception[] exceptions) 15 | { 16 | var result = new StringBuilder(); 17 | 18 | foreach (var exception in exceptions) 19 | { 20 | result.AppendLine("--------------------------------------------------------------------"); 21 | result.Append(exception).AppendLine(); 22 | } 23 | 24 | return result.ToString(); 25 | } 26 | 27 | public Exception[] Exceptions { get; private set; } 28 | 29 | public override string ToString() 30 | { 31 | var result = new StringBuilder(); 32 | 33 | result.AppendLine(base.ToString()); 34 | 35 | foreach (var exception in Exceptions) 36 | { 37 | result.AppendLine("--------------------------------------------------------------------"); 38 | result.Append(exception).AppendLine(); 39 | } 40 | 41 | return result.ToString(); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ShouldExtensions/EnumerableExtensionsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.ShouldExtensions; 3 | 4 | namespace SpecsFor.Lamar.Tests.ShouldExtensions; 5 | 6 | public class EnumerableExtensionsSpecs 7 | { 8 | public class when_checking_for_ascending_lists : SpecsFor 9 | { 10 | [Test] 11 | public void then_it_does_not_throw_for_ascending_lists() 12 | { 13 | Assert.DoesNotThrow(() => new[] { 1,2,3,4}.ShouldBeAscending()); 14 | } 15 | 16 | [Test] 17 | public void then_it_throws_for_lists_that_are_not_ascending() 18 | { 19 | Assert.Throws(() => new[] { 1,1,3,4}.ShouldBeAscending()); 20 | } 21 | } 22 | 23 | public class when_checking_for_descending_lists : SpecsFor 24 | { 25 | [Test] 26 | public void then_it_does_not_throw_for_descending_lists() 27 | { 28 | Assert.DoesNotThrow(() => new[] { 4,3,2,1 }.ShouldBeDescending()); 29 | } 30 | 31 | [Test] 32 | public void then_it_throws_for_lists_that_are_not_descending() 33 | { 34 | Assert.Throws(() => new[] { 4,4,3,2}.ShouldBeAscending()); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ComposingContext/StackingContext/StackingContextConfig.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.Configuration; 3 | using SpecsFor.StructureMap.Tests.ComposingContext.TestDomain; 4 | 5 | namespace SpecsFor.StructureMap.Tests.ComposingContext.StackingContext 6 | { 7 | [SetUpFixture] 8 | public class StackingContextConfig : SpecsForConfiguration 9 | { 10 | public StackingContextConfig() 11 | { 12 | WhenTesting().EnrichWith(); 13 | } 14 | } 15 | 16 | public class NestedMagicProvider : Behavior 17 | { 18 | public override void Given(ILikeMagic instance) 19 | { 20 | instance.CalledByDuringGiven.Add(this.GetType().Name); 21 | } 22 | 23 | public override void AfterGiven(ILikeMagic instance) 24 | { 25 | instance.CalledByAfterGiven.Add(this.GetType().Name); 26 | } 27 | 28 | public override void AfterSpec(ILikeMagic instance) 29 | { 30 | instance.CalledByAfterSpec.Add(this.GetType().Name); 31 | } 32 | 33 | public override void AfterTest(ILikeMagic instance) 34 | { 35 | instance.CalledByAfterTest.Add(this.GetType().Name); 36 | } 37 | 38 | public override void BeforeTest(ILikeMagic instance) 39 | { 40 | instance.CalledByBeforeTest.Add(this.GetType().Name); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/PartialMatching/PartialMatchingWithSome.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor; 3 | using SpecsFor.ShouldExtensions; 4 | 5 | namespace Beginners.PartialMatching 6 | { 7 | public class PartialMatchingWithSome 8 | { 9 | public class when_using_some_compare_properties : SpecsFor 10 | { 11 | [Test] 12 | public void then_it_passes_if_the_property_matches_the_expectation() 13 | { 14 | var train = new TrainCar {MaxPassengers = 123}; 15 | 16 | train.ShouldLookLike(() => new TrainCar 17 | { 18 | MaxPassengers = Some.ValueOf(x => x > 100) 19 | }); 20 | } 21 | 22 | [Test] 23 | public void then_it_passes_if_the_property_falls_within_the_expected_range() 24 | { 25 | var train = new TrainCar {MaxPassengers = 123}; 26 | 27 | train.ShouldLookLike(() => new TrainCar 28 | { 29 | MaxPassengers = Some.ValueInRange(120, 130) 30 | }); 31 | } 32 | 33 | [Test] 34 | public void then_it_throws_if_the_property_falls_outside_the_range() 35 | { 36 | var train = new TrainCar { MaxPassengers = 123 }; 37 | 38 | train.ShouldLookLike(() => new TrainCar 39 | { 40 | MaxPassengers = Some.ValueInRange(100, 120) 41 | }); 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac/SpecsFor.Autofac.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SpecsFor.Autofac 5 | 8.0.0-rc1a 6 | Matt Honeycutt 7 | Heroic Applications 8 | 9 | https://github.com/MattHoneycutt/SpecsFor/blob/master/LICENSE.md 10 | http://specsfor.com 11 | http://specsfor.com/images/specsfor-icon-128x128.png 12 | SpecsFor is another Behavior-Driven Development framework that focuses on ease of use for *developers* by minimizing testing friction. 13 | 14 | Package updates. 15 | 16 | Copyright 2025 17 | TDD;Testing;BDD;Test Driven Development;NET Core;NUnit 18 | 19 | 20 | 21 | net6.0 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ComposingContext/StackingContext/StackingContextConfig.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.Configuration; 3 | using SpecsFor.Lamar.Tests.ComposingContext.TestDomain; 4 | 5 | namespace SpecsFor.Lamar.Tests.ComposingContext.StackingContext; 6 | 7 | [SetUpFixture] 8 | public class StackingContextConfig : SpecsForConfiguration 9 | { 10 | public StackingContextConfig() 11 | { 12 | WhenTesting().EnrichWith(); 13 | } 14 | } 15 | 16 | public class NestedMagicProvider : Behavior 17 | { 18 | public override void Given(ILikeMagic instance) 19 | { 20 | instance.CalledByDuringGiven.Add(this.GetType().Name); 21 | } 22 | 23 | public override void AfterGiven(ILikeMagic instance) 24 | { 25 | instance.CalledByAfterGiven.Add(this.GetType().Name); 26 | } 27 | 28 | public override void AfterSpec(ILikeMagic instance) 29 | { 30 | instance.CalledByAfterSpec.Add(this.GetType().Name); 31 | } 32 | 33 | public override void AfterTest(ILikeMagic instance) 34 | { 35 | instance.CalledByAfterSpec.Add(this.GetType().Name); 36 | } 37 | 38 | public override void BeforeTest(ILikeMagic instance) 39 | { 40 | instance.CalledByBeforeTest.Add(this.GetType().Name); 41 | } 42 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap/SpecsFor.StructureMap.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SpecsFor.StructureMap 5 | 8.0.0-rc1a 6 | Matt Honeycutt 7 | Heroic Applications 8 | 9 | https://github.com/MattHoneycutt/SpecsFor/blob/master/LICENSE.md 10 | http://specsfor.com 11 | http://specsfor.com/images/specsfor-icon-128x128.png 12 | SpecsFor is another Behavior-Driven Development framework that focuses on ease of use for *developers* by minimizing testing friction. 13 | 14 | Package updates. 15 | 16 | Copyright 2025 17 | TDD;Testing;BDD;Test Driven Development;NET Core;NUnit 18 | 19 | 20 | 21 | net6.0 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /metapackage/specsfor-metapackage.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SpecsFor 5 | 8.0.0-rc1a 6 | Matt Honeycutt 7 | Matt Honeycutt 8 | https://github.com/MattHoneycutt/SpecsFor/blob/master/LICENSE.md 9 | http://specsfor.com/ 10 | http://specsfor.com/images/specsfor-icon-128x128.png 11 | 12 | SpecsFor is another Behavior-Driven Development framework that focuses on ease of use for *developers* by minimizing testing friction. 13 | This is package simply forwards to SpecsFor.StructureMap for backwards compatibility. 14 | 15 | 16 | See updates for SpecsFor.StructureMap for details. 17 | 18 | docs\README.md 19 | Copyright 2025 20 | TDD;Testing;BDD;Test Driven Development;NET Core;NUnit 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /SpecsFor.Lamar/SpecsFor.Lamar.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SpecsFor.Lamar 5 | 8.0.0-rc1a 6 | Matt Honeycutt 7 | Heroic Applications 8 | 9 | https://github.com/MattHoneycutt/SpecsFor/blob/master/LICENSE.md 10 | http://specsfor.com 11 | http://specsfor.com/images/specsfor-icon-128x128.png 12 | SpecsFor is another Behavior-Driven Development framework that focuses on ease of use for *developers* by minimizing testing friction. 13 | 14 | Initial release of Lamar support! 15 | 16 | Copyright 2025 17 | TDD;Testing;BDD;Test Driven Development;NET Core;NUnit 18 | 19 | 20 | 21 | 22 | net6.0 23 | enable 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ComposingContext/TestDomain/ProvideMagicForEveryone.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core; 2 | using SpecsFor.Core.Configuration; 3 | 4 | namespace SpecsFor.StructureMap.Tests.ComposingContext.TestDomain 5 | { 6 | public class ProvideMagicForEveryone : Behavior 7 | { 8 | public override void Given(ISpecs instance) 9 | { 10 | ((ILikeMagic) instance).CalledByDuringGiven.Add(GetType().Name); 11 | } 12 | 13 | public override void AfterGiven(ISpecs instance) 14 | { 15 | ((ILikeMagic) instance).CalledByAfterGiven.Add(GetType().Name); 16 | } 17 | 18 | public override void AfterSpec(ISpecs instance) 19 | { 20 | ((ILikeMagic)instance).CalledByAfterSpec.Add(GetType().Name); 21 | } 22 | 23 | public override void AfterTest(ISpecs instance) 24 | { 25 | ((ILikeMagic)instance).CalledByAfterTest.Add(GetType().Name); 26 | } 27 | 28 | public override void BeforeTest(ISpecs instance) 29 | { 30 | ((ILikeMagic)instance).CalledByBeforeTest.Add(GetType().Name); 31 | } 32 | 33 | public override void ClassUnderTestInitialized(ISpecs instance) 34 | { 35 | ((ILikeMagic)instance).CalledByApplyAfterClassUnderTestInitialized.Add(GetType().Name); 36 | } 37 | 38 | public override void SpecInit(ISpecs instance) 39 | { 40 | ((ILikeMagic)instance).CalledBySpecInit.Add(GetType().Name); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | using Microsoft.Web.Mvc; 3 | using SpecsForWebHelpers.Web.Domain; 4 | using SpecsForWebHelpers.Web.Models; 5 | 6 | namespace SpecsForWebHelpers.Web.Controllers 7 | { 8 | public class HomeController : Controller 9 | { 10 | private readonly ICurrentUser _currentUser; 11 | 12 | public HomeController(ICurrentUser currentUser) 13 | { 14 | _currentUser = currentUser; 15 | } 16 | 17 | public ActionResult Index() 18 | { 19 | return View(); 20 | } 21 | 22 | public ActionResult SetName() 23 | { 24 | return View(); 25 | } 26 | 27 | [HttpPost] 28 | public ActionResult SetName(string name) 29 | { 30 | if (string.IsNullOrEmpty(name)) 31 | { 32 | ViewBag.Error = "You must specify a name!"; 33 | return View(); 34 | } 35 | 36 | _currentUser.SetName(name); 37 | 38 | return RedirectToAction("Index", "Home"); 39 | } 40 | 41 | public ActionResult SayHello(string name) 42 | { 43 | var model = new SayHelloViewModel 44 | { 45 | Name = name 46 | }; 47 | 48 | return View(model); 49 | } 50 | 51 | [HttpPost] 52 | public ActionResult SayHello(SayHelloForm form) 53 | { 54 | return this.RedirectToAction(c => c.SayHello(form.Name)); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/OldSchoolTests/OrderProcessorSpecs.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using NUnit.Framework; 3 | using Should; 4 | using SpecsFor.Demo.Domain; 5 | 6 | namespace SpecsFor.Demo.OldSchoolTests 7 | { 8 | public class OrderProcessorSpecs : SpecsFor 9 | { 10 | [Test] 11 | public void Order_submitted_successfully_Tests() 12 | { 13 | GetMockFor() 14 | .Setup(i => i.IsQuantityAvailable("TestPart", 10)) 15 | .Returns(true) 16 | .Verifiable(); 17 | 18 | var result = SUT.Process(new Order {PartNumber = "TestPart", Quantity = 10}); 19 | 20 | result.WasAccepted.ShouldBeTrue(); 21 | 22 | GetMockFor().Verify(); 23 | 24 | GetMockFor() 25 | .Verify(p => p.Publish(It.Is(o => o.OrderNumber == result.OrderNumber))); 26 | } 27 | 28 | [Test] 29 | public void Order_is_rejected_Tests() 30 | { 31 | GetMockFor() 32 | .Setup(i => i.IsQuantityAvailable("TestPart", 10)) 33 | .Returns(false) 34 | .Verifiable(); 35 | 36 | var result = SUT.Process(new Order {PartNumber = "TestPart", Quantity = 10}); 37 | 38 | result.WasAccepted.ShouldBeFalse(); 39 | 40 | GetMockFor().Verify(); 41 | 42 | GetMockFor() 43 | .Verify(p => p.Publish(It.IsAny()), Times.Never()); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /ResharperTemplates/SpecsFor.Templates.Resharper9.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SpecsFor.Templates.R90 5 | SpecsFor File & Live Templates for Resharper 9 6 | 1.0.5 7 | Matt Honeycutt 8 | Matt Honeycutt 9 | https://github.com/MattHoneycutt/SpecsFor/blob/master/LICENSE.md 10 | http://specsfor.com/ 11 | http://specsfor.com/images/specsfor-icon-128x128.png 12 | false 13 | File and live templates for use with the SpecsFor testing framework. 14 | • Updated for ReSharper 9.1! 15 | resharper specsfor testing 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/PartialMatching/LooksLikeSpecs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Moq; 3 | using NUnit.Framework; 4 | using SpecsFor; 5 | using SpecsFor.ShouldExtensions; 6 | 7 | namespace Beginners.PartialMatching 8 | { 9 | public class LooksLikeSpecs 10 | { 11 | public class when_verifying_with_a_partial_object : SpecsFor 12 | { 13 | [Test] 14 | public void then_it_verifies_correctly_if_the_object_matches_the_specified_properties() 15 | { 16 | var myCar = new TrainCar {Name = "Simple Car", MaxPassengers = 100, YearBuilt = 2014}; 17 | 18 | GetMockFor().Object 19 | .StoreCar(myCar); 20 | 21 | GetMockFor() 22 | .Verify(x => x.StoreCar(Looks.Like(() => new TrainCar{YearBuilt = 2014}))); 23 | } 24 | 25 | [Test] 26 | public void then_it_verifies_correctly_if_the_matcher_is_satisfied() 27 | { 28 | GetMockFor().Object 29 | .RetrieveLuggage(new LuggageTicket 30 | { 31 | IssuedTo = "Jane Doe", 32 | Issued = DateTime.Now, 33 | }); 34 | 35 | GetMockFor() 36 | .Verify(x => x.RetrieveLuggage(Looks.Like(() => new LuggageTicket 37 | { 38 | IssuedTo = "Jane Doe", 39 | Issued = Some.ValueOf(d => DateTime.Now.Subtract(d) < TimeSpan.FromSeconds(1)) 40 | }))); 41 | } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ShouldExtensions/EnumerableExtensionsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.ShouldExtensions; 3 | 4 | namespace SpecsFor.Autofac.Tests.ShouldExtensions 5 | { 6 | public class EnumerableExtensionsSpecs 7 | { 8 | public class when_checking_for_ascending_lists : SpecsFor 9 | { 10 | [Test] 11 | public void then_it_does_not_throw_for_ascending_lists() 12 | { 13 | Assert.DoesNotThrow(() => new[] { 1,2,3,4}.ShouldBeAscending()); 14 | } 15 | 16 | [Test] 17 | public void then_it_throws_for_lists_that_are_not_ascending() 18 | { 19 | Assert.Throws(() => new[] { 1,1,3,4}.ShouldBeAscending()); 20 | } 21 | } 22 | 23 | public class when_checking_for_descending_lists : SpecsFor 24 | { 25 | [Test] 26 | public void then_it_does_not_throw_for_descending_lists() 27 | { 28 | Assert.DoesNotThrow(() => new[] { 4,3,2,1 }.ShouldBeDescending()); 29 | } 30 | 31 | [Test] 32 | public void then_it_throws_for_lists_that_are_not_descending() 33 | { 34 | Assert.Throws(() => new[] { 4,4,3,2}.ShouldBeAscending()); 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ComposingContext/TestDomain/ProvideMagicForEveryone.cs: -------------------------------------------------------------------------------- 1 | using SpecsFor.Core; 2 | using SpecsFor.Core.Configuration; 3 | 4 | namespace SpecsFor.Lamar.Tests.ComposingContext.TestDomain; 5 | 6 | public class ProvideMagicForEveryone : Behavior 7 | { 8 | public override void Given(ISpecs instance) 9 | { 10 | ((ILikeMagic) instance).CalledByDuringGiven.Add(GetType().Name); 11 | } 12 | 13 | public override void AfterGiven(ISpecs instance) 14 | { 15 | ((ILikeMagic) instance).CalledByAfterGiven.Add(GetType().Name); 16 | } 17 | 18 | public override void AfterSpec(ISpecs instance) 19 | { 20 | ((ILikeMagic)instance).CalledByAfterSpec.Add(GetType().Name); 21 | } 22 | 23 | public override void AfterTest(ISpecs instance) 24 | { 25 | ((ILikeMagic)instance).CalledByAfterTest.Add(GetType().Name); 26 | } 27 | 28 | public override void BeforeTest(ISpecs instance) 29 | { 30 | ((ILikeMagic)instance).CalledByBeforeTest.Add(GetType().Name); 31 | } 32 | 33 | public override void ClassUnderTestInitialized(ISpecs instance) 34 | { 35 | ((ILikeMagic)instance).CalledByApplyAfterClassUnderTestInitialized.Add(GetType().Name); 36 | } 37 | 38 | public override void SpecInit(ISpecs instance) 39 | { 40 | ((ILikeMagic)instance).CalledBySpecInit.Add(GetType().Name); 41 | } 42 | } -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ShouldExtensions/EnumerableExtensionsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.ShouldExtensions; 3 | 4 | namespace SpecsFor.StructureMap.Tests.ShouldExtensions 5 | { 6 | public class EnumerableExtensionsSpecs 7 | { 8 | public class when_checking_for_ascending_lists : SpecsFor 9 | { 10 | [Test] 11 | public void then_it_does_not_throw_for_ascending_lists() 12 | { 13 | Assert.DoesNotThrow(() => new[] { 1,2,3,4}.ShouldBeAscending()); 14 | } 15 | 16 | [Test] 17 | public void then_it_throws_for_lists_that_are_not_ascending() 18 | { 19 | Assert.Throws(() => new[] { 1,1,3,4}.ShouldBeAscending()); 20 | } 21 | } 22 | 23 | public class when_checking_for_descending_lists : SpecsFor 24 | { 25 | [Test] 26 | public void then_it_does_not_throw_for_descending_lists() 27 | { 28 | Assert.DoesNotThrow(() => new[] { 4,3,2,1 }.ShouldBeDescending()); 29 | } 30 | 31 | [Test] 32 | public void then_it_throws_for_lists_that_are_not_descending() 33 | { 34 | Assert.Throws(() => new[] { 4,4,3,2}.ShouldBeAscending()); 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /SpecsFor.Core/Configuration/Model/ConditionalBehavior.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpecsFor.Core.Configuration.Model 4 | { 5 | internal class ConditionalBehavior : IConditionalBehavior where TSpec : class 6 | { 7 | private readonly Func _predicate; 8 | private readonly Behavior _behavior; 9 | 10 | public ConditionalBehavior(Func predicate, Behavior behavior) 11 | { 12 | _predicate = predicate; 13 | _behavior = behavior; 14 | } 15 | 16 | public bool CanBeAppliedTo(Type targetType) 17 | { 18 | return _predicate(targetType); 19 | } 20 | 21 | public void ApplyGivenTo(object specs) 22 | { 23 | _behavior.Given((TSpec) specs); 24 | } 25 | 26 | public void ApplyAfterGivenTo(object specs) 27 | { 28 | _behavior.AfterGiven((TSpec) specs); 29 | } 30 | 31 | public void ApplyAfterSpecTo(object specs) 32 | { 33 | _behavior.AfterSpec((TSpec)specs); 34 | } 35 | 36 | public void ApplyAfterTestTo(object specs) 37 | { 38 | _behavior.AfterTest((TSpec) specs); 39 | } 40 | 41 | public void ApplyBeforeTestTo(object specs) 42 | { 43 | _behavior.BeforeTest((TSpec) specs); 44 | } 45 | 46 | public void ApplySpecInitTo(object specs) 47 | { 48 | _behavior.SpecInit((TSpec)specs); 49 | } 50 | 51 | public void ApplyAfterClassUnderTestInitializedTo(object specs) 52 | { 53 | _behavior.ClassUnderTestInitialized((TSpec)specs); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /SpecsFor.Autofac/SpecsFor.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Extras.Moq; 3 | using SpecsFor.Core; 4 | 5 | namespace SpecsFor.Autofac 6 | { 7 | public class SpecsFor : SpecsForBase where T : class 8 | { 9 | /// 10 | /// Override this in your specs if you need to provide additional configuration, such as 11 | /// supplying a concrete implmentation of an interface. 12 | /// 13 | /// 14 | public virtual void ConfigureMocker(AutoMock mocker) 15 | { 16 | 17 | } 18 | 19 | /// 20 | /// Override this in your specs if you want to use a different setting of Autofac's AutoMocker. 21 | /// The default is AutoMock.GetLoose(). You can also use AutoMock.GetStrict(), or provide your own repository with 22 | /// AutoMock.GetFromRepository(myRepository); 23 | /// 24 | /// 25 | public virtual AutoMock CreateInternalMocker() 26 | { 27 | return AutoMock.GetLoose(); 28 | } 29 | 30 | /// 31 | /// Do not override this unless you really know what you're doing. If you're trying to adjust Moq behavior, 32 | /// override CreateMocker() instead. 33 | /// 34 | /// 35 | protected override IAutoMocker CreateAutoMocker() 36 | { 37 | return new AutofacAutoMocker(this); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /SpecsFor.StructureMap/MoqFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace SpecsFor.StructureMap 5 | { 6 | public class MoqFactory 7 | { 8 | private readonly Type _mockOpenType; 9 | 10 | public MoqFactory() 11 | { 12 | var moq = Assembly.Load("Moq"); 13 | _mockOpenType = moq.GetType("Moq.Mock`1"); 14 | if (_mockOpenType == null) 15 | throw new InvalidOperationException("Unable to find Type Moq.Mock in assembly " + moq.Location); 16 | } 17 | 18 | public object CreateMock(Type type) 19 | { 20 | var closedType = _mockOpenType.MakeGenericType(type); 21 | var objectProperty = closedType.GetProperty("Object", type); 22 | var instance = Activator.CreateInstance(closedType); 23 | return objectProperty.GetValue(instance, null); 24 | } 25 | 26 | public object CreateMockThatCallsBase(Type type, object[] args) 27 | { 28 | var closedType = _mockOpenType.MakeGenericType(type); 29 | var callBaseProperty = closedType.GetProperty("CallBase", typeof (bool)); 30 | var objectProperty = closedType.GetProperty("Object", type); 31 | var constructor = closedType.GetConstructor(new[] {typeof (object[])}); 32 | var instance = constructor.Invoke(new[] {args}); 33 | callBaseProperty.SetValue(instance, true, null); 34 | return objectProperty.GetValue(instance, null); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp.Specs/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ShouldExtensions/ExpectedObjectExtensionsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.ShouldExtensions; 3 | 4 | namespace SpecsFor.StructureMap.Tests.ShouldExtensions 5 | { 6 | public class ExpectedObjectExtensionsSpecs : SpecsFor 7 | { 8 | #region Test Classes 9 | 10 | public class TestObject 11 | { 12 | public int ID { get; set; } 13 | public string Name { get; set; } 14 | } 15 | 16 | public interface ITestService 17 | { 18 | void DoStuff(TestObject obj); 19 | } 20 | 21 | #endregion 22 | 23 | protected override void InitializeClassUnderTest() 24 | { 25 | SUT = new TestObject { ID = 1, Name = "Test" }; 26 | } 27 | 28 | [Test] 29 | public void two_equivalent_objects_look_identical() 30 | { 31 | Assert.DoesNotThrow(() => SUT.ShouldLookLike(new TestObject { ID = 1, Name = "Test" })); 32 | } 33 | 34 | [Test] 35 | public void two_different_objects_do_not_look_the_same() 36 | { 37 | Assert.Throws(() => SUT.ShouldLookLike(new TestObject())); 38 | } 39 | 40 | [Test] 41 | public void then_partial_matching_with_an_equivalenet_object_works() 42 | { 43 | Assert.DoesNotThrow(() => SUT.ShouldLookLikePartial(new { ID = 1, Name = "Test" })); 44 | } 45 | 46 | [Test] 47 | public void then_partial_matching_with_an_unequivalenet_object_throws_exception() 48 | { 49 | Assert.Throws(() => SUT.ShouldLookLikePartial(new { ID = 5, Name = "blah" })); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Specs/Fakes/ConfiguringBehaviorDemos.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Should; 3 | using SpecsFor; 4 | using SpecsFor.Helpers.Web.Mvc; 5 | using SpecsForWebHelpers.Web.Helpers; 6 | 7 | namespace SpecsForWebHelpers.Specs.Fakes 8 | { 9 | public class ConfiguringBehaviorDemos 10 | { 11 | public class when_getting_the_app_version_and_the_app_is_in_debug_mode : SpecsFor 12 | { 13 | private string _version; 14 | 15 | protected override void Given() 16 | { 17 | GetMockFor() 18 | .Setup(x => x.IsDebuggingEnabled) 19 | .Returns(true); 20 | } 21 | 22 | protected override void When() 23 | { 24 | _version = SUT.GetVersionString(); 25 | } 26 | 27 | [Test] 28 | public void then_the_version_contains_the_debug_suffix() 29 | { 30 | _version.EndsWith("DEBUG").ShouldBeTrue(); 31 | } 32 | } 33 | 34 | public class when_getting_the_app_version_and_the_app_is_in_release_mode : SpecsFor 35 | { 36 | private string _version; 37 | 38 | protected override void Given() 39 | { 40 | GetMockFor() 41 | .Setup(x => x.IsDebuggingEnabled) 42 | .Returns(false); 43 | } 44 | 45 | protected override void When() 46 | { 47 | _version = SUT.GetVersionString(); 48 | } 49 | 50 | [Test] 51 | public void then_the_version_contains_the_debug_suffix() 52 | { 53 | _version.EndsWith("DEBUG").ShouldBeFalse(); 54 | } 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SpecsFor.Demo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("SpecsFor.Demo")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("eb880723-b128-4ed7-b811-c10ec6ba3c35")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ShouldExtensions/PartialMatchingWithListsSpecs.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NUnit.Framework; 3 | using Should.Core.Exceptions; 4 | using SpecsFor.Core.ShouldExtensions; 5 | 6 | namespace SpecsFor.Autofac.Tests.ShouldExtensions 7 | { 8 | public class PartialMatchingWithListsSpecs 9 | { 10 | #region Test Classes 11 | public class TestClass 12 | { 13 | public string Name { get; set; } 14 | public List Items { get; set; } 15 | } 16 | 17 | public class NestedClass 18 | { 19 | public int Id { get; set; } 20 | public string Name { get; set; } 21 | } 22 | #endregion 23 | 24 | public class when_partial_matching_objects_with_list_members : SpecsFor 25 | { 26 | [Test] 27 | public void then_it_does_not_throw_on_a_matching_pair_of_objects() 28 | { 29 | var obj1 = new TestClass { Name = "Name", Items = new List { new NestedClass { Id = 1, Name = "One" } } }; 30 | 31 | Assert.DoesNotThrow(() => obj1.ShouldLookLike(() => 32 | new TestClass { Name = "Name", Items = new List { new NestedClass { Id = 1 } } }) 33 | ); 34 | } 35 | 36 | [Test] 37 | public void then_it_does_throw_on_a_non_matching_pair_of_objects() 38 | { 39 | var obj1 = new TestClass { Name = "Name", Items = new List { new NestedClass { Id = 1, Name = "One" } } }; 40 | 41 | Assert.Throws(() => obj1.ShouldLookLike(() => 42 | new TestClass { Name = "Name", Items = new List { new NestedClass { Id = 2 } } }) 43 | ); 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("WindowsAuthSampleApp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("WindowsAuthSampleApp")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b06ab153-8e31-4adb-af27-3cf020d50b2e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /SpecsFor.StructureMap.Tests/ShouldExtensions/PartialMatchingWithListsSpecs.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NUnit.Framework; 3 | using Should.Core.Exceptions; 4 | using SpecsFor.Core.ShouldExtensions; 5 | 6 | namespace SpecsFor.StructureMap.Tests.ShouldExtensions 7 | { 8 | public class PartialMatchingWithListsSpecs 9 | { 10 | #region Test Classes 11 | public class TestClass 12 | { 13 | public string Name { get; set; } 14 | public List Items { get; set; } 15 | } 16 | 17 | public class NestedClass 18 | { 19 | public int Id { get; set; } 20 | public string Name { get; set; } 21 | } 22 | #endregion 23 | 24 | public class when_partial_matching_objects_with_list_members : SpecsFor 25 | { 26 | [Test] 27 | public void then_it_does_not_throw_on_a_matching_pair_of_objects() 28 | { 29 | var obj1 = new TestClass { Name = "Name", Items = new List { new NestedClass { Id = 1, Name = "One" } } }; 30 | 31 | Assert.DoesNotThrow(() => obj1.ShouldLookLike(() => 32 | new TestClass { Name = "Name", Items = new List { new NestedClass { Id = 1 } } }) 33 | ); 34 | } 35 | 36 | [Test] 37 | public void then_it_does_throw_on_a_non_matching_pair_of_objects() 38 | { 39 | var obj1 = new TestClass { Name = "Name", Items = new List { new NestedClass { Id = 1, Name = "One" } } }; 40 | 41 | Assert.Throws(() => obj1.ShouldLookLike(() => 42 | new TestClass { Name = "Name", Items = new List { new NestedClass { Id = 2 } } }) 43 | ); 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SpecsForWebHelpers.Web")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SpecsForWebHelpers.Web")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b9b6d7ec-42e6-4230-a2dc-2306b9ea4d59")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Specs/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Beginners")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Beginners")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a3d62421-945a-458d-a893-e1545fb6a065")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/Beginners.Domain/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Beginners.Domain")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Beginners.Domain")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7010090f-1b27-463d-aa86-86cfdb21961d")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/PartialMatching/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PartialMatching")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("PartialMatching")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("2ddf7827-b4c7-4191-b592-6b0ef73213f1")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ShouldExtensions/ExpectedObjectExtensionsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.ShouldExtensions; 3 | 4 | namespace SpecsFor.Lamar.Tests.ShouldExtensions; 5 | 6 | public class ExpectedObjectExtensionsSpecs : SpecsFor 7 | { 8 | #region Test Classes 9 | 10 | public class TestObject 11 | { 12 | public int ID { get; set; } 13 | public string Name { get; set; } 14 | } 15 | 16 | public interface ITestService 17 | { 18 | void DoStuff(TestObject obj); 19 | } 20 | 21 | #endregion 22 | 23 | protected override void InitializeClassUnderTest() 24 | { 25 | SUT = new TestObject { ID = 1, Name = "Test" }; 26 | } 27 | 28 | [Test] 29 | public void two_equivalent_objects_look_identical() 30 | { 31 | Assert.DoesNotThrow(() => SUT.ShouldLookLike(new TestObject { ID = 1, Name = "Test" })); 32 | } 33 | 34 | [Test] 35 | public void two_different_objects_do_not_look_the_same() 36 | { 37 | Assert.Throws(() => SUT.ShouldLookLike(new TestObject())); 38 | } 39 | 40 | [Test] 41 | public void then_partial_matching_with_an_equivalenet_object_works() 42 | { 43 | Assert.DoesNotThrow(() => SUT.ShouldLookLikePartial(new { ID = 1, Name = "Test" })); 44 | } 45 | 46 | [Test] 47 | public void then_partial_matching_with_an_unequivalenet_object_throws_exception() 48 | { 49 | Assert.Throws(() => SUT.ShouldLookLikePartial(new { ID = 5, Name = "blah" })); 50 | } 51 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Conventions.Basics")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Conventions.Basics")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1d912bc7-e1cd-44e4-97f5-10ad9edfa4ed")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/Conventions.Basics/Specs/FooFactorySpecs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Conventions.Basics.Domain; 3 | using NUnit.Framework; 4 | using Should; 5 | using SpecsFor; 6 | 7 | namespace Conventions.Basics.Specs 8 | { 9 | public class FooFactorySpecs 10 | { 11 | public class when_creating_a_foo_with_no_options : SpecsFor 12 | { 13 | private Foo _result; 14 | 15 | protected override void When() 16 | { 17 | _result = SUT.Create(); 18 | } 19 | 20 | [Test] 21 | public void then_it_uses_the_right_default_name() 22 | { 23 | _result.Name.ShouldEqual("Unnamed"); 24 | } 25 | 26 | [Test] 27 | public void then_it_assigns_an_id() 28 | { 29 | _result.Id.ShouldNotEqual(Guid.Empty); 30 | } 31 | } 32 | 33 | public class when_creating_a_foo_with_a_name : SpecsFor 34 | { 35 | private Foo _result; 36 | 37 | protected override void When() 38 | { 39 | _result = SUT.Create("TestFoo"); 40 | } 41 | 42 | [Test] 43 | public void then_it_uses_the_specified_name() 44 | { 45 | _result.Name.ShouldEqual("TestFoo"); 46 | } 47 | 48 | [Test] 49 | public void then_it_assigns_an_id() 50 | { 51 | _result.Id.ShouldNotEqual(Guid.Empty); 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Specs/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SpecsForWebHelpers.Specs")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SpecsForWebHelpers.Specs")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f53fd53d-6d4d-45a2-b892-8e5a39d7ede3")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp.Specs/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("WindowsAuthSampleApp.Specs")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("WindowsAuthSampleApp.Specs")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("d452f3f8-a522-4af9-9e51-6a9e3a95902a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model WindowsAuthSampleApp.Models.HomePageViewModel 2 | @{ 3 | ViewBag.Title = "Home Page"; 4 | } 5 | 6 |
7 |

ASP.NET

8 |

ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.

9 |

Learn more »

10 |

Hello, @Model.UserName

11 |
12 | 13 |
14 |
15 |

Getting started

16 |

17 | ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that 18 | enables a clean separation of concerns and gives you full control over markup 19 | for enjoyable, agile development. 20 |

21 |

Learn more »

22 |
23 |
24 |

Get more libraries

25 |

NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.

26 |

Learn more »

27 |
28 |
29 |

Web Hosting

30 |

You can easily find a web hosting company that offers the right mix of features and price for your applications.

31 |

Learn more »

32 |
33 |
-------------------------------------------------------------------------------- /SpecsFor.Lamar.Tests/ShouldExtensions/PartialMatchingWithListsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Should.Core.Exceptions; 3 | using SpecsFor.Core.ShouldExtensions; 4 | 5 | namespace SpecsFor.Lamar.Tests.ShouldExtensions; 6 | 7 | public class PartialMatchingWithListsSpecs 8 | { 9 | #region Test Classes 10 | public class TestClass 11 | { 12 | public string Name { get; set; } 13 | public List Items { get; set; } 14 | } 15 | 16 | public class NestedClass 17 | { 18 | public int Id { get; set; } 19 | public string Name { get; set; } 20 | } 21 | #endregion 22 | 23 | public class when_partial_matching_objects_with_list_members : SpecsFor 24 | { 25 | [Test] 26 | public void then_it_does_not_throw_on_a_matching_pair_of_objects() 27 | { 28 | var obj1 = new TestClass { Name = "Name", Items = new List { new NestedClass { Id = 1, Name = "One" } } }; 29 | 30 | Assert.DoesNotThrow(() => obj1.ShouldLookLike(() => 31 | new TestClass { Name = "Name", Items = new List { new NestedClass { Id = 1 } } }) 32 | ); 33 | } 34 | 35 | [Test] 36 | public void then_it_does_throw_on_a_non_matching_pair_of_objects() 37 | { 38 | var obj1 = new TestClass { Name = "Name", Items = new List { new NestedClass { Id = 1, Name = "One" } } }; 39 | 40 | Assert.Throws(() => obj1.ShouldLookLike(() => 41 | new TestClass { Name = "Name", Items = new List { new NestedClass { Id = 2 } } }) 42 | ); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /publish-packages.ps1: -------------------------------------------------------------------------------- 1 | if (Test-path .\SpecsFor.Core\bin\Release\SpecsFor.Core.*.nupkg) { 2 | rm (Resolve-Path .\SpecsFor.Core\bin\Release\SpecsFor.Core.*.nupkg) 3 | } 4 | if (Test-path .\SpecsFor.StructureMap\bin\Release\SpecsFor.StructureMap.*.nupkg) { 5 | rm (Resolve-Path .\SpecsFor.StructureMap\bin\Release\SpecsFor.StructureMap.*.nupkg) 6 | } 7 | if (Test-path .\SpecsFor.Autofac\bin\Release\SpecsFor.Autofac.*.nupkg) { 8 | rm (Resolve-Path .\SpecsFor.Autofac\bin\Release\SpecsFor.Autofac.*.nupkg) 9 | } 10 | if (Test-path .\SpecsFor.Lamar\bin\Release\SpecsFor.Lamar.*.nupkg) { 11 | rm (Resolve-Path .\SpecsFor.Lamar\bin\Release\SpecsFor.Lamar.*.nupkg) 12 | } 13 | if (Test-path .\SpecsFor.*.nupkg) { 14 | rm (Resolve-Path .\SpecsFor.*.nupkg) 15 | } 16 | dotnet pack .\SpecsFor.Core\SpecsFor.Core.csproj 17 | dotnet pack .\SpecsFor.StructureMap\SpecsFor.StructureMap.csproj 18 | dotnet pack .\SpecsFor.Autofac\SpecsFor.Autofac.csproj 19 | dotnet pack .\SpecsFor.Lamar\SpecsFor.Lamar.csproj 20 | nuget pack .\metapackage\specsfor-metapackage.nuspec 21 | 22 | Write-Host "Packages built, publish?" 23 | pause 24 | 25 | nuget push (Resolve-Path .\SpecsFor.Core\bin\Release\SpecsFor.Core.*.nupkg) -Source https://api.nuget.org/v3/index.json 26 | nuget push (Resolve-Path .\SpecsFor.StructureMap\bin\Release\SpecsFor.StructureMap.*.nupkg) -Source https://api.nuget.org/v3/index.json 27 | nuget push (Resolve-Path .\SpecsFor.Autofac\bin\Release\SpecsFor.Autofac.*.nupkg) -Source https://api.nuget.org/v3/index.json 28 | nuget push (Resolve-Path .\SpecsFor.Lamar\bin\Release\SpecsFor.Lamar.*.nupkg) -Source https://api.nuget.org/v3/index.json 29 | nuget push (Resolve-Path .\SpecsFor.*.nupkg) -Source https://api.nuget.org/v3/index.json 30 | 31 | -------------------------------------------------------------------------------- /SpecsFor.Core/ShouldExtensions/EnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using NUnit.Framework; 4 | 5 | namespace SpecsFor.Core.ShouldExtensions 6 | { 7 | public static class EnumerableExtensions 8 | { 9 | public static void ShouldBeAscending(this IEnumerable values) where T : IComparable 10 | { 11 | if (values == null) throw new ArgumentNullException(nameof(values)); 12 | 13 | var position = 0; 14 | var enumerator = values.GetEnumerator(); 15 | 16 | if (!enumerator.MoveNext()) return; 17 | 18 | var old = enumerator.Current; 19 | 20 | while (enumerator.MoveNext()) 21 | { 22 | position++; 23 | if (enumerator.Current.CompareTo(old) <= 0) 24 | throw new AssertionException($"Found non-ascending values at position {position - 1}, {position}: {old}, {enumerator.Current}"); 25 | } 26 | } 27 | 28 | public static void ShouldBeDescending(this IEnumerable values) where T : IComparable 29 | { 30 | if (values == null) throw new ArgumentNullException(nameof(values)); 31 | 32 | var position = 0; 33 | var enumerator = values.GetEnumerator(); 34 | 35 | if (!enumerator.MoveNext()) return; 36 | 37 | var old = enumerator.Current; 38 | 39 | while (enumerator.MoveNext()) 40 | { 41 | position++; 42 | if (enumerator.Current.CompareTo(old) >= 0) 43 | throw new AssertionException($"Found non-descending values at position {position - 1}, {position}: {old}, {enumerator.Current}"); 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ShouldExtensions/ExpectedObjectExtensionsSpecs.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecsFor.Core.ShouldExtensions; 3 | 4 | namespace SpecsFor.Autofac.Tests.ShouldExtensions 5 | { 6 | public class ExpectedObjectExtensionsSpecs : SpecsFor 7 | { 8 | #region Test Classes 9 | 10 | public class TestObject 11 | { 12 | public int ID { get; set; } 13 | public string Name { get; set; } 14 | } 15 | 16 | public interface ITestService 17 | { 18 | void DoStuff(TestObject obj); 19 | } 20 | 21 | #endregion 22 | 23 | protected override void InitializeClassUnderTest() 24 | { 25 | SUT = new TestObject { ID = 1, Name = "Test" }; 26 | } 27 | 28 | [Test] 29 | public void two_equivalent_objects_look_identical() 30 | { 31 | Assert.DoesNotThrow(() => SUT.ShouldLookLike(new TestObject { ID = 1, Name = "Test" })); 32 | } 33 | 34 | [Test] 35 | public void two_different_objects_do_not_look_the_same() 36 | { 37 | Assert.Throws(() => SUT.ShouldLookLike(new TestObject())); 38 | } 39 | 40 | [Test] 41 | public void then_partial_matching_with_an_equivalenet_object_works() 42 | { 43 | Assert.DoesNotThrow(() => SUT.ShouldLookLikePartial(new { ID = 1, Name = "Test" })); 44 | } 45 | 46 | [Test] 47 | public void then_partial_matching_with_an_unequivalenet_object_throws_exception() 48 | { 49 | Assert.Throws(() => SUT.ShouldLookLikePartial(new { ID = 5, Name = "blah" })); 50 | } 51 | 52 | [Test] 53 | public void then_partial_matching_with_a_nonexistant_property_throws_exception() 54 | { 55 | Assert.Throws(() => SUT.ShouldLookLikePartial(new { NotAProperty = 5 })); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /SpecsFor.Core/SpecsFor.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SpecsFor.Core 5 | 8.0.0-rc1a 6 | Matt Honeycutt 7 | Heroic Applications 8 | 9 | https://github.com/MattHoneycutt/SpecsFor/blob/master/LICENSE.md 10 | http://specsfor.com 11 | http://specsfor.com/images/specsfor-icon-128x128.png 12 | SpecsFor is another Behavior-Driven Development framework that focuses on ease of use for *developers* by minimizing testing friction. 13 | 14 | Updated packages, added support for Lamar.. 15 | 16 | Copyright 2025 17 | TDD;Testing;BDD;Test Driven Development;NET Core;NUnit 18 | true 19 | 20 | 21 | 22 | net6.0 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | all 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Web/Views/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Specs/Filters/MattOnlyAttributeSpecsWithHelpers.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Should; 3 | using SpecsFor; 4 | using SpecsFor.Helpers.Web.Mvc; 5 | using SpecsForWebHelpers.Web.Domain; 6 | using SpecsForWebHelpers.Web.Filters; 7 | 8 | namespace SpecsForWebHelpers.Specs.Filters 9 | { 10 | public class MattOnlyAttributeSpecsWithHelpers 11 | { 12 | public class when_the_user_is_not_a_matt : SpecsFor 13 | { 14 | private FakeActionExecutingContext _filterContext; 15 | 16 | protected override void Given() 17 | { 18 | var userMock = GetMockFor(); 19 | userMock.Setup(x => x.UserName).Returns("John"); 20 | SUT.CurrentUser = userMock.Object; 21 | } 22 | 23 | protected override void When() 24 | { 25 | _filterContext = new FakeActionExecutingContext(); 26 | SUT.OnActionExecuting(_filterContext); 27 | } 28 | 29 | [Test] 30 | public void then_it_displays_an_unauthorized_view() 31 | { 32 | _filterContext.Result.ShouldRenderView() 33 | .ViewName.ShouldEqual("YouAreNotMatt"); 34 | } 35 | } 36 | 37 | public class when_the_user_is_a_matt : SpecsFor 38 | { 39 | private FakeActionExecutingContext _filterContext; 40 | 41 | protected override void Given() 42 | { 43 | var userMock = GetMockFor(); 44 | userMock.Setup(x => x.UserName).Returns("Matt"); 45 | SUT.CurrentUser = userMock.Object; 46 | } 47 | 48 | protected override void When() 49 | { 50 | _filterContext = new FakeActionExecutingContext(); 51 | SUT.OnActionExecuting(_filterContext); 52 | } 53 | 54 | [Test] 55 | public void then_the_filter_does_not_alter_the_result() 56 | { 57 | _filterContext.Result.ShouldBeNull(); 58 | } 59 | } 60 | 61 | } 62 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Views/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/WindowsAuthSampleApp/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @ViewBag.Title - My ASP.NET Application 7 | @Styles.Render("~/Content/css") 8 | @Scripts.Render("~/bundles/modernizr") 9 | 10 | 11 | 31 |
32 | @RenderBody() 33 |
34 |
35 |

© @DateTime.Now.Year - My ASP.NET Application

36 |
37 |
38 | 39 | @Scripts.Render("~/bundles/jquery") 40 | @Scripts.Render("~/bundles/bootstrap") 41 | @RenderSection("scripts", required: false) 42 | 43 | 44 | -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Specs/Controllers/HomeControllerSpecsWithHelpers.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | using NUnit.Framework; 3 | using SpecsFor; 4 | using SpecsFor.Helpers.Web.Mvc; 5 | using SpecsForWebHelpers.Web.Controllers; 6 | using SpecsForWebHelpers.Web.Domain; 7 | using SpecsForWebHelpers.Web.Models; 8 | 9 | namespace SpecsForWebHelpers.Specs.Controllers 10 | { 11 | public class HomeControllerSpecsWithHelpers 12 | { 13 | public class when_setting_the_users_name : SpecsFor 14 | { 15 | private ActionResult _result; 16 | 17 | protected override void When() 18 | { 19 | _result = SUT.SetName("Jane Doe"); 20 | } 21 | 22 | [Test] 23 | public void then_it_sets_the_name_of_the_user() 24 | { 25 | GetMockFor() 26 | .Verify(x => x.SetName("Jane Doe")); 27 | } 28 | 29 | [Test] 30 | public void then_it_redirects_back_home() 31 | { 32 | _result.ShouldRedirectTo(c => c.Index()); 33 | } 34 | } 35 | 36 | public class when_saying_hello_to_a_user : SpecsFor 37 | { 38 | private ActionResult _result; 39 | 40 | protected override void When() 41 | { 42 | _result = SUT.SayHello("John Doe"); 43 | } 44 | 45 | [Test] 46 | public void then_it_says_hello_to_the_user() 47 | { 48 | _result.ShouldRenderDefaultView() 49 | .WithModelLike(new SayHelloViewModel 50 | { 51 | Name = "John Doe" 52 | }); 53 | } 54 | } 55 | 56 | public class when_saying_hello_with_a_form : SpecsFor 57 | { 58 | private ActionResult _result; 59 | 60 | protected override void When() 61 | { 62 | _result = SUT.SayHello(new SayHelloForm { Name = "Jane Doe" }); 63 | } 64 | 65 | [Test] 66 | public void then_it_redirects_to_the_say_hello_action() 67 | { 68 | _result.ShouldRedirectTo( 69 | c => c.SayHello("Jane Doe")); 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Specs/Helpers/BootstrapHelperSpecsWithHelpers.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Routing; 2 | using HtmlTags; 3 | using NUnit.Framework; 4 | using Should; 5 | using SpecsFor; 6 | using SpecsFor.Helpers.Web.Mvc; 7 | using SpecsForWebHelpers.Web; 8 | using SpecsForWebHelpers.Web.Controllers; 9 | using SpecsForWebHelpers.Web.Helpers; 10 | 11 | namespace SpecsForWebHelpers.Specs.Helpers 12 | { 13 | public class BootstrapHelperSpecsWithHelpers 14 | { 15 | public class when_creating_a_bootstrap_button : SpecsFor 16 | { 17 | private HtmlTag _button; 18 | 19 | protected override void When() 20 | { 21 | _button = SUT.BootstrapButton("Submit!"); 22 | } 23 | 24 | [Test] 25 | public void then_it_creates_submit_button() 26 | { 27 | _button.Attr("type").ShouldEqual("submit"); 28 | } 29 | 30 | [Test] 31 | public void then_it_sets_the_correct_button_classes() 32 | { 33 | _button.HasClass("btn").ShouldBeTrue(); 34 | _button.HasClass("btn-primary").ShouldBeTrue(); 35 | } 36 | } 37 | 38 | public class when_creating_a_bootstrap_link_button : SpecsFor 39 | { 40 | private HtmlTag _link; 41 | 42 | protected override void Given() 43 | { 44 | RouteConfig.RegisterRoutes(RouteTable.Routes); 45 | } 46 | 47 | protected override void When() 48 | { 49 | _link = SUT.BootstrapActionLinkButton( 50 | c => c.SetName(), "Set Name!"); 51 | } 52 | 53 | [Test] 54 | public void then_it_builds_a_link_tag() 55 | { 56 | _link.TagName().ShouldEqual("a"); 57 | } 58 | 59 | [Test] 60 | public void then_it_sets_the_link_correctly() 61 | { 62 | _link.Attr("href").ShouldEqual("/Home/SetName"); 63 | } 64 | 65 | [Test] 66 | public void then_it_looks_like_a_bootstrap_button() 67 | { 68 | _link.HasClass("btn").ShouldBeTrue(); 69 | _link.HasClass("btn-primary").ShouldBeTrue(); 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /SpecsFor.Core/Validation/NUnitSpecValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Linq; 4 | using System.Reflection; 5 | using NUnit.Framework; 6 | using SpecsFor.Core.Configuration; 7 | 8 | namespace SpecsFor.Core.Validation 9 | { 10 | public class NUnitSpecValidator : ISpecValidator 11 | { 12 | //Used to cache validation results for an assembly. 13 | private static readonly ConcurrentDictionary _validationResults = new ConcurrentDictionary(); 14 | 15 | public void ValidateSpec(ISpecs spec) 16 | { 17 | //NOTE: Other validations may be performed in the future. For now, 18 | // just verify that everything in the spec's assembly that derives 19 | // from SpecsForConfiguration has the correct attribute. 20 | var assembly = spec.GetType().Assembly; 21 | 22 | _validationResults.GetOrAdd(assembly.FullName, _ => ValidateAssembly(assembly)); 23 | } 24 | 25 | private bool ValidateAssembly(Assembly assembly) 26 | { 27 | var configClassesWithoutSetupFixtureAttribute = (from t in assembly.GetTypes() 28 | where typeof (SpecsForConfiguration).IsAssignableFrom(t) && 29 | !t.IsAbstract && 30 | Attribute.GetCustomAttribute(t, typeof (SetUpFixtureAttribute)) == 31 | null 32 | select t).ToArray(); 33 | 34 | if (configClassesWithoutSetupFixtureAttribute.Any()) 35 | { 36 | var message = "Found one or more SpecsForConfiguration types that do not have a SetUpFixtureAttribute. " + 37 | "You must apply the attribute to each type or make the type abstract. " + 38 | "Offending type(s): \r\n" + string.Join("\r\n", configClassesWithoutSetupFixtureAttribute.Select(t => t.FullName)); 39 | throw new InvalidOperationException(message); 40 | } 41 | 42 | return true; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /SpecsFor.Autofac.Tests/ComposingContext/StackingContext/StackingContextSpecs.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using NUnit.Framework; 4 | using Should; 5 | using SpecsFor.Autofac.Tests.ComposingContext.TestDomain; 6 | 7 | namespace SpecsFor.Autofac.Tests.ComposingContext.StackingContext 8 | { 9 | public class StackingContextSpecs 10 | { 11 | public class when_running_tests_decorated_with_a_behavior : SpecsFor, ILikeMagic 12 | { 13 | public List CalledByDuringGiven { get; set; } 14 | public List CalledByAfterSpec { get; set; } 15 | public List CalledByAfterTest { get; set; } 16 | public List CalledByBeforeTest { get; set; } 17 | public List CalledByApplyAfterClassUnderTestInitialized { get; set; } 18 | public List CalledBySpecInit { get; set; } 19 | 20 | public when_running_tests_decorated_with_a_behavior() 21 | { 22 | CalledBySpecInit = new List(); 23 | CalledByApplyAfterClassUnderTestInitialized = new List(); 24 | CalledByDuringGiven = new List(); 25 | CalledByAfterSpec = new List(); 26 | CalledByAfterTest = new List(); 27 | CalledByBeforeTest = new List(); 28 | } 29 | 30 | [Test] 31 | public void then_handlers_defined_in_the_higher_level_config_should_be_called() 32 | { 33 | CalledByDuringGiven.ShouldContain(typeof(ProvideMagicByInterface).Name); 34 | CalledByDuringGiven.ShouldContain(typeof(ProvideMagicByConcreteType).Name); 35 | CalledByDuringGiven.ShouldContain(typeof(ProvideMagicByTypeName).Name); 36 | CalledByDuringGiven.ShouldNotContain(typeof(DoNotProvideMagic).Name); 37 | CalledByDuringGiven.ShouldContain(typeof(ProvideMagicForEveryone).Name); 38 | } 39 | 40 | [Test] 41 | public void then_handlers_for_this_levels_config_should_be_called() 42 | { 43 | CalledByDuringGiven.ShouldContain(typeof(NestedMagicProvider).Name); 44 | } 45 | 46 | [Test] 47 | public void then_the_parent_contexts_are_applied_before_the_child_context() 48 | { 49 | CalledByDuringGiven.AsEnumerable().Reverse().First().ShouldEqual(typeof(NestedMagicProvider).Name); 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /SpecsFor.Core/ShouldExtensions/Matcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | using System.Reflection; 4 | 5 | namespace SpecsFor.Core.ShouldExtensions 6 | { 7 | public class Matcher 8 | { 9 | [ThreadStatic] 10 | public static Matcher LastMatcher; 11 | 12 | public static void Create(Expression> matcher, string message) 13 | { 14 | LastMatcher = new Matcher(matcher, message); 15 | } 16 | } 17 | 18 | public class Matcher : Matcher 19 | { 20 | private readonly Expression> _matcher; 21 | private readonly string _message; 22 | 23 | public Matcher(Expression> matcher, string message) 24 | { 25 | _matcher = matcher ?? (x => true); 26 | _message = message; 27 | } 28 | 29 | public override bool Equals(object obj) 30 | { 31 | if (!ObjectIsCompatibleWithType(obj)) 32 | { 33 | return false; 34 | } 35 | 36 | var matcher = _matcher.Compile(); 37 | 38 | return matcher((T)obj); 39 | } 40 | 41 | protected bool Equals(Matcher other) 42 | { 43 | return Equals(_matcher, other._matcher) && string.Equals(_message, other._message); 44 | } 45 | 46 | public override int GetHashCode() 47 | { 48 | unchecked 49 | { 50 | return ((_matcher != null ? _matcher.GetHashCode() : 0) * 397) ^ (_message != null ? _message.GetHashCode() : 0); 51 | } 52 | } 53 | 54 | private static bool ObjectIsCompatibleWithType(object obj) 55 | { 56 | if (obj is T || obj == null) return true; 57 | 58 | if (IsNullable(typeof(T)) && GetInnerTypeFromNullable(typeof(T)) == obj.GetType()) 59 | return true; 60 | 61 | return false; 62 | } 63 | 64 | public override string ToString() 65 | { 66 | return _message; 67 | } 68 | 69 | // From https://github.com/structuremap/structuremap/blob/master/src/StructureMap/TypeExtensions.cs 70 | private static bool IsNullable(Type type) 71 | { 72 | return type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); 73 | } 74 | 75 | private static Type GetInnerTypeFromNullable(Type nullableType) 76 | { 77 | return nullableType.GetGenericArguments()[0]; 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/PlainBDD/OrderProcessorSpecs.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using NUnit.Framework; 3 | using Should; 4 | using SpecsFor.Demo.Domain; 5 | 6 | namespace SpecsFor.Demo.PlainBDD 7 | { 8 | public class OrderProcessorSpecs 9 | { 10 | public class given_the_item_is_available_when_processing_an_order : SpecsFor 11 | { 12 | private OrderResult _result; 13 | 14 | protected override void Given() 15 | { 16 | GetMockFor() 17 | .Setup(i => i.IsQuantityAvailable("TestPart", 10)) 18 | .Returns(true) 19 | .Verifiable(); 20 | } 21 | 22 | protected override void When() 23 | { 24 | _result = SUT.Process(new Order { PartNumber = "TestPart", Quantity = 10 }); 25 | } 26 | 27 | [Test] 28 | public void then_the_order_is_accepted() 29 | { 30 | _result.WasAccepted.ShouldBeTrue(); 31 | } 32 | 33 | [Test] 34 | public void then_it_checks_the_inventory() 35 | { 36 | GetMockFor().Verify(); 37 | } 38 | 39 | [Test] 40 | public void then_it_raises_an_order_submitted_event() 41 | { 42 | GetMockFor() 43 | .Verify(p => p.Publish(It.Is(o => o.OrderNumber == _result.OrderNumber))); 44 | } 45 | } 46 | 47 | public class given_the_item_is_not_available_when_processing_an_order : SpecsFor 48 | { 49 | private OrderResult _result; 50 | 51 | protected override void Given() 52 | { 53 | GetMockFor() 54 | .Setup(i => i.IsQuantityAvailable("TestPart", 10)) 55 | .Returns(false) 56 | .Verifiable(); 57 | } 58 | 59 | protected override void When() 60 | { 61 | _result = SUT.Process(new Order { PartNumber = "TestPart", Quantity = 10 }); 62 | } 63 | 64 | [Test] 65 | public void then_the_order_is_rejected() 66 | { 67 | _result.WasAccepted.ShouldBeFalse(); 68 | } 69 | 70 | [Test] 71 | public void then_it_checks_the_inventory() 72 | { 73 | GetMockFor().Verify(); 74 | } 75 | 76 | [Test] 77 | public void then_it_does_not_raise_an_order_submitted_event() 78 | { 79 | GetMockFor() 80 | .Verify(p => p.Publish(It.IsAny()), Times.Never()); 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /SpecsFor.Demo/BDD.Inheritance/OrderProcessorSpecs.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using NUnit.Framework; 3 | using Should; 4 | using SpecsFor.Demo.Domain; 5 | 6 | namespace SpecsFor.Demo.BDD.Inheritance 7 | { 8 | public class OrderProcessorSpecs 9 | { 10 | public class when_processing_an_order : given.the_item_is_available 11 | { 12 | private OrderResult _result; 13 | 14 | protected override void When() 15 | { 16 | _result = SUT.Process(new Order { PartNumber = "TestPart", Quantity = 10 }); 17 | } 18 | 19 | [Test] 20 | public void then_the_order_is_accepted() 21 | { 22 | _result.WasAccepted.ShouldBeTrue(); 23 | } 24 | 25 | [Test] 26 | public void then_it_checks_the_inventory() 27 | { 28 | GetMockFor().Verify(); 29 | } 30 | 31 | [Test] 32 | public void then_it_raises_an_order_submitted_event() 33 | { 34 | GetMockFor() 35 | .Verify(p => p.Publish(It.Is(o => o.OrderNumber == _result.OrderNumber))); 36 | } 37 | } 38 | 39 | 40 | public class when_processing_an_order_with_a_negative_quantity : given.the_item_is_available 41 | { 42 | private OrderResult _result; 43 | 44 | protected override void When() 45 | { 46 | _result = SUT.Process(new Order{ PartNumber = "TestPart", Quantity = -1}); 47 | } 48 | 49 | [Test] 50 | public void then_the_order_is_rejected() 51 | { 52 | _result.WasAccepted.ShouldBeFalse(); 53 | } 54 | 55 | [Test] 56 | public void then_it_does_not_check_the_inventory() 57 | { 58 | GetMockFor() 59 | .Verify(i => i.IsQuantityAvailable("TestPart", -1), Times.Never()); 60 | } 61 | 62 | [Test] 63 | public void then_it_does_not_raise_an_order_submitted_event() 64 | { 65 | GetMockFor() 66 | .Verify(p => p.Publish(It.IsAny()), Times.Never()); 67 | } 68 | } 69 | 70 | public class given 71 | { 72 | public abstract class the_item_is_available : SpecsFor 73 | { 74 | protected override void Given() 75 | { 76 | GetMockFor() 77 | .Setup(i => i.IsQuantityAvailable("TestPart", 10)) 78 | .Returns(true) 79 | .Verifiable(); 80 | } 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/PartialMatching/FuzzyMatchingExampleSpecs.cs: -------------------------------------------------------------------------------- 1 | using Beginners.Domain; 2 | using Beginners.Domain.MockingBasics; 3 | using NUnit.Framework; 4 | using SpecsFor; 5 | using SpecsFor.ShouldExtensions; 6 | 7 | namespace PartialMatching 8 | { 9 | public class FuzzyMatchingExampleSpecs 10 | { 11 | public class when_you_only_care_about_what_things_look_like : SpecsFor 12 | { 13 | [Test] 14 | public void then_you_can_check_for_a_non_null_value() 15 | { 16 | var engine = new Engine { Maker = "Heroic" }; 17 | engine.ShouldLookLike(() => new Engine 18 | { 19 | Maker = Any.NonNullValueOf() 20 | }); 21 | } 22 | 23 | [Test] 24 | public void then_you_can_check_for_a_value_in_a_range() 25 | { 26 | var engine = new Engine {YearBuilt = 2015}; 27 | engine.ShouldLookLike(() => new Engine 28 | { 29 | YearBuilt = Some.ValueInRange(2014, 2016) 30 | }); 31 | } 32 | 33 | [Test] 34 | public void then_you_can_check_for_a_value_matching_some_expression() 35 | { 36 | var engine = new Engine {Maker = "Heroic"}; 37 | engine.ShouldLookLike(() => new Engine 38 | { 39 | Maker = Some.ValueOf(s => char.IsUpper(s[0])) 40 | }); 41 | } 42 | 43 | [Test] 44 | public void then_you_can_check_for_an_item_in_a_list() 45 | { 46 | var warehouse = new Warehouse 47 | { 48 | Engines = new[] {new Engine {YearBuilt = 2013}, new Engine {YearBuilt = 2016}} 49 | }; 50 | 51 | warehouse.ShouldLookLike(() => new Warehouse 52 | { 53 | Engines = Some.ListContaining(() => new Engine 54 | { 55 | //Yep, you can use partial matching recursively! 56 | YearBuilt = Some.ValueOf(i => i % 2 == 0) 57 | }) 58 | }); 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /samples/SpecsForSamples/SpecsForWebHelpers.Specs/Controllers/HomeControllerSpecsWithoutHelpers.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using System.Web.Mvc; 3 | using NUnit.Framework; 4 | using Should; 5 | using SpecsFor; 6 | using SpecsFor.ShouldExtensions; 7 | using SpecsForWebHelpers.Web.Controllers; 8 | using SpecsForWebHelpers.Web.Domain; 9 | using SpecsForWebHelpers.Web.Models; 10 | 11 | namespace SpecsForWebHelpers.Specs.Controllers 12 | { 13 | public class HomeControllerSpecsWithoutHelpers 14 | { 15 | public class when_setting_the_users_name : SpecsFor 16 | { 17 | private ActionResult _result; 18 | 19 | protected override void When() 20 | { 21 | _result = SUT.SetName("Jane Doe"); 22 | } 23 | 24 | [Test] 25 | public void then_it_sets_the_name_of_the_user() 26 | { 27 | GetMockFor() 28 | .Verify(x => x.SetName("Jane Doe")); 29 | } 30 | 31 | [Test] 32 | public void then_it_redirects_back_home() 33 | { 34 | var routeResult = (RedirectToRouteResult)_result; 35 | routeResult.RouteValues["action"].ShouldEqual("Index"); 36 | } 37 | } 38 | 39 | public class when_saying_hello_to_a_user : SpecsFor 40 | { 41 | private ActionResult _result; 42 | 43 | protected override void When() 44 | { 45 | _result = SUT.SayHello("John Doe"); 46 | } 47 | 48 | [Test] 49 | public void then_it_says_hello_to_the_user() 50 | { 51 | var viewResult = _result.ShouldBeType(); 52 | var model = viewResult.Model.ShouldBeType(); 53 | model.ShouldLookLike(new SayHelloViewModel 54 | { 55 | Name = "John Doe" 56 | }); 57 | } 58 | } 59 | 60 | public class when_saying_hello_with_a_form : SpecsFor 61 | { 62 | private ActionResult _result; 63 | 64 | protected override void When() 65 | { 66 | _result = SUT.SayHello(new SayHelloForm { Name = "Jane Doe" }); 67 | } 68 | 69 | [Test] 70 | public void then_it_redirects_to_the_say_hello_action() 71 | { 72 | var redirectResult = _result.ShouldBeType(); 73 | redirectResult.RouteValues["controller"].ShouldEqual("Home"); 74 | redirectResult.RouteValues["action"].ShouldEqual("SayHello"); 75 | redirectResult.RouteValues["name"].ShouldEqual("Jane Doe"); 76 | } 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /SpecsFor.Core/ShouldExtensions/Some.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | 6 | namespace SpecsFor.Core.ShouldExtensions 7 | { 8 | public static class Some 9 | { 10 | public static TimeSpan DefaultDateTimeTolerance = TimeSpan.FromSeconds(1); 11 | 12 | public static T ValueOf(Expression> matcher) 13 | { 14 | Matcher.Create(matcher, "Object matching " + matcher.Body); 15 | 16 | return default(T); 17 | } 18 | 19 | public static T ValueInRange(T min, T max) where T : IComparable 20 | { 21 | return ValueInRange(min, max, true); 22 | } 23 | 24 | public static T ValueInRange(T min, T max, bool inclusive) where T: IComparable 25 | { 26 | if (inclusive) 27 | { 28 | var message = string.Format("Object greater than or equal to {0} and less than or equal to {1}", min, max); 29 | Matcher.Create(x => x.CompareTo(min) >= 0 && x.CompareTo(max) <= 0, message); 30 | } 31 | else 32 | { 33 | var message = string.Format("Object greater than {0} and less than {1}", min, max); 34 | Matcher.Create(x => x.CompareTo(min) > 0 && x.CompareTo(max) < 0, message); 35 | } 36 | 37 | return default(T); 38 | } 39 | 40 | public static DateTime DateTimeNear(DateTime value) 41 | { 42 | return DateTimeNear(value, null); 43 | } 44 | 45 | public static DateTime DateTimeNear(DateTime value, TimeSpan? tolerance) 46 | { 47 | var actualTolerance = tolerance ?? DefaultDateTimeTolerance; 48 | 49 | return ValueInRange(value.Subtract(actualTolerance), value.Add(actualTolerance)); 50 | } 51 | 52 | public static DateTimeOffset DateTimeNear(DateTimeOffset value) 53 | { 54 | return DateTimeNear(value, null); 55 | } 56 | 57 | public static DateTimeOffset DateTimeNear(DateTimeOffset value, TimeSpan? tolerance) 58 | { 59 | var actualTolerance = tolerance ?? DefaultDateTimeTolerance; 60 | 61 | return ValueInRange(value.Subtract(actualTolerance), value.Add(actualTolerance)); 62 | } 63 | 64 | public static T[] ListContaining(Expression> initializer) where T : class 65 | { 66 | Matcher.Create>(x => x.ContainsMatch(initializer), $"Expected list containing item matching [{initializer.Body}], but match was not found."); 67 | 68 | return default(T[]); 69 | } 70 | 71 | public static T[] ListContaining(T obj) 72 | { 73 | Matcher.Create>(x => x.Contains(obj), $"Expected list containing [{obj}], but item was not found."); 74 | 75 | return default(T[]); 76 | } 77 | } 78 | } --------------------------------------------------------------------------------