public void An_object_with_all_its_properties_stubbed_is_returned()
        {
            var stubService = new StubService();
            var obj = stubService.GetStubbedObject<NullablePrimitiveThing>();

            //TODO:  Make Randomizer methods for all primitive types
            Assert.NotNull(obj.Boolean);
            Assert.NotNull(obj.Byte);
            Assert.NotNull(obj.Char);
            Assert.NotNull(obj.DateTime);
            Assert.NotNull(obj.Decimal);
            Assert.NotNull(obj.Double);
            Assert.NotNull(obj.Float);
            Assert.NotNull(obj.Int16);
            Assert.NotNull(obj.Int32);
            Assert.NotNull(obj.Int64);
            Assert.NotNull(obj.IntPtr);
            Assert.NotNull(obj.SignedByte);
            Assert.NotNull(obj.Single);
            Assert.NotNull(obj.String);
            Assert.NotNull(obj.UnsignedInt16);
            Assert.NotNull(obj.UnsignedInt32);
            Assert.NotNull(obj.UnsignedInt64);
            Assert.NotNull(obj.UnsignedIntPtr);
        }
        private static Func <Type, object> CreateStubServiceFactoryFor(StubService service)
        {
            var factory = MockRepository.GenerateStub <Func <Type, object> >();

            factory.Stub(x => x(Arg <Type> .Is.Equal(typeof(StubService)))).Return(service);
            return(factory);
        }
Пример #3
0
        public void CreateInvocationDelegate_CalledWithServiceMethodThatReturnsNoResponse_ExpectReturnedDelegateReturnsDefaultResponse(
            StubService service, object request, Request dto, Response defaultResponse)
        {
            var lambda = (Func <object, object>) new SyncServiceMethodInvocation().CreateInvocationDelegate(
                InfoOf.Method <StubService>(x => x.ServiceMethodWithNoResponse(null)),
                Stub.InvocationContextFor(service, request, dto, defaultResponse));

            lambda(request).Should().BeSameAs(defaultResponse);
        }
Пример #4
0
        public void CreateInvocationDelegate_CalledWithAsyncDecoratedMethodWithCancellationToken_ExpectReturnedDelegateReturnsDefaultResponse(
            StubService service, object request, Request dto, Response defaultResponse)
        {
            var lambda = (Func <object, CancellationToken, Task <object> >) new AsyncVoidServiceMethodInvocation().CreateInvocationDelegate(
                InfoOf.Method <StubService>(svc => svc.AsyncDecoratedMethodWithCancellationToken(null, CancellationToken.None)),
                Stub.InvocationContextFor(service, request, dto, defaultResponse));

            lambda(request, CancellationToken.None).Result.Should().BeSameAs(defaultResponse);
        }
		public void Init()
		{
			_service = new StubService();
			_dispatcher = new LocalInvocationDispatcher(service =>
			{
				if (service == serviceName) return Tuple.Create<object,Type>(_service, _service.GetType());
				throw new Exception("service not found");
			}, new ProtoBufSerializationStrategy());
		}
        public void Its_first_layer_of_complex_properties_are_stubbed()
        {
            var stubService = new StubService();
            var person = stubService.GetStubbedObject<ComplexPerson>();

            Assert.NotNull(person.House);
            Assert.That(person.House.Bathrooms != 0);
            Assert.That(person.House.Floors != 0);
            Assert.That(person.House.SquareFeet != 0);
        }
Пример #7
0
        public void InjectAStubAndGetTheStubBack()
        {
            var stub = new StubService();

            _container.Inject <IMockedService>(stub);

            Assert.AreSame(stub, _container.GetInstance <IMockedService>());
            Assert.AreSame(stub, _container.GetInstance <IMockedService>());
            Assert.AreSame(stub, _container.GetInstance <IMockedService>());
        }
        public void InjectAStubAndGetTheStubBack()
        {
            var stub = new StubService();

            _container.Inject <IMockedService>(stub);

            stub.ShouldBeTheSameAs(_container.GetInstance <IMockedService>());
            stub.ShouldBeTheSameAs(_container.GetInstance <IMockedService>());
            stub.ShouldBeTheSameAs(_container.GetInstance <IMockedService>());
        }
Пример #9
0
        public void return_weather_if_range_of_korea(double lat, double lng, Observation observationWeather)
        {
            //Arrange
            Location GangNam_gu = new Location(lat, lng);
            var      sut        = new StubService(observationWeather);

            //Action
            var Reqeust = new Func <Observation>(() => sut.Request_NowWeatherAsync(GangNam_gu).Result);

            //Assert
            Reqeust.Should().NotThrow <Exception>();
        }
Пример #10
0
        public void Guard_throw_exception_if_out_of_range_korea(double lat, double lng, Observation observationWeather)
        {
            //Arrange
            Location location = new Location(lat, lng);
            var      sut      = new StubService(observationWeather);

            //Action
            var Reqeust = new Func <Observation>(() => sut.Request_NowWeatherAsync(location).Result);

            //Assert
            Reqeust.Should().Throw <KoreaWeatherAPIException>();
        }
 public void Init()
 {
     _service    = new StubService();
     _dispatcher = new LocalInvocationDispatcher(service =>
     {
         if (service == serviceName)
         {
             return(Tuple.Create <object, Type>(_service, _service.GetType()));
         }
         throw new Exception("service not found");
     }, new ProtoBufSerializationStrategy());
 }
        public void All_its_premative_properties_are_stubbed()
        {
            var stubService = new StubService();
            var person = stubService.GetStubbedObject<ComplexPerson>();

            Assert.NotNull(person);
            Assert.That(!string.IsNullOrWhiteSpace(person.FirstName));
            Assert.That(!string.IsNullOrWhiteSpace(person.LastName));
            Assert.That(!string.IsNullOrWhiteSpace(person.MiddleName));
            Assert.That(!string.IsNullOrWhiteSpace(person.NickName));
            Assert.That(!string.IsNullOrWhiteSpace(person.PhoneNumber));
            Assert.That(person.Age != 0);
        }
        public void All_of_the_objects_it_contains_are_fully_hydrated()
        {
            var stubService = new StubService();
            var people = stubService.GetStubbedObject<IEnumerable<SimplePerson>>();

            Assert.NotNull(people);
            Assert.IsNotEmpty(people);
            Assert.That(people.All(person => !string.IsNullOrWhiteSpace(person.FirstName)));
            Assert.That(people.All(person => !string.IsNullOrWhiteSpace(person.MiddleName)));
            Assert.That(people.All(person => !string.IsNullOrWhiteSpace(person.LastName)));
            Assert.That(people.All(person => !string.IsNullOrWhiteSpace(person.NickName)));
            Assert.That(people.All(person => !string.IsNullOrWhiteSpace(person.PhoneNumber)));
            Assert.That(people.All(person => person.Age != 0));
        }
        public void All_its_properties_are_populated()
        {
            var stubService = new StubService();
            var person = stubService.GetStubbedObject<SimplePerson>();

            Assert.NotNull(person);
            Assert.That(!string.IsNullOrWhiteSpace(person.FirstName));
            Assert.That(!string.IsNullOrWhiteSpace(person.LastName));
            Assert.That(!string.IsNullOrWhiteSpace(person.MiddleName));
            Assert.That(!string.IsNullOrWhiteSpace(person.NickName));
            Assert.That(!string.IsNullOrWhiteSpace(person.PhoneNumber));
            Assert.That(person.Age != 0);
            Assert.That(person.DateOfBirth > new DateTime(1930, 1, 1) && person.DateOfBirth < new DateTime(1999, 12, 31));
        }
        public void Its_second_layer_of_complex_properties_are_stubbed()
        {
            var stubService = new StubService();
            var person = stubService.GetStubbedObject<ComplexPerson>();

            Assert.NotNull(person.House.Address);
            Assert.That(!string.IsNullOrWhiteSpace(person.House.Address.Street1));
            Assert.That(!string.IsNullOrWhiteSpace(person.House.Address.Street2));
            Assert.That(!string.IsNullOrWhiteSpace(person.House.Address.City));
            Assert.That(!string.IsNullOrWhiteSpace(person.House.Address.State));
            Assert.That(!string.IsNullOrWhiteSpace(person.House.Address.County));
            Assert.That(!string.IsNullOrWhiteSpace(person.House.Address.Country));
            Assert.That(!string.IsNullOrWhiteSpace(person.House.Address.Zip));
        }
Пример #16
0
        public void TheAutoMockerPushesInMocksAndAPreBuiltStubForAllOfTheConstructorArguments()
        {
            AutoMocker <ConcreteClass> autoMocker = createAutoMocker <ConcreteClass>();
            var stub = new StubService();

            autoMocker.Inject <IMockedService>(stub);

            var service2 = autoMocker.Get <IMockedService2>();
            var service3 = autoMocker.Get <IMockedService3>();

            ConcreteClass concreteClass = autoMocker.ClassUnderTest;

            Assert.AreSame(stub, concreteClass.Service);
            Assert.AreSame(service2, concreteClass.Service2);
            Assert.AreSame(service3, concreteClass.Service3);
        }
Пример #17
0
        public void TheAutoMockerPushesInMocksAndAPreBuiltStubForAllOfTheConstructorArguments()
        {
            var autoMocker = createAutoMocker <ConcreteClass>();
            var stub       = new StubService();

            autoMocker.Inject <IMockedService>(stub);

            var service2 = autoMocker.Get <IMockedService2>();
            var service3 = autoMocker.Get <IMockedService3>();

            var concreteClass = autoMocker.ClassUnderTest;

            stub.ShouldBeTheSameAs(concreteClass.Service);
            service2.ShouldBeTheSameAs(concreteClass.Service2);
            service3.ShouldBeTheSameAs(concreteClass.Service3);
        }
        public void ExpectOverridingRegistrarDispatchContextMultipleTimesInheritsSettingsFromPreviousContext(RouteRegistrar registrar, Guid token)
        {
            var module  = new StubModule();
            var service = new StubService();
            var factory = MockRepository.GenerateMock <Func <Type, object> >();

            factory.Stub(x => x(Arg <Type> .Is.Anything)).Return(service);

            registrar
            .WithDispatchContext(x => x.WithServiceFactory(factory))
            .WithDispatchContext(x => x.WithDefaultResponse(token))
            .RegisterServiceInto(module, typeof(StubService));

            new Browser(with => with.Module(module)).Get <Guid>("/void").Should().Be(token);
            factory.AssertWasCalled(x => x(Arg <Type> .Is.Equal(typeof(StubService))), x => x.Repeat.Once());
        }
Пример #19
0
        //[Test]
        public void Analyze_WebServiceThrows_SendsEmail()
        {
            var stubService = new StubService();

            stubService.ToThrow = new Exception("fake exception");

            var mockEmail = new MockEmailService();

            var log = new LogAnalyzer2(stubService, mockEmail);

            string tooShortFileName = "abc.ext";

            log.Analyze(tooShortFileName);

            Assert.AreEqual("a", mockEmail.To);
            Assert.AreEqual("fake exception", mockEmail.Body);
            Assert.AreEqual("subject", mockEmail.Subject);
        }
		private static Func<Type, object> CreateStubServiceFactoryFor(StubService service)
		{
			var factory = MockRepository.GenerateStub<Func<Type, object>>();
			factory.Stub(x => x(Arg<Type>.Is.Equal(typeof(StubService)))).Return(service);
			return factory;
		}
		public void ExpectOverridingRegistrarDispatchContextMultipleTimesInheritsSettingsFromPreviousContext(RouteRegistrar registrar, Guid token)
		{
			var module = new StubModule();
			var service = new StubService();
			var factory = MockRepository.GenerateMock<Func<Type, object>>();
			factory.Stub(x => x(Arg<Type>.Is.Anything)).Return(service);

			registrar
				.WithDispatchContext(x => x.WithServiceFactory(factory))
					.WithDispatchContext(x => x.WithDefaultResponse(token))
					.RegisterServiceInto(module, typeof(StubService));

			new Browser(with => with.Module(module)).Get<Guid>("/void").Should().Be(token);
			factory.AssertWasCalled(x => x(Arg<Type>.Is.Equal(typeof(StubService))), x => x.Repeat.Once());
		}
Пример #22
0
        public void DisposedHearbeat()
        {
            var service = new StubService();

            service.RunProcess();
        }
Пример #23
0
 public TestCompoundWithConstructorWithoutMatchingArgument(StubService invalidArgument)
 {
 }
		public void CreateInvocationDelegate_CalledWithNonAsyncDecoratedMethodWithCancellationToken_ExpectReturnedDelegateReturnsDefaultResponse(
			StubService service, object request, Request dto, object defaultResponse)
		{
			var lambda = (Func<object, CancellationToken, Task<object>>) new AsyncTaskServiceMethodInvocation().CreateInvocationDelegate(
				InfoOf.Method<StubService>(svc => svc.NonAsyncDecoratedMethodWithCancellationTokenAndTaskResponse(null, CancellationToken.None)),
				Stub.InvocationContextFor(service, request, dto, defaultResponse));

			lambda(request, CancellationToken.None).Result.Should().BeSameAs(defaultResponse);
		}
Пример #25
0
 private TestDecoratorWithConstructorWithoutMatchingArgument(StubService argument)
 {
 }
 public void Invocation()
 {
     StubRpcServiceDescriptor service = new StubRpcServiceDescriptor();
     RpcMethodDescriptor method = new RpcMethodDescriptor(service, StubService.SumInfo);
     StubService serviceInstance = new StubService();
     object result = method.Invoke(serviceInstance, new object[] { 2, 3 });
     Assert.AreEqual(5, result);
 }
Пример #27
0
 public TestTypeWithTooManyPublicConstructors(StubService param)
 {
 }