public void Setup()
 {
     mock = new MockRepository();
     mockContext = mock.PartialMock<TestBasketballContext>();
     // TODO This doesn't work
     eventRepository = mock.PartialMock<EventRepository>(mockContext);
     eventService = new EventService(eventRepository);
 }
        public void Read_TwoMessages()
        {
            var mocks = new MockRepository();
            var adapter = mocks.PartialMock<CrossPlatformUdpClient>(new UdpClient());

            // first datagram
            Expect.Call(adapter.Read())
                .Return(new List<byte>(new byte[] { 1 }));

            // second datagram
            Expect.Call(adapter.Read())
                .Return(new List<byte>(new byte[] { 2, 3, 4 }));

            mocks.ReplayAll();

            // read first datagram
            var buffer = new byte[1];
            Assert.AreEqual(1, adapter.Read(buffer, 0, 1));

            // read second datagram
            buffer = new byte[3];
            Assert.AreEqual(3, adapter.Read(buffer, 0, 3));

            Assert.AreEqual(new byte[] { 2, 3, 4 }, buffer);

            mocks.VerifyAll();
        }
        public void UnicastMessage_AcknowlegeSlaveException()
        {
            MockRepository mocks = new MockRepository();
            ModbusTransport transport = mocks.PartialMock<ModbusTransport>();

            // set the wait to retry property to a small value so the test completes quickly
            transport.WaitToRetryMilliseconds = 5;

            transport.Write(null);
            LastCall.IgnoreArguments();

            // return a slave exception a greater number of times than number of retries to make sure we aren't just retrying
            Expect.Call(transport.ReadResponse<ReadHoldingInputRegistersResponse>())
                .Return(new SlaveExceptionResponse(1, Modbus.ReadHoldingRegisters + Modbus.ExceptionOffset,
                    Modbus.Acknowledge))
                .Repeat.Times(transport.Retries + 1);

            Expect.Call(transport.ReadResponse<ReadHoldingInputRegistersResponse>())
                .Return(new ReadHoldingInputRegistersResponse(Modbus.ReadHoldingRegisters, 1, new RegisterCollection(1)));

            transport.OnValidateResponse(null, null);
            LastCall.IgnoreArguments();

            mocks.ReplayAll();

            ReadHoldingInputRegistersRequest request = new ReadHoldingInputRegistersRequest(
                Modbus.ReadHoldingRegisters, 1, 1, 1);
            ReadHoldingInputRegistersResponse expectedResponse =
                new ReadHoldingInputRegistersResponse(Modbus.ReadHoldingRegisters, 1, new RegisterCollection(1));
            ReadHoldingInputRegistersResponse response =
                transport.UnicastMessage<ReadHoldingInputRegistersResponse>(request);
            Assert.AreEqual(expectedResponse.MessageFrame, response.MessageFrame);

            mocks.VerifyAll();
        }
 public void SetUp()
 {
     mocker = new MockRepository();
     service = mocker.PartialMock<HarvestService>();
     harvestor = mocker.CreateMock<IHarvester>();
     scripter = mocker.CreateMock<ISqlScripter>();
 }
        public void IssueToken_CalledOnFederationBinding_CallsIssueToken()
        {
            // Arrange
            var returnToken = MockRepository.GenerateStub<SecurityToken>();
            var mockRepository = new MockRepository();
            var securityTokenProvider = mockRepository.PartialMock<SecurityTokenProvider>();
            securityTokenProvider.Stub(x => x.IssueToken(Arg<IWSTrustChannelContract>.Is.Anything, Arg<string>.Is.Anything, Arg<SecurityToken>.Is.Anything, Arg<SecurityToken>.Is.Anything)).Return(returnToken);
            securityTokenProvider.Replay();

            var binding = MockRepository.GenerateStub<WS2007FederationHttpBinding>();
            var messageSecurityOverHttp = new FederatedMessageSecurityOverHttp
            {
                IssuerAddress = new EndpointAddress("http://localhost/issuer"),
                IssuerBinding = new WS2007HttpBinding()
            };
            binding.Security.Message = messageSecurityOverHttp;
            var actAsToken = MockRepository.GenerateStub<SecurityToken>();

            // Act
            var actual = securityTokenProvider.IssueToken(binding, "http://localhost/service", actAsToken);

            // Assert
            securityTokenProvider.AssertWasCalled(
                x => x.IssueToken(Arg<IWSTrustChannelContract>.Is.Anything, Arg<string>.Is.Anything, Arg<SecurityToken>.Is.Anything, Arg<SecurityToken>.Is.Anything));
            Assert.AreEqual(returnToken, actual);
        }
		public void WillInitializeAllModuleLoadersOnStart()
		{

			MockRepository mocks = new MockRepository();
			IModuleLoader mockLoader1 = mocks.DynamicMock<IModuleLoader>();
			IModuleLoader mockLoader2 = mocks.DynamicMock<IModuleLoader>();
			IModuleLoader mockLoader3 = mocks.DynamicMock<IModuleLoader>();
			IShellView stubShell = mocks.Stub<IShellView>();
			DefaultApplicationContext context = mocks.PartialMock<DefaultApplicationContext>(
				stubShell, new IModuleLoader[] { mockLoader1, mockLoader2, mockLoader3 });

			using (mocks.Record())
			{
				//we may have order dependnecies, let us verify
				//that it does this in order
				using (mocks.Ordered())
				{
					mockLoader1.Initialize(context, stubShell);
					mockLoader2.Initialize(context, stubShell);
					mockLoader3.Initialize(context, stubShell);
				}

				//force context to ignore these calls
				Expect.Call(context.GetShellAsForm()).Return(null).Repeat.Once();
				Expect.Call(delegate { context.RunForm(null); }).Repeat.Once();
			}

			using (mocks.Playback())
			{
				context.Start();
			}
		}
        public void FiltersOnParseAndFormat()
        {
            MockRepository mocks = new MockRepository();
            IFormatter underlyingFormatter = mocks.StrictMock<IFormatter>();
            TestFilteringFormatter formatter = (TestFilteringFormatter) mocks.PartialMock(typeof (TestFilteringFormatter), underlyingFormatter);

            string inputText = "inputText";
            string filteredInputText = "filteredInputText";
            object outputValue = new object();
            object filteredOutputValue = new object();

            using(mocks.Ordered())
            {
                Expect.Call(formatter.DoFilterValueToParse(inputText)).Return(filteredInputText);
                Expect.Call(underlyingFormatter.Parse(filteredInputText)).Return(outputValue);

                Expect.Call(formatter.DoFilterValueToFormat(outputValue)).Return(filteredOutputValue);
                Expect.Call(underlyingFormatter.Format(filteredOutputValue)).Return(inputText);
            }
            mocks.ReplayAll();

            Assert.AreSame(outputValue, formatter.Parse(inputText));
            Assert.AreEqual(inputText, formatter.Format(outputValue));

            mocks.VerifyAll();
        }
        public void When_application_context_is_started_it_will_initialized_all_the_module_loader()
		{

            MockRepository mocks = new MockRepository();
            IModuleLoader mockLoader1 = mocks.DynamicMock<IModuleLoader>();
            IModuleLoader mockLoader2 = mocks.DynamicMock<IModuleLoader>();
            IModuleLoader mockLoader3 = mocks.DynamicMock<IModuleLoader>();
            IApplicationShell stubShell = mocks.Stub<IApplicationShell>();
            DefaultApplicationContext context = mocks.PartialMock<DefaultApplicationContext>(
                stubShell, 
				mocks.DynamicMock<ILayoutRegistry>(),
				new IModuleLoader[] { mockLoader1, mockLoader2, mockLoader3 });

            //we may have order dependnecies, let us verify
            //that it does this in order
            using (mocks.Record())
            using (mocks.Ordered())
            {
                mockLoader1.Initialize(context, stubShell);
                mockLoader2.Initialize(context, stubShell);
                mockLoader3.Initialize(context, stubShell);
            }

            using (mocks.Playback())
            {
                context.Start();
            }
        }
 public static PageDefinitionSynchronizationEngine PartialMock(MockRepository fakesRepository)
 {
     return fakesRepository.PartialMock<PageDefinitionSynchronizationEngine>(
         new PageDefinitionUpdater(new PageDefinitionRepository(), new TabDefinitionRepository(), new PageDefinitionTypeMapper(new PageDefinitionTypeRepository(), new NativePageDefinitionsMap())),
         new PageTypePropertyDefinitionLocator(),
         new PageDefinitionSpecificPropertySettingsUpdater(() => new PropertySettingsRepository(), new GlobalPropertySettingsLocator(new AppDomainAssemblyLocator()), new PageDefinitionRepository()));
 }
 public static PageTypePropertyUpdater PartialMock(MockRepository fakesRepository)
 {
     return fakesRepository.PartialMock<PageTypePropertyUpdater>(
         new PageDefinitionFactory(),
         new PageDefinitionTypeFactory(),
         new TabFactory());
 }
Exemplo n.º 11
0
        public void RegisterCustomFunction_FunctionAlreadyExists()
        {
            MockRepository mocks = new MockRepository();
            var slave = mocks.PartialMock<ModbusSlave>((byte) 1, new EmptyTransport());

            slave.RegisterCustomFunction<TestMessage>(100, (request, dataStore) => { throw new NotImplementedException(); });
            Assert.Throws<ArgumentException>(() => slave.RegisterCustomFunction<TestMessage>(100, (request, dataStore) => { throw new NotImplementedException(); }));
        }
Exemplo n.º 12
0
		protected virtual MementoEntity CreateMock( IChangeTrackingService memento, bool registerAsrTransient ) 
		{
			MockRepository mocks = new MockRepository();
			var entity = mocks.PartialMock<MementoEntity>( memento, registerAsrTransient );
			entity.Replay();

			return entity;
		}
Exemplo n.º 13
0
		protected virtual MementoEntity CreateMock( bool registerAsrTransient ) 
		{
			MockRepository mocks = new MockRepository();
			var entity = mocks.PartialMock<MementoEntity>( registerAsrTransient );
			entity.Replay();

			return entity;
		}
Exemplo n.º 14
0
		protected override Entity CreateMock()
		{
			MockRepository mocks = new MockRepository();
			var entity = mocks.PartialMock<MementoEntity>();
			entity.Replay();

			return entity;
		}
Exemplo n.º 15
0
 public static File File(MockRepository mocks, int id)
 {
     var file = mocks.PartialMock<File>();
     SetupResult.For(file.GetHashCode()).Return(random.Next());
     SetupResult.For(file.FullName).Return(id.ToString());
     SetupResult.For(file.Name).Return(id.ToString());
     return file;
 }
Exemplo n.º 16
0
		public void RequestBytesToReadDiagnostics()
		{
			MockRepository mocks = new MockRepository();
			var mockSlave = mocks.PartialMock<ModbusSlave>((byte) 1, new EmptyTransport());

			byte[] frame = { 0x01, 0x08, 0x00, 0x00, 0xA5, 0x37, 0, 0 };
			Assert.AreEqual(1, ModbusRtuTransport.RequestBytesToRead(frame, mockSlave));
		}
Exemplo n.º 17
0
		public void RequestBytesToReadCoils()
		{
			MockRepository mocks = new MockRepository();
			var mockSlave = mocks.PartialMock<ModbusSlave>((byte) 1, new EmptyTransport());

			byte[] frameStart = { 0x11, 0x01, 0x00, 0x13, 0x00, 0x25 };
			Assert.AreEqual(1, ModbusRtuTransport.RequestBytesToRead(frameStart, mockSlave));
		}
        public void ReadRequest()
        {
            MockRepository mocks = new MockRepository();
            ModbusRtuTransport transport = mocks.PartialMock<ModbusRtuTransport>(MockRepository.GenerateStub<IStreamResource>());
            var mockSlave = mocks.PartialMock<ModbusSlave>((byte) 1, new EmptyTransport());

            Expect.Call(transport.Read(ModbusRtuTransport.RequestFrameStartLength))
                .Return(new byte[] { 1, 1, 1, 0, 1, 0, 0 });

            Expect.Call(transport.Read(1))
                .Return(new byte[] { 5 });

            mocks.ReplayAll();

            Assert.AreEqual(new byte[] { 1, 1, 1, 0, 1, 0, 0, 5 }, transport.ReadRequest(mockSlave));
            mocks.VerifyAll();
        }
Exemplo n.º 19
0
 public void BuildMessageFrame()
 {
     MockRepository mocks = new MockRepository();
     ModbusIpTransport mockModbusTcpTransport = mocks.PartialMock<ModbusIpTransport>(MockRepository.GenerateStub<IStreamResource>());
     ReadCoilsInputsRequest message = new ReadCoilsInputsRequest(Modbus.ReadCoils, 2, 10, 5);
     mocks.ReplayAll();
     Assert.AreEqual(new byte[] { 0, 0, 0, 0, 0, 6, 2, 1, 0, 10, 0, 5 }, mockModbusTcpTransport.BuildMessageFrame(message));
     mocks.VerifyAll();
 }
Exemplo n.º 20
0
        public void Init()
        {
            mocks = new MockRepository();

            view = mocks.PartialMock<SparkView>();

            engineContext = new StubEngineContext(new UrlInfo("", "Home", "Index", "/", "castle"));
            controllerContext = new ControllerContext();
        }
Exemplo n.º 21
0
        public void SetUp()
        {
            mocks = new MockRepository();
            cache = (ExposingAbstractCache)mocks.PartialMock(typeof(ExposingAbstractCache));

            expectedPerItemTTL = new TimeSpan(0, 0, 10);
            expectedPerCacheTTL = new TimeSpan(0, 0, 20);

            cache.TimeToLive = expectedPerCacheTTL;
        }
 private PageTypeDefinitionPropertiesValidator CreateValidatorWithFakeValidatePageTypePropertyMethodCalls(PropertyInfo propertyInfo)
 {
     MockRepository fakes = new MockRepository();
     PageTypeDefinitionPropertiesValidator propertiesValidator = fakes.PartialMock<PageTypeDefinitionPropertiesValidator>((PageDefinitionTypeMapper)null);
     propertiesValidator.Stub(validator => validator.ValidateCompilerGeneratedProperty(propertyInfo));
     propertiesValidator.Stub(validator => validator.ValidatePageTypePropertyAttribute(propertyInfo));
     propertiesValidator.Stub(validator => validator.ValidatePageTypePropertyType(propertyInfo));
     propertiesValidator.Replay();
     return propertiesValidator;
 }
		public void entityItemViewFilterBase_interface_shouldInclude_using_null_reference_should_raise_ArgumentNullException()
		{
			MockRepository mocks = new MockRepository();

			var filter = mocks.PartialMock<EntityItemViewFilterBase<GenericParameterHelper>>();
			filter.Replay();

			var target = ( IEntityItemViewFilter )filter;
			target.ShouldInclude( null );
		}
Exemplo n.º 24
0
        public void OnActionExecutingWithoutSecurityTest()
        {
            MockRepository mockRepo = new MockRepository();
            ActionExecutingContext context = mockRepo.PartialMock<ActionExecutingContext>();
            SecurityAttribute attribute = mockRepo.PartialMock<SecurityAttribute>();
            HttpContextBase httpContext = mockRepo.PartialMock<HttpContextBase>();
            HttpRequestBase httpRequest = mockRepo.PartialMock<HttpRequestBase>();

            Expect.Call(httpRequest.RawUrl).Return("TestUrl").Repeat.Any();
            Expect.Call(httpContext.Request).Return(httpRequest).Repeat.Any();
            Expect.Call(context.HttpContext).Return(httpContext).Repeat.Any();
            Expect.Call(attribute.HasPermission(context)).Return(false);
            attribute.Expect(x => x.ProccessNoPermissionResult(context)).Do(
                (Action<ActionExecutingContext>)(filterContext => filterContext.Result = new RedirectToLoginResult()));

            mockRepo.ReplayAll();
            attribute.OnActionExecuting(context);
            mockRepo.VerifyAll();
            Assert.IsTrue(context.Result is RedirectToLoginResult);
        }
Exemplo n.º 25
0
		public void Write()
		{
			MockRepository mocks = new MockRepository();
			var mockTcpStreamAdapter = mocks.StrictMock<IStreamResource>();
			mockTcpStreamAdapter.Write(new byte[] { 255, 255, 0, 0, 0, 6, 1, 1, 0, 1, 0, 3 }, 0, 12);
			ModbusIpTransport mockModbusTcpTransport = mocks.PartialMock<ModbusIpTransport>(mockTcpStreamAdapter);
			Expect.Call(mockModbusTcpTransport.GetNewTransactionId()).Return(UInt16.MaxValue);
			mocks.ReplayAll();
			ReadCoilsInputsRequest request = new ReadCoilsInputsRequest(Modbus.ReadCoils, 1, 1, 3);
			mockModbusTcpTransport.Write(request);
			mocks.VerifyAll();
		}
Exemplo n.º 26
0
        public void ParametersPassed()
        {
            //Arrange
            var mocks = new MockRepository();
            var list = mocks.PartialMock<ArrayList>(500);

            mocks.ReplayAll();
            //Act
            Assert.AreEqual(500, list.Capacity);
            //Assert
            mocks.VerifyAll();
        }
Exemplo n.º 27
0
        public void OnActionExecutingWithSecurityTest()
        {
            MockRepository mockRepo = new MockRepository();
            ActionExecutingContext context = mockRepo.DynamicMock<ActionExecutingContext>();
            SecurityAttribute attribute = mockRepo.PartialMock<SecurityAttribute>();

            Expect.Call(attribute.HasPermission(context)).Return(true);
            mockRepo.ReplayAll();
            attribute.OnActionExecuting(context);
            mockRepo.VerifyAll();
            Assert.IsFalse(context.Result is RedirectToLoginResult);
        }
		public void entityItemViewFilterBase_toString_normal_should_return_expected_value()
		{
			var expected = "Default name.";

			MockRepository mocks = new MockRepository();

			var target = mocks.PartialMock<EntityItemViewFilterBase<GenericParameterHelper>>();
			target.Replay();

			var actual = target.ToString();

			actual.Should().Be.EqualTo( expected );
		}
        public void ReadRequestResponseNotEnoughBytes()
        {
            MockRepository mocks = new MockRepository();
            IStreamResource mockSerialResource = mocks.StrictMock<IStreamResource>();

            var mockTransport = mocks.PartialMock<ModbusAsciiTransport>(mockSerialResource);
            ExpectReadLine(mockSerialResource, Encoding.ASCII.GetBytes(":10\r\n"));
            mocks.ReplayAll();

            Assert.Throws<IOException>(() => mockTransport.ReadRequestResponse());

            mocks.VerifyAll();
        }
 public void UsingPartialMocks()
 {
     MockRepository mocks = new MockRepository();
     ProcessorBase proc = mocks.PartialMock<ProcessorBase>();
     Expect.Call(proc.Add(1)).Return(1);
     Expect.Call(proc.Add(1)).Return(2);
     mocks.ReplayAll();
     proc.Inc();
     Assert.AreEqual(1, proc.Register);
     proc.Inc();
     Assert.AreEqual(2, proc.Register);
     mocks.VerifyAll();
 }