Ejemplo n.º 1
0
        public void SubscribeToForum_SubscribeCanRead_ReturnsValidObject()
        {
            int canReadOut = 0;
            MockRepository mocks = new MockRepository();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.TryGetIntOutputParameter("CanRead", out canReadOut)).Return(true).OutRef(1);
            //reader.Stub(x => x.AddParameter("reviewforumid", id)).Return(reader).AssertWasNotCalled(y => y.Throw(new Exception("AddParameter(reviewforumid, id) not called")));

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getforumpermissions")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("subscribetoforum")).Return(reader);
            mocks.ReplayAll();


            int userId = 1; 
            int forumId = 1; 
            bool unSubcribe = false; 
            SubscribeResult actual;
            actual = SubscribeResult.SubscribeToForum(creator, userId, forumId, unSubcribe);
            Assert.AreEqual(forumId, actual.ToForum);
            Assert.AreEqual(0, actual.Failed);
            
        }
        public void OnViewLoadedSetsCategorieIntheView()
        {
            // Mock the View
            MockRepository mocks = new MockRepository();
            //Arrange
            var service = mocks.DynamicMock<ICategorieService>();

            //Act
            var controller = mocks.DynamicMock<ICategorieController>();

            // Create Presenter With Mock View and Dummy BlogService
            CategorieService serviceActual = new MockCategorieService();
            var controllerActual = new CategorieController(serviceActual,null,null);
            var presenter = new CategorieenPresenter(controllerActual);
            var cat = new BeheerContextEntity { DataKeyValue = "added" };
            IList<BeheerContextEntity> list= new List<BeheerContextEntity>();
            list.Add(cat);
            //controller.AddBusinessEntity(cat);

            // Set Expectations  
            controller.Expect(action=>action.AddBusinessEntity(cat));
            //presenter.Expect(action => action.OnViewLoaded());
            
            
            // Tell Rhino Mocks We're Done Setting Expectations
            mocks.ReplayAll();
            presenter.OnViewLoaded();
            
            mocks.VerifyAll();


        }
Ejemplo n.º 3
0
 protected virtual void BeforeEachTest()
 {
     CreateMappings.Create();
     Mockery = new MockRepository();
     UnitOfWorkFactory = Mockery.DynamicMock<IUnitOfWorkFactory>();
     UnitOfWork = Mockery.DynamicMock<IUnitOfWork>();
 }
Ejemplo n.º 4
0
 public void List_getValidNumberAndReferencesOfNews()
 {
     var news = Builder<News>.CreateListOfSize(100)
                .Build();
     for (int page = 1; page < 10; page++)
     {
         Mockery = new MockRepository();
         var newsService = Mockery.DynamicMock<INewsService>();
         UnitOfWorkFactory = Mockery.DynamicMock<IUnitOfWorkFactory>();
         UnitOfWork = Mockery.DynamicMock<IUnitOfWork>();
         using (Mockery.Record())
         {
             Expect.Call(UnitOfWorkFactory.Create()).Return(UnitOfWork);
             Expect.Call(newsService.GetAll()).Return(news);
             Expect.Call(newsService.Get(Arg<Int32>.Is.Equal((page - 1) * Constants.NEWS_PAGER_LINKS_PER_PAGE), Arg<Int32>.Is.Equal(Constants.NEWS_PAGER_LINKS_PER_PAGE))).
             Return(news.Skip((page - 1) * Constants.NEWS_PAGER_LINKS_PER_PAGE).Take(Constants.NEWS_PAGER_LINKS_PER_PAGE).ToList());
         }
         IEnumerable<News> resultNews;
         using (Mockery.Playback())
         {
             var controller = new NewsController(newsService, UnitOfWorkFactory);
             var result = controller.List(page);
             resultNews = (IEnumerable<News>)result.Data;
         }
         var enumerable = resultNews as News[] ?? resultNews.ToArray();
         Assert.AreEqual(news.Skip((page - 1) * Constants.GIRLS_PAGER_LINKS_PER_PAGE).
             Take(Constants.GIRLS_PAGER_LINKS_PER_PAGE).Count(), enumerable.Count());
         if (enumerable.Count() != 0)
             Assert.AreEqual(news.Skip((page - 1) * Constants.GIRLS_PAGER_LINKS_PER_PAGE).
                 Take(Constants.GIRLS_PAGER_LINKS_PER_PAGE).First().Id, enumerable.First().Id);
     }
 }
Ejemplo n.º 5
0
        public void Initialize()
        {
            Queue<string> tags = new Queue<string>();
            tags.Enqueue("<2cents>");
            tags.Enqueue("<ale>");
            tags.Enqueue("<yikes>");
            tags.Enqueue(";)");
            tags.Enqueue("<3");
            

            Queue<string> tagTranslation = new Queue<string>();
            tagTranslation.Enqueue("2cents");
            tagTranslation.Enqueue("ale");
            tagTranslation.Enqueue("yikes");
            tagTranslation.Enqueue("winkeye");
            tagTranslation.Enqueue("specialheart");
            
            

            MockRepository mocks = new MockRepository();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(true);
            //reader.Stub(x => x.Read()).Return(true).Repeat.Times(4);
            reader.Stub(x => x.Read()).Return(true).Repeat.Times(4);
            reader.Stub(x => x.GetStringNullAsEmpty("name")).Return("").WhenCalled(x => x.ReturnValue = tagTranslation.Dequeue());
            reader.Stub(x => x.GetStringNullAsEmpty("tag")).Return("").WhenCalled(x => x.ReturnValue = tags.Dequeue());
            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getsmileylist")).Return(reader);
            mocks.ReplayAll();

            SmileyTranslator.LoadSmileys(creator);

            ProfanityFilterTests.InitialiseProfanities();
        }
Ejemplo n.º 6
0
 public void Setup()
 {
   _mocks = new MockRepository();
   _treeService = _mocks.DynamicMock<ITreeCreationService>();
   _naming = _mocks.DynamicMock<INamingService>();
   _mapper = new ViewSourceMapper(new NullLogger(), _treeService, _naming);
 }
Ejemplo n.º 7
0
 	public void Setup()
 	{
 		_mocks = new MockRepository();
     _task = _mocks.DynamicMock<ITask>();
     _engine = _mocks.DynamicMock<IBuildEngine>();
     _logger = new MsBuildLogger(new TaskLoggingHelper(_task));
 	}
Ejemplo n.º 8
0
 protected virtual void BeforeEachTest()
 {
     Mockery = new MockRepository();
     NHibernateInitializer = Mockery.DynamicMock<INHibernateInitializer>();
     SessionFactory = Mockery.DynamicMock<ISessionFactory>();
     NhCongiguration = Mockery.DynamicMock<Configuration>();
 }
        public void CanRegisterConsumer()
        {
            var mockRepository = new MockRepository();
            var rabbitModel = mockRepository.DynamicMock<IModel>();
            var messageSerializer = mockRepository.DynamicMock<IMessageSerializer>();
            var registeredConsumer = mockRepository.DynamicMock<IRegisteredConsumer>();
            var config = mockRepository.DynamicMock<IBrokerConfiguration>();

            using (mockRepository.Record())
            {
                SetupResult.For(registeredConsumer.Queue).Return("q");

                Expect.Call(rabbitModel.BasicConsume(null, false, null))
                    .IgnoreArguments()
                    .WhenCalled(mi =>
                                    {
                                        Assert.Equal("q", mi.Arguments[0] as string);
                                        Assert.Equal(false, (bool)mi.Arguments[1]);
                                        Assert.IsType(typeof(QueueActivityConsumer), mi.Arguments[2]);
                                    }).Return("token");
            }

            using (mockRepository.Playback())
            {
                var callbackConsumer = new GroupedCallbackConsumer(rabbitModel, messageSerializer, config);
                callbackConsumer.ConsumeQueue(registeredConsumer);

                Assert.Equal(1, callbackConsumer.QueueConsumers.Count);
                Assert.Equal(1, callbackConsumer.QueueConsumers.Values.Count);
                Assert.Equal("token", callbackConsumer.QueueConsumers.Values.First().ConsumeToken.ConsumerTag);

                callbackConsumer.Close();
                callbackConsumer.Dispose();
            }
        }
Ejemplo n.º 10
0
            public void When_Capture_Then_Original_Filter_Is_Switched_And_PutBack()
            {
                var mocks = new MockRepository();
                var context = mocks.DynamicMock<HttpContextBase>();
                var response = mocks.DynamicMock<HttpResponseBase>();
                var origFilter = mocks.DynamicMock<Stream>();

                var action = mocks.DynamicMock<Action>();

                using (mocks.Record())
                {
                    SetupResult.For(context.Response).Return(response);
                    SetupResult.For(response.ContentEncoding).Return(Encoding.ASCII);

                    Expect.Call(response.Filter).Return(origFilter);

                    response.Filter = null;
                    LastCall.IgnoreArguments().Constraints(Rhino.Mocks.Constraints.Is.TypeOf(typeof(CapturingResponseFilter)));

                    response.Filter = origFilter;
                }
                using (mocks.Playback())
                {
                    new BlockRenderer(context).Capture(action);
                }
            }
Ejemplo n.º 11
0
        public void GroupLayerCloneTest()
        {
            var mocks = new MockRepository();
            var map = mocks.StrictMock<Map>();
            map.Expect(m => m.IsDisposing).Return(false).Repeat.Any();

            var layer1 = mocks.DynamicMock<ILayer>();
            var layer1Clone = mocks.DynamicMock<ILayer>();
            layer1.Expect(l => l.Clone()).Return(layer1Clone).Repeat.Once();

            mocks.ReplayAll();

            var originalGroupLayer = new GroupLayer("original");
            originalGroupLayer.Map = map;
            originalGroupLayer.Layers.AddRange(new[]{layer1});
            originalGroupLayer.HasReadOnlyLayersCollection = true;

            var clone = (GroupLayer) originalGroupLayer.Clone();

            Assert.AreEqual("original", clone.Name);
            Assert.IsNull(clone.Map);
            Assert.IsTrue(clone.HasReadOnlyLayersCollection);

            mocks.VerifyAll();
        }
        public void AcksOnDelivery()
        {
            var mockRepository = new MockRepository();
            var rabbitModel = mockRepository.DynamicMock<IModel>();
            var messageSerializer = mockRepository.DynamicMock<IMessageSerializer>();
            var registeredConsumer = mockRepository.DynamicMock<IRegisteredConsumer>();
            var properties = mockRepository.Stub<IBasicProperties>();
            var config = mockRepository.DynamicMock<IBrokerConfiguration>();

            using (mockRepository.Record())
            {
                SetupResult.For(registeredConsumer.MessageType).Return(typeof (TestMessage));
                SetupResult.For(registeredConsumer.Queue).Return("q");
                SetupResult.For(registeredConsumer.ConsumerType).Return(typeof (TestConsumer));
                SetupResult.For(messageSerializer.DeserializeMessage(null)).IgnoreArguments().Return(
                    mockRepository.Stub<IMessageEnvelope<TestMessage>>());
                SetupResult.For(config.PipelineEvents).Return(new PipelineEvents());
                Expect.Call(() => rabbitModel.BasicAck(1, false));
            }

            using (mockRepository.Playback())
            {
                var callbackConsumer = new GroupedCallbackConsumer(rabbitModel, messageSerializer, config);
                callbackConsumer.ConsumeQueue(registeredConsumer);
                callbackConsumer.QueueConsumers["q"].Consumer.HandleBasicDeliver("ct1", 1, false, "ex", typeof(TestMessage).ToRoutingKey(), properties, new byte[0]);

                callbackConsumer.Close();
                callbackConsumer.Dispose();
            }
        }
Ejemplo n.º 13
0
        public void ProcessEvents_LogFiles_CorrectNames()
        {
            MockRepository mocks = new MockRepository();

            IDnaDataReaderCreator dataReaderCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            IDnaHttpClientCreator httpClientCreator = mocks.DynamicMock<IDnaHttpClientCreator>();
            IDnaDataReader dataReader = mocks.Stub<IDnaDataReader>();

            dataReaderCreator.Stub(x => x.CreateDnaDataReader("getexmoderationevents")).Return(dataReader);
            dataReader.Stub(x => x.Execute()).Return(dataReader);
            dataReader.Stub(x => x.Read()).Return(true).Repeat.Times(1);
            dataReader.Stub(x => x.Read()).Return(false);
            dataReader.Stub(x => x.GetInt32NullAsZero("modid")).Return(0);
            dataReader.Stub(x => x.GetString("notes")).Return("");
            dataReader.Stub(x => x.GetString("uri")).Return("");
            dataReader.Stub(x => x.GetDateTime("datecompleted")).Return(DateTime.Now);
            dataReader.Stub(x => x.GetInt32NullAsZero("status")).Return(0);
            dataReader.Stub(x => x.GetString("callbackuri")).Return("");

            IDnaLogger logger = new DnaLogger();

            mocks.ReplayAll();

            ExModerationProcessor exModProcessor = new ExModerationProcessor(dataReaderCreator, logger, httpClientCreator);

            exModProcessor.ProcessEvents(null);
        }
Ejemplo n.º 14
0
        public void ClosesOpenConnectionOnDispose()
        {
            var mockRepository = new MockRepository();
            var config = mockRepository.DynamicMock<IBrokerConfiguration>();
            var connFactory = mockRepository.DynamicMock<IBrokerConnectionFactory>();
            var conn = mockRepository.DynamicMock<IBrokerConnection>();
            var consumer = mockRepository.DynamicMock<IRegisteredConsumer>();

            using (mockRepository.Record())
            {
                SetupResult.For(consumer.MessageType).Return(typeof (TestMessage));
                SetupResult.For(connFactory.CreateConnection()).Return(conn);
                SetupResult.For(config.ConnectionFactory).Return(connFactory);
                SetupResult.For(config.RegisteredConsumers).Return(new Dictionary<Type, IList<IRegisteredConsumer>> { { typeof(TestMessage), new List<IRegisteredConsumer> { consumer } } });
                SetupResult.For(conn.IsOpen).Return(true);

                Expect.Call(conn.Close);
            }

            using (mockRepository.Playback())
            {
                var bus = new Bus(config);
                bus.GetLiveConnection();
                bus.Dispose();
            }
        }
Ejemplo n.º 15
0
        public void CanPublish()
        {
            var mockRepository = new MockRepository();
            var config = mockRepository.DynamicMock<IBrokerConfiguration>();
            var connFactory = mockRepository.DynamicMock<IBrokerConnectionFactory>();
            var conn = mockRepository.DynamicMock<IBrokerConnection>();
            var consumer = mockRepository.DynamicMock<IRegisteredConsumer>();
            var message = new TestMessage();

            using (mockRepository.Record())
            {
                SetupResult.For(consumer.MessageType).Return(typeof(TestMessage));
                SetupResult.For(connFactory.CreateConnection()).Return(conn);
                SetupResult.For(config.Exchange).Return("ex");
                SetupResult.For(config.ConnectionFactory).Return(connFactory);
                SetupResult.For(config.RegisteredConsumers).Return(new Dictionary<Type, IList<IRegisteredConsumer>> { { typeof(TestMessage), new List<IRegisteredConsumer> { consumer } } }); ;
                SetupResult.For(conn.IsOpen).Return(true);

                Expect.Call(() => conn.Publish<TestMessage>(null))
                    .IgnoreArguments()
                    .WhenCalled(mi =>
                            {
                                var envelope = mi.Arguments[0];

                                Assert.IsAssignableFrom(typeof(IMessageEnvelope<TestMessage>), envelope);
                                Assert.Same(message, ((IMessageEnvelope<TestMessage>)envelope).Message);
                            });
            }

            using (mockRepository.Playback())
            {
                var bus = new Bus(config);
                bus.Publish(message);
            }
        }
Ejemplo n.º 16
0
        public void SetUp()
        {
            _mocks = new MockRepository();

             _streamAdapter = _mocks.DynamicMock<IStreamAdapter>();
             _serializeAdapter = _mocks.DynamicMock<ISerializeAdapter>();
        }
Ejemplo n.º 17
0
        public void BuildAndExecuteRequest()
        {
            MockRepository mr = new MockRepository();

            IOAuthHelpers helpers = mr.DynamicMock<IOAuthHelpers>();
            IHttpImplemenation http = mr.DynamicMock<IHttpImplemenation>();

            DefaultOAuthRequestImplementation request = new DefaultOAuthRequestImplementation();
            request.SetHelperImplementation(helpers);
            request.SetHttpImplementaton(http);

            string testUrl = "TESTURL";
            var baseString = "BASESTRING";
            string consumerKey = "CONSUMER_KEY";
            string signature = "SIGNATURE";
            byte[] bytes = new byte[1] { (byte)1 };
            List<KeyValuePair<string, string>> args = new List<KeyValuePair<string, string>>();
            args.Add(new KeyValuePair<string, string>("key", "value"));

            using (mr.Record())
            {
                helpers.Expect(h => h.BuildBaseString("GET", testUrl, args)).Return(baseString);
                helpers.Expect(h => h.GetBytes(consumerKey)).Return(bytes);
                helpers.Expect(h => h.GetBytes(baseString)).Return(bytes);
                helpers.Expect(h => h.UrlEncode(String.Empty)).IgnoreArguments().Return(signature);
                http.Expect(x => x.CreateRequest("TESTURL?key=value&oauth_signature=SIGNATURE")).Return(null);
            }
            using (mr.Playback())
            {
                request.BuildAndExecuteRequest(testUrl, consumerKey, args);
            }
        }
Ejemplo n.º 18
0
        public void ApplyUserSettings_AsEditor_ReturnsReadWriteObject()
        {
            int siteId = 1;
            MockRepository mocks = new MockRepository();
            ISite site = mocks.DynamicMock<ISite>();
            site.Stub(x => x.SiteID).Return(siteId);
            IUser user = mocks.DynamicMock<IUser>();
            user.Stub(x => x.UserId).Return(1);
            user.Stub(x => x.IsEditor).Return(true);
            

            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getthreadgroupalertid")).Return(reader);
            mocks.ReplayAll();

            ForumThreadPosts target = new ForumThreadPosts();
            target.ApplyUserSettings(user, creator);
            Assert.AreEqual(target.CanRead, 1);
            Assert.AreEqual(target.CanWrite, 1);

            //test as superuser
            user = mocks.DynamicMock<IUser>();
            user.Stub(x => x.UserId).Return(1);
            user.Stub(x => x.IsSuperUser).Return(true);
            mocks.ReplayAll();

            target.ApplyUserSettings(user, creator);
            Assert.AreEqual(target.CanRead, 1);
            Assert.AreEqual(target.CanWrite, 1);
        }
Ejemplo n.º 19
0
        public void RetrieveDenialsForDirectory_Root_Group()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IFilesStorageProviderV30 filesProv = mocks.DynamicMock<IFilesStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            string dirName = Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(filesProv, "/");
            Expect.Call(aclManager.RetrieveEntriesForSubject("G.Group")).Return(
                new AclEntry[] {
                    new AclEntry(dirName, Actions.ForDirectories.List, "G.Group", Value.Deny),
                    new AclEntry(dirName, Actions.FullControl, "G.Group", Value.Grant),
                    new AclEntry("D." + AuthTools.GetDirectoryName(filesProv, "/Other/"), Actions.ForDirectories.UploadFiles, "G.Group", Value.Deny)
                });

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;

            string[] grants = AuthReader.RetrieveDenialsForDirectory(new UserGroup("Group", "Group", null),
                filesProv, "/");

            Assert.AreEqual(1, grants.Length, "Wrong denial count");
            Assert.AreEqual(Actions.ForDirectories.List, grants[0], "Wrong denial");
        }
Ejemplo n.º 20
0
 public void List_getValidNumberAndReferencesOfBeautifulGirls()
 {
     const int countOfBeautifulGirls= 50;
     var girls = Builder<Girl>.CreateListOfSize(2 * countOfBeautifulGirls)
                .All()
                     .With(x => x.Height = 175).With(x => x.Weight = 55).With(x => x.BirthDate = new DateTime(1990, 2, 2))
                .TheLast(countOfBeautifulGirls)
                     .With(x => x.Height = 180).With(x => x.Weight = 105).With(x => x.BirthDate = new DateTime(1990, 2, 2))
                .Build();
     for (int page = 1; page < 10; page++)
     {
         Mockery = new MockRepository();
         var girlService = Mockery.Stub<IGirlService>();
         UnitOfWorkFactory = Mockery.DynamicMock<IUnitOfWorkFactory>();
         UnitOfWork = Mockery.DynamicMock<IUnitOfWork>();
         using (Mockery.Record())
         {
             Expect.Call(UnitOfWorkFactory.Create()).Return(UnitOfWork);
             Expect.Call(girlService.GetBeautifulGirls()).Return(girls.Take(countOfBeautifulGirls).ToList());
         }
         IEnumerable<GirlModel> resultGirls;
         using (Mockery.Playback())
         {
             var controller = new GirlsController(girlService, UnitOfWorkFactory);
             var result = controller.List(page, true);
             resultGirls = (IEnumerable<GirlModel>) result.Data;
         }
         var girlModels = resultGirls as GirlModel[] ?? resultGirls.ToArray();
         Assert.AreEqual(girls.Take(countOfBeautifulGirls).Skip((page - 1) * Constants.GIRLS_PAGER_LINKS_PER_PAGE).
             Take(Constants.GIRLS_PAGER_LINKS_PER_PAGE).Count(), girlModels.Count());
         if (girlModels.Count() != 0)
             Assert.AreEqual(girls.Take(countOfBeautifulGirls).Skip((page - 1) * Constants.GIRLS_PAGER_LINKS_PER_PAGE).
                 Take(Constants.GIRLS_PAGER_LINKS_PER_PAGE).First().Id, girlModels.First().Id);
     }
 }
 public virtual void Setup()
 {
   _mocks = new MockRepository();
   _services = _mocks.DynamicMock<ICodeGeneratorServices>();
   _controller = _mocks.DynamicMock<TestController>();
   _factory = new DefaultControllerReferenceFactory();
 }
        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 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();
			}
		}
Ejemplo n.º 24
0
 public void ExtraParams()
 {
     var mocks = new MockRepository();
     var parser = mocks.DynamicMock<ISolrQueryResultParser<TestDocument>>();
     var conn = mocks.DynamicMock<ISolrConnection>();
     var serializer = mocks.StrictMock<ISolrQuerySerializer>();
     With.Mocks(mocks)
         .Expecting(() => Expect.On(serializer)
                              .Call(serializer.Serialize(null))
                              .IgnoreArguments()
                              .Return("123123"))
         .Verify(() => {
             var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, serializer, null, null);
             var p = queryExecuter.GetAllParameters(new SolrQuery("123123"), new QueryOptions {
                 ExtraParams = new Dictionary<string, string> {
                     {"qt", "geo"},
                     {"lat", "40.75141843299745"},
                     {"long", "-74.0093994140625"},
                     {"radius", "1"},
                 }
             }).ToDictionary(x => x.Key, x => x.Value);
             Assert.AreEqual("123123", p["q"]);
             Assert.AreEqual("geo", p["qt"]);
             Assert.AreEqual("1", p["radius"]);
         });
 }
Ejemplo n.º 25
0
 public void Init()
 {
     mocks = new MockRepository();
     config = mocks.StrictMock<IUserConfiguration>();
     view = mocks.DynamicMock<IProfileView>();
     manager = mocks.DynamicMock<IDataManager>();
     ClientServiceLocator.Register(config);
 }
Ejemplo n.º 26
0
 public void TestClientConnectionSetUp()
 {
     mocks = new MockRepository();
     mockSocket = mocks.DynamicMock<iSocket.iSocket>();
     mockClient = mocks.DynamicMock<Client.iClient>();
     connection = new Client.Connection(mockClient);
     connection.sock = mockSocket;
 }
        public void Init()
        {
            _mocks = new MockRepository();
            _workflow = _mocks.DynamicMock<IWorkflow>();
            _rendererFactory = _mocks.DynamicMock<IWorkStepRendererFactory>();

            _httpHandler = new WorkflowHttpHandler(_workflow, _rendererFactory);
        }
		public void Setup()
		{
			mocks = new MockRepository();
			logger = new NullLogger();
			typeResolver = mocks.DynamicMock<ITypeResolver>();
			treeService = mocks.DynamicMock<ITreeCreationService>();
			visitor = new WizardStepPageVisitor(logger, typeResolver, treeService);
		}
Ejemplo n.º 29
0
 public void Setup()
 {
   _mocks = new MockRepository();
   _logger = new NullLogger();
   _typeResolver = _mocks.DynamicMock<ITypeResolver>();
   _treeService = _mocks.DynamicMock<ITreeCreationService>();
   _visitor = new ControllerVisitor(_logger, _typeResolver, _treeService);
 }
Ejemplo n.º 30
0
        public void SetUp()
        {
            mocks = new MockRepository();
            persistenceService = mocks.DynamicMock<IPersistenceService>();
            repository = mocks.DynamicMock<IMyClassRepository>();

            BuilderSetup.SetPersistenceService(this.persistenceService);
        }
Ejemplo n.º 31
0
        public void can_start_uow()
        {
            var factory    = _mocks.DynamicMock <IUnitOfWorkFactory>();
            var unitOfWork = _mocks.DynamicMock <IUnitOfWork>();

            var fieldInfo = typeof(UnitOfWork).GetField("_unitOfWorkFactory",
                                                        BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);

            fieldInfo.SetValue(null, factory);
            using (_mocks.Record())
            {
                Expect.Call(factory.Create()).Return(unitOfWork);
            }
            using (_mocks.Playback())
            {
            }
        }
Ejemplo n.º 32
0
        public async Task C_F_RhinoMocksDynamicMockDoesntWorkWell()
        {
            var mocks   = new Rhino.Mocks.MockRepository();
            var service = mocks.DynamicMock <IService>();
            var sut     = new Sut
            {
                Service = service
            };

            mocks.ReplayAll();
            await sut.UseServiceAsync();

            mocks.VerifyAll();
        }
Ejemplo n.º 33
0
        public async Task C_G_RhinoMocksButIfYouExplicitlyExpectThenOfCourseItWorks()
        {
            var mocks   = new Rhino.Mocks.MockRepository();
            var service = mocks.DynamicMock <IService>();

            Expect.Call(service.DoSomethingAsync()).Return(Task.CompletedTask);
            var sut = new Sut
            {
                Service = service
            };

            mocks.ReplayAll();
            await sut.UseServiceAsync();

            mocks.VerifyAll();
        }
Ejemplo n.º 34
0
        private static ExpectationVerificationInformation GetExpectationsToVerify <T>(T mock, Action <T> action,
                                                                                      Action <IMethodOptions <object> >
                                                                                      setupConstraints)
        {
            IMockedObject  mockedObject = MockRepository.GetMockedObject(mock);
            MockRepository mocks        = mockedObject.Repository;

            if (mocks.IsInReplayMode(mockedObject) == false)
            {
                throw new InvalidOperationException(
                          "Cannot assert on an object that is not in replay mode. Did you forget to call ReplayAll() ?");
            }

            var mockToRecordExpectation =
                (T)mocks.DynamicMock(FindAppropriteType <T>(mockedObject), mockedObject.ConstructorArguments);

            action(mockToRecordExpectation);

            AssertExactlySingleExpectaton(mocks, mockToRecordExpectation);

            IMethodOptions <object> lastMethodCall = mocks.LastMethodCall <object>(mockToRecordExpectation);

            lastMethodCall.TentativeReturn();
            if (setupConstraints != null)
            {
                setupConstraints(lastMethodCall);
            }
            ExpectationsList expectationsToVerify = mocks.Replayer.GetAllExpectationsForProxy(mockToRecordExpectation);

            if (expectationsToVerify.Count == 0)
            {
                throw new InvalidOperationException(
                          "The expectation was removed from the waiting expectations list, did you call Repeat.Any() ? This is not supported in AssertWasCalled()");
            }
            IExpectation           expected             = expectationsToVerify[0];
            ICollection <object[]> argumentsForAllCalls = mockedObject.GetCallArgumentsFor(expected.Method);

            return(new ExpectationVerificationInformation
            {
                ArgumentsForAllCalls = new List <object[]>(argumentsForAllCalls),
                Expected = expected
            });
        }