public void Should_throw_exception_When_no_dependency_provided_for_value_type() { var builder = new AutoMock <Target_ValueTypeDependency>(); //ACT Assert.That(() => builder.SelectConstructor(), Throws.TypeOf <Exception>()); }
public void Should_build_target_When_value_dependency() { //ARRANGE var container = new DependencyContainer(); container.AddDependencyInstance(true); container.AddDependencyInstance(new Byte()); container.AddDependencyInstance('c'); container.AddDependencyInstance(new Decimal()); container.AddDependencyInstance((double)1); container.AddDependencyInstance((float)1); container.AddDependencyInstance((int)1); container.AddDependencyInstance((long)1); container.AddDependencyInstance((sbyte)1); container.AddDependencyInstance((short)1); container.AddDependencyInstance((uint)1); container.AddDependencyInstance((ulong)1); container.AddDependencyInstance((ushort)1); container.AddDependencyInstance("string"); var builder = new AutoMock <Target_ValueTypeDependency>(container); //ACT builder.SelectConstructor(); var target = builder.CreateTarget(); //ASSERT Assert.IsNotNull(target); }
public void Should_throw_When_no_constructor_with_dependencies() { //ARRANGE var builder = new AutoMock <Target_NoParametrizedConstructor>(); //ACT Assert.That(() => builder.SelectConstructor(), Throws.TypeOf <InvalidOperationException>()); }
public void Should_throw_When_no_constructor_with_chosen_number_of_parameters() { //ARRANGE var builder = new AutoMock <Target_ConstructorsWithDifferentParametersCount>(); //ACT Assert.That(() => builder.SelectConstructor(999), Throws.TypeOf <InvalidOperationException>()); }
public void Should_throw_When_more_then_one_constructor_with_chosen_number_of_parameters() { //ARRANGE var builder = new AutoMock <Target_MultipleConstructorsWithSameParametersCount>(); //ACT Assert.That(() => builder.SelectConstructor(2), Throws.TypeOf <InvalidOperationException>()); }
public void Should_throw_When_more_constructor_with_dependencies() { //ARRANGE var builder = new AutoMock <Target_ConstructorsWithDifferentParametersCount>(); //ACT Assert.That(() => builder.SelectConstructor(), Throws.TypeOf <InvalidOperationException>()); }
public void Should_throw_When_getting_dependency_registered_under_multiple_names() { //ARRANGE var builder = new AutoMock <Target_SameTypeDependency>(); //ACT builder.SelectConstructor(); Assert.That(() => builder.GetMock <IDependency>(), Throws.TypeOf <InvalidOperationException>()); }
public void Should_throw_when_getting_not_created_mock_parameter_name() { //ARRANGE var builder = new AutoMock <Target>(); //ACT builder.SelectConstructor(); Assert.That(() => builder.GetMock <IDependency>("notExistingName"), Throws.TypeOf <InvalidOperationException>()); }
public void Should_use_custom_mock_factory() { //ARRANGE var builder = new AutoMock <Target_ConcreteDependency>(new CustomMockFactory()); //ACT builder.SelectConstructor(); //ASSERT Assert.IsNotNull(builder.GetMock <DependencyImplementation1>()); }
public void Should_build_target_When_not_provided_dependencies() { var builder = new AutoMock <Target>(); //ACT builder.SelectConstructor(); var target = builder.CreateTarget(); //ASSERT Assert.IsNotNull(target); }
public void Should_get_injected_mock() { //ARRANGE var builder = new AutoMock <Target>(); //ACT builder.SelectConstructor(); //ASSERT Assert.IsNotNull(builder.GetMock <IDependency>()); }
public void Should_call_proper_constructor_When_selecting_by_parameters_number() { //ARRANGE var builder = new AutoMock <Target_ConstructorsWithDifferentParametersCount>(); //ACT builder.SelectConstructor(2); var target = builder.CreateTarget(); //ASSERT Assert.IsNotNull(target); }
public void Should_get_injected_mock_When_multiple_dependencies_of_the_same_type() { //ARRANGE var builder = new AutoMock <Target_SameTypeDependency>(); //ACT builder.SelectConstructor(); //ASSERT Assert.IsNotNull(builder.GetMock <IDependency>("d1")); Assert.IsNotNull(builder.GetMock <IDependency>("d2")); }
public void Should_build_parametrized_target_When_default_constructor() { //ARRANGE var builder = new AutoMock <Target>(); //ACT builder.SelectConstructor(); var target = builder.CreateTarget(); //ASSERT Assert.AreEqual(typeof(Target), target.GetType()); }
public void Should_throw_when_two_implementations_of_the_same_interface_injected() { //ARRANGE var container = new DependencyContainer(); container.AddDependencyInstance(new DependencyImplementation1()); container.AddDependencyInstance(new DependencyImplementation2()); var builder = new AutoMock <Target>(container); //ACT Assert.That(() => builder.SelectConstructor(), Throws.TypeOf <InvalidOperationException>()); }
public void Should_build_target_When_provided_dependencies() { //ASSERT var container = new DependencyContainer(); container.AddDependencyInstance(Substitute.For <IDependency>()); var builder = new AutoMock <Target>(container); //ACT builder.SelectConstructor(); var target = builder.CreateTarget(); //ASSERT Assert.IsNotNull(target); }
public void should_use_custom_mock_and_dependency_container() { //ARRANGE var container = new DependencyContainer(); container.AddDependencyInstance(new DependencyImplementation1()); var builder = new AutoMock <Target_TwoConcreteDependencies>(new CustomMockFactory(), container); //ACT builder.SelectConstructor(); //ASSERT Assert.IsNotNull(builder.GetMock <DependencyImplementation2>()); }
public void Should_build_target_When_multiple_dependencies_of_the_same_type() { //ARRANGE var container = new DependencyContainer(); container.AddDependencyInstance(Substitute.For <IDependency>(), "d1"); container.AddDependencyInstance(Substitute.For <IDependency>(), "d2"); var builder = new AutoMock <Target_SameTypeDependency>(container); //ACT builder.SelectConstructor(); var target = builder.CreateTarget(); //ASSERT Assert.IsNotNull(target); }
public void Should_create_mocks_build_target_and_inject_mocks_to_constructor_with_two_dependencies() { // ASSERT var builder = new AutoMock <Driver>(); builder.SelectConstructor(2); var driver = builder.CreateTarget(); //ACT driver.Drive(); //ASSERT Assert.IsNotNull(builder.GetMock <IVehicle>()); Assert.IsNotNull(builder.GetMock <IDrivingLicense>()); builder.GetMock <IVehicle>() .Received() .Drive(); }
public void Should_create_mocks_build_target_and_inject_mocks_to_constructor_selected_by_function() { // ASSERT var builder = new AutoMock <Driver>(); builder.SelectConstructor(SelectConstructorFunc); var driver = builder.CreateTarget(); //ACT driver.Drive(); //ASSERT Assert.IsNotNull(builder.GetMock <IVehicle>()); Assert.IsNotNull(builder.GetMock <IDrivingLicense>()); builder.GetMock <IVehicle>() .Received() .Drive(); }
public void Should_create_mocks_build_target_and_inject_dependencies_and_mocks() { // ASSERT var container = new DependencyContainer(); container.AddDependencyInstance(new FancyGloves()); var builder = new AutoMock <Driver>(container); builder.SelectConstructor(); var driver = builder.CreateTarget(); //ACT driver.Drive(); //ASSERT Assert.IsNotNull(builder.GetMock <IVehicle>()); Assert.IsNotNull(builder.GetMock <IDrivingLicense>()); builder.GetMock <IVehicle>() .Received() .Drive(); }