private void Setup(IMockFactory factory)
        {
            var httpContext = factory.DynamicMock <HttpContextBase>();

            var request  = factory.DynamicMock <HttpRequestBase>();
            var response = factory.DynamicMock <HttpResponseBase>();
            var server   = factory.DynamicMock <HttpServerUtilityBase>();
            var cache    = HttpRuntime.Cache;

            httpContext.ReturnFor(c => c.Session, Session);
            httpContext.ReturnFor(c => c.Cache, cache);
            httpContext.SetupProperty(c => c.User);

            request.ReturnFor(r => r.QueryString, QueryString);
            request.ReturnFor(r => r.Form, Form);
            request.ReturnFor(r => r.Files, (HttpFileCollectionBase)Files);
            request.ReturnFor(r => r.ServerVariables, new NameValueCollection());
            request.CallbackFor(r => r.AcceptTypes, () => AcceptTypes);
            request.CallbackFor(r => r.Params, () => new NameValueCollection {
                QueryString, Form
            });
            request.CallbackFor(r => r.AppRelativeCurrentExecutionFilePath, () => AppRelativeCurrentExecutionFilePath);
            request.CallbackFor(r => r.ApplicationPath, () => ApplicationPath);
            request.CallbackFor(r => r.PathInfo, () => PathInfo);
            request.CallbackFor(r => r.RawUrl, () => RawUrl);
            response.SetupProperty(r => r.Status);

            httpContext.ReturnFor(c => c.Request, request.Object);
            httpContext.ReturnFor(c => c.Response, response.Object);
            httpContext.ReturnFor(c => c.Server, server.Object);

            HttpContext = httpContext.Object;
        }
 static ContainerBuilder CreateBuilder(IMockFactory mockFactory)
 {
     var containerBuilder = new ContainerBuilder();
     containerBuilder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
     containerBuilder.RegisterSource(new AutofacMockRegistrationHandler(mockFactory));
     return containerBuilder;
 }
        /// <summary>
        /// Creates a factory that will use the first creatable factory type.
        /// </summary>
        /// <param name="factoryTypes"></param>
        internal FirstAvailableMockFactory(params Type[] factoryTypes)
        {
            foreach (Type factoryType in factoryTypes)
            {
                try
                {
                    _realFactory = (IMockFactory)Activator.CreateInstance(factoryType);
                    break;
                }
                catch (TargetInvocationException ex)
                {
                    //Factories should throw an InvalidOperationException if they can't be
                    //instantiated due to a missing library.  If that happens, we want to
                    //attempt loading the next available factory.
                    if (ex.InnerException is InvalidOperationException)
                    {
                        continue;
                    }

                    throw;
                }
            }

            if (_realFactory == null)
            {
                throw new InvalidOperationException("Unable to create a factory.  Be sure a mocking framework is available.");
            }
        }
        static ContainerBuilder CreateBuilder(IMockFactory mockFactory)
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
            containerBuilder.RegisterSource(new AutofacMockRegistrationHandler(mockFactory));
            return(containerBuilder);
        }
Beispiel #5
0
        public TinyIoCContainer Create(IMockFactory mockFactory)
        {
            var container = new TinyIoCContainer();

            RegisterScenarios(container);
            RegisterScenarioContainer(container, mockFactory);
            return(container);
        }
Beispiel #6
0
        public ContainerBuilder Create(IMockFactory mockFactory)
        {
            var builder = new ContainerBuilder();

            RegisterScenarios(builder);
            RegisterScenarioContainer(builder, mockFactory);

            return(builder);
        }
 public ObservationContext(ITestState <Subject> test_state_implementation,
                           ISubjectDependencyBuilder subject_dependency_builder,
                           IMockFactory mock_factory,
                           ISubjectFactory subject_factory)
 {
     this.mock_factory = mock_factory;
     this.test_state   = test_state_implementation;
     this.subject_dependency_builder = subject_dependency_builder;
     this.subject_factory            = subject_factory;
 }
        public void GivenIHaveAnObservationContext()
        {
            this.testState = MockRepository.GenerateMock<ITestState<DummyClassWithSingleParameterisedConstructor>>();
            this.subjectDependencyBuilder = MockRepository.GenerateMock<ISubjectDependencyBuilder>();
            this.mockFactory = MockRepository.GenerateMock<IMockFactory>();
            this.subjectFactory = MockRepository.GenerateMock<ISubjectFactory>();

            this.subject = new ObservationContext<DummyClassWithSingleParameterisedConstructor>(
                this.testState, this.subjectDependencyBuilder, this.mockFactory, this.subjectFactory);
        }
Beispiel #9
0
        public TinyIoCContainer Create(IMockFactory mockFactory)
        {
            if (mockFactory == null)
            {
                mockFactory = new NullMockFactory();
            }

            var container = new TinyIoCContainer();

            RegisterScenarios(container);
            RegisterScenarioContainer(container, mockFactory);
            return(container);
        }
Beispiel #10
0
        //public AutoMockingContainer(MockRepository mocks, bool resolveProperties)
        //  : this(new MockRepositoryAdapter(mocks), resolveProperties)
        //{
        //}

        /// <summary>Creates an AutoMocking Container with the given <paramref name="mocks"/> repository.</summary>
        /// <param name="mocks">The mocks repository to use</param>
        /// <param name="resolveProperties"><c>true</c> if properties should be resolved, otherwise <c>false</c>; the defualt is <c>false</c></param>
        public AutoMockingContainer(MockRepository mocks, bool resolveProperties)
        {
            if (mocks == null)
            {
                _mockFactory = new AAAMockFactory();
            }
            else
            {
                _mockFactory = new DefaultMockFactory(mocks);
            }
            _mocks             = mocks;
            _resolveProperties = resolveProperties;
        }
Beispiel #11
0
 private void RegisterScenarioContainer(TinyIoCContainer container, IMockFactory mockFactory)
 {
     if (mockFactory.GetType() == typeof(NullMockFactory))
     {
         container.Register <IContainer>((c, p) => new TinyContainer(c.GetChildContainer()));
         this.Log()
         .DebugFormat("Registered {ScenarioContainer} for IContainer", "TinyContainer");
     }
     else
     {
         container.Register <IContainer>((c, p) => new TinyMockingContainer(mockFactory, c.GetChildContainer()));
         this.Log()
         .DebugFormat("Registered {ScenarioContainer} for IContainer with mock factory {MockFactory}", "TinyMockingContainer", mockFactory.MockProviderName);
     }
 }
        public static void RegisterSpecify(this ContainerBuilder builder, IMockFactory mockFactory = null)
        {
            if (builder == null)
            {
                builder = new ContainerBuilder();
            }

            if (mockFactory == null)
            {
                mockFactory = new NullMockFactory();
            }

            RegisterScenarios(builder);
            RegisterScenarioContainer(builder, mockFactory);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TestControllerBuilder"/> class using
        /// the specified mock factory to create any mock objects.
        /// </summary>
        public TestControllerBuilder(IMockFactory mockFactory)
        {
            AppRelativeCurrentExecutionFilePath = "~/";
            ApplicationPath = "/";
            PathInfo        = "";

            RouteData          = new RouteData();
            Session            = new MockSession();
            TempDataDictionary = new TempDataDictionary();
            QueryString        = new NameValueCollection();
            Form  = new NameValueCollection();
            Files = new WriteableHttpFileCollection();

            Setup(mockFactory);
        }
Beispiel #14
0
        private void RegisterScenarioContainer(ContainerBuilder builder, IMockFactory mockFactory)
        {
            if (mockFactory == null)
            {
                builder.Register <IContainer>(c => new AutofacContainer(c.Resolve <ILifetimeScope>().BeginLifetimeScope()));
                this.Log().DebugFormat("Registered {ScenarioContainer} for IContainer", "TinyContainer");
            }
            else
            {
                builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
                builder.RegisterSource(new AutofacMockRegistrationHandler(mockFactory));
                builder.Register <IContainer>(c => new AutofacContainer(c.Resolve <ILifetimeScope>().BeginLifetimeScope()));

                this.Log().DebugFormat("Registered {ScenarioContainer} for IContainer with mock factory {MockFactory}", "TinyMockingContainer", mockFactory.MockProviderName);
            }
        }
Beispiel #15
0
        public Testable(params object[] dependancies)
        {
            this.MockFactory = (IMockFactory)Activator.CreateInstance(typeof(TMockFactory));

            // Protects against null errors
            this.Dependancies = new Dictionary <Type, object>();

            // Inject dependacies for any constructors
            var ctor = GetConstructor();
            var constructorInstances = CreateInstancesOfConstructorParameters(ctor.GetParameters(), dependancies ?? new object[0]);

            this.Instance = (T)ctor.Invoke(constructorInstances.ToArray());

            // Inject any dependancies for any property dependancies
            var properties = GetPropertiesFromType();

            CreateInstancesForProperties(properties, dependancies);
            SetPropertyObjects(properties, this.Dependancies);
        }
Beispiel #16
0
 public Mokkit(IMockFactory mockFactory)
 {
     _mockFactory = mockFactory;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TinyMockingContainer"/> class.
 /// </summary>
 /// <param name="mockFactory">The mock factory.</param>
 /// <param name="container">The container.</param>
 public TinyMockingContainer(IMockFactory mockFactory, TinyIoCContainer container)
     : base(container)
 {
     _mockFactory = mockFactory;
 }
Beispiel #18
0
        public Scenery(IMockFactory mockFactory)
        {
            _mockFactory = mockFactory;

            Mokkit = new Mokkit <TMokkitToken>(mockFactory);
        }
Beispiel #19
0
 public AutoMockingContainer(IMockFactory mockFactory)
     : base(CreateBuilder(mockFactory))
 {
 }
 public AutofacMockRegistrationHandler(IMockFactory mockFactory)
 {
     _mockFactory = mockFactory;
 }
 public AutofacAutoMockingContainer(IMockFactory mockFactory)
     : base(CreateBuilder(mockFactory))
 {
 }
Beispiel #22
0
 /// <summary>
 /// Creates a mock with the given parameters.
 /// </summary>
 /// <param name="factory">The <see cref="IMockFactory"/> used to create instances of mocks.</param>
 /// <param name="mocksAssembly">Assembly where compile-time generated mocks exist.</param>
 /// <returns>A mock that implements <see cref="IMocked"/> in addition to the specified <typeparamref name="T"/>.</returns>
 public static T CreateMock <T>(this IMockFactory factory, Assembly mocksAssembly)
 => (T)factory.CreateMock(mocksAssembly, typeof(T), new Type[0], new object[0]);
 public AutofacMockRegistrationHandler(IMockFactory mockFactory)
 {
     _mockFactory = mockFactory;
 }
 public SubjectDependencyBuilder(IDependencyBag dependency_bag, IMockFactory mock_factory)
 {
     this.dependency_bag = dependency_bag;
     this.mock_factory   = mock_factory;
 }