Ejemplo n.º 1
0
 public void Setup()
 {
     _autoSubstitute = AutoSubstituteContainer.Create();
     _h = _autoSubstitute.ResolveAndSubstituteFor<HtmlHelper<TestFieldViewModel>>();
     _t = _autoSubstitute.Resolve<IFormTemplate>();
     _t.BeginForm(Action, Method, _htmlAttributes, Enctype).Returns(_beginHtml);
     _t.EndForm().Returns(_endHtml);
 }
Ejemplo n.º 2
0
 public void Setup()
 {
     _autoSubstitute = AutoSubstituteContainer.Create();
     _h = _autoSubstitute.ResolveAndSubstituteFor <HtmlHelper <TestFieldViewModel> >();
     _t = _autoSubstitute.Resolve <IFormTemplate>();
     _t.BeginForm(Action, Method, _htmlAttributes, Enctype).Returns(_beginHtml);
     _t.EndForm().Returns(_endHtml);
 }
        public RoleCoordinatorTests(ITestOutputHelper output)
        {
            var builder = new AutoSubstitute();
            builder.Provide<ILogger>(new TestLogger(output));

            this.persistentState = Substitute.ForPartsOf<InMemoryPersistentState>();
            builder.Provide<IRaftPersistentState>(this.persistentState);

            builder.ResolveAndSubstituteFor<FollowerRole<int>>();

            // After the container is configured, resolve required services.
            this.coordinator = builder.Resolve<RoleCoordinator<int>>();
            this.container = builder;
        }
        public RoleCoordinatorTests(ITestOutputHelper output)
        {
            var builder = new AutoSubstitute();

            builder.Provide <ILogger>(new TestLogger(output));

            this.persistentState = Substitute.ForPartsOf <InMemoryPersistentState>();
            builder.Provide <IRaftPersistentState>(this.persistentState);

            builder.ResolveAndSubstituteFor <FollowerRole <int> >();

            // After the container is configured, resolve required services.
            this.coordinator = builder.Resolve <RoleCoordinator <int> >();
            this.container   = builder;
        }
Ejemplo n.º 5
0
        public void Example_test_with_substitute_for_concrete_resolved_from_autofac()
        {
            const int val1           = 2;
            const int val2           = 3;
            const int val3           = 4;
            var       AutoSubstitute = new AutoSubstitute();

            // Much better / more maintainable than:
            //AutoSubstitute.SubstituteFor<ConcreteClassWithDependency>(AutoSubstitute.Resolve<IDependency1>(), val1);
            AutoSubstitute.ResolveAndSubstituteFor <ConcreteClassWithDependency>(new TypedParameter(typeof(int), val1));
            AutoSubstitute.Resolve <IDependency2>().SomeOtherMethod().Returns(val2);
            AutoSubstitute.Resolve <IDependency1>().SomeMethod(val1).Returns(val3);

            var result = AutoSubstitute.Resolve <MyClassWithConcreteDependencyThatHasDependencies>().AMethod();

            Assert.That(result, Is.EqualTo(val2 * val3 * 2));
        }
Ejemplo n.º 6
0
        public void TestGetMachineByName()
        {
            var autoSubstitute = new AutoSubstitute();

            autoSubstitute.Resolve <IHyperVConfiguration>().FetchNamespacePath().Returns("TestNameSpace");

            autoSubstitute.Resolve <IHyperVConfiguration>().FetchServer().Returns("TestServer");

            autoSubstitute.Resolve <IHyperVConfiguration>().FetchUsername().Returns("TestUsername");

            autoSubstitute.Resolve <IHyperVConfiguration>().FetchPassword().Returns("TestPassword");

            var provider = autoSubstitute.ResolveAndSubstituteFor <IHyperVProvider>();

            var machine = new HyperVMachine(
                new ManagementObject("")
                );

            provider.GetMachineByName("Test").Returns(machine);

            provider.GetMachineByName("Test").Should().Be(machine);
        }
Ejemplo n.º 7
0
 public TSubstitute SubstituteFor <TSubstitute>() where TSubstitute : class
 {
     return(AutoSubstitute.ResolveAndSubstituteFor <TSubstitute>());
 }
        public void Example_test_with_substitute_for_concrete_resolved_from_autofac()
        {
            const int val1 = 2;
            const int val2 = 3;
            const int val3 = 4;
            var AutoSubstitute = new AutoSubstitute();
            // Much better / more maintainable than:
            //AutoSubstitute.SubstituteFor<ConcreteClassWithDependency>(AutoSubstitute.Resolve<IDependency1>(), val1);
            AutoSubstitute.ResolveAndSubstituteFor<ConcreteClassWithDependency>(new TypedParameter(typeof(int), val1));
            AutoSubstitute.Resolve<IDependency2>().SomeOtherMethod().Returns(val2);
            AutoSubstitute.Resolve<IDependency1>().SomeMethod(val1).Returns(val3);

            var result = AutoSubstitute.Resolve<MyClassWithConcreteDependencyThatHasDependencies>().AMethod();

            Assert.That(result, Is.EqualTo(val2*val3*2));
        }
 public void Setup()
 {
     _autoSubstitute = AutoSubstituteContainer.Create();
     _h = _autoSubstitute.ResolveAndSubstituteFor <HtmlHelper <TestViewModel> >();
 }