当前位置: 首页>>代码示例>>C#>>正文


C# Mock.SetupAllProperties方法代码示例

本文整理汇总了C#中Mock.SetupAllProperties方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.SetupAllProperties方法的具体用法?C# Mock.SetupAllProperties怎么用?C# Mock.SetupAllProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mock的用法示例。


在下文中一共展示了Mock.SetupAllProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetWebRequest

			public IHttpWebRequest GetWebRequest(Uri url)
			{
				var mock = new Mock<IHttpWebRequest>();
				mock.SetupAllProperties();
				mock.Setup(m => m.GetResponse())
					.Returns(() =>
					{
						var mockResponse = new Mock<IHttpWebResponse>();
						mockResponse.SetupAllProperties();
						mockResponse.SetupProperty(m => m.Headers, new WebHeaderCollection());

						byte[] responseContent = new byte[0];
						if (mock.Object.Method == "GET")
						{
							if (url.AbsolutePath == "/movies/")
								responseContent = Encoding.UTF8.GetBytes(GetFromResources("SimpleBrowser.UnitTests.SampleDocs.movies1.htm"));
							if (url.AbsolutePath == "/movies/Movies/Create")
								responseContent = Encoding.UTF8.GetBytes(GetFromResources("SimpleBrowser.UnitTests.SampleDocs.movies2.htm"));
						}
						else if (mock.Object.Method == "POST")
						{
							if (url.AbsolutePath == "/movies/Movies/Create")
							{
								mockResponse.Object.StatusCode = HttpStatusCode.Moved;
								mockResponse.Object.Headers.Add(HttpResponseHeader.Location, "http://localhost/movies/");
							}
						}
						mockResponse.Setup(r => r.GetResponseStream()).Returns(new MemoryStream(responseContent));
						return mockResponse.Object;
					});
				mock.SetupProperty(m => m.Headers, new WebHeaderCollection());
				mock.Setup(m => m.GetRequestStream()).Returns(new MemoryStream(new byte[20000]));
				return mock.Object;
			}
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:34,代码来源:Helper.cs

示例2: test_setup

        public void test_setup()
        {
            currentChainMock = new Mock<ICurrentChain>();
            currentChainMock.SetupAllProperties();

            handler = new Home.GetHandler(currentChainMock.Object);
        }
开发者ID:tappm,项目名称:FubuMVC.Recipes,代码行数:7,代码来源:GetHandlerTests.cs

示例3: GetInspectionResults

        public Task<PartialViewResult> GetInspectionResults(string code)
        {
            //Arrange
            var builder = new MockVbeBuilder();
            VBComponent component;

            // ensure line endings are \r\n
            code = code.Replace("\r\n", "\n").Replace("\n", "\r\n");
            var vbe = builder.BuildFromSingleStandardModule(code, out component);

            var mockHost = new Mock<IHostApplication>();
            mockHost.SetupAllProperties();

            var parser = MockParser.Create(vbe.Object, _state);
            Task.Run(() => parser.Parse(new System.Threading.CancellationTokenSource())).Wait();
            if (parser.State.Status >= ParserState.Error)
            {
                throw new ArgumentException(parser.State.Status.ToString());
            }

            var results = _inspector.Inspect(parser.State);

            if (results.Any())
            {
                return Task.FromResult(PartialView("~/Views/Home/InspectionResults.cshtml", results));
            }

            return Task.FromResult(PartialView("~/Views/Home/NoInspectionResults.cshtml", results));
        }
开发者ID:rubberduck-vba,项目名称:RubberduckWeb,代码行数:29,代码来源:InspectionsController.cs

示例4: UseMeaningfulName_ReturnsResult_NameEndsWithDigit

        public void UseMeaningfulName_ReturnsResult_NameEndsWithDigit()
        {
            const string inputCode =
@"Sub Foo1()
End Sub";

            //Arrange
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("VBAProject", vbext_ProjectProtection.vbext_pp_none)
                .AddComponent("MyClass", vbext_ComponentType.vbext_ct_ClassModule, inputCode)
                .Build();
            var vbe = builder.AddProject(project).Build();

            var mockHost = new Mock<IHostApplication>();
            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState());

            parser.Parse();
            if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }

            var inspection = new UseMeaningfulNameInspection(null, parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(1, inspectionResults.Count());
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:25,代码来源:UseMeaningfulNameInspectionTests.cs

示例5: ReloadData_CollectionNull_CollectionInstantiated

        public void ReloadData_CollectionNull_CollectionInstantiated()
        {
            var accountsLoaded = false;
            var transactionsLoaded = false;
            var categoryLoaded = false;

            var accountRepoSetup = new Mock<IAccountRepository>();
            accountRepoSetup.SetupAllProperties();
            accountRepoSetup.Setup(x => x.Load(It.IsAny<Expression<Func<Account, bool>>>()))
                .Callback(() => accountsLoaded = true);

            var transactionRepoSetup = new Mock<ITransactionRepository>();
            transactionRepoSetup.SetupAllProperties();
            transactionRepoSetup.Setup(x => x.Load(It.IsAny<Expression<Func<FinancialTransaction, bool>>>()))
                .Callback(() => transactionsLoaded = true);

            var categoryRepoSetup = new Mock<IRepository<Category>>();
            categoryRepoSetup.SetupAllProperties();
            categoryRepoSetup.Setup(x => x.Load(It.IsAny<Expression<Func<Category, bool>>>()))
                .Callback(() => categoryLoaded = true);

            var accountRepo = accountRepoSetup.Object;
            var transactionRepo = transactionRepoSetup.Object;

            new RepositoryManager(accountRepo, transactionRepo, categoryRepoSetup.Object,
                new TransactionManager(transactionRepo, accountRepo, new Mock<IDialogService>().Object))
                .ReloadData();

            accountsLoaded.ShouldBeTrue();
            transactionsLoaded.ShouldBeTrue();
            categoryLoaded.ShouldBeTrue();
        }
开发者ID:jgodinez,项目名称:MoneyManager,代码行数:32,代码来源:RepositoryManagerTests.cs

示例6: Build

        public ISessionDataService Build()
        {
            var mock = new Mock<ISessionDataService>();
            mock.SetupAllProperties();

            mock.Setup(s => s.SessionExists(It.IsAny<Guid>(), It.IsAny<IUser>(), It.IsAny<bool>()))
                .Returns(
                    (Guid identifier,
                     IUser user,
                     bool includeExpired)
                    => Sessions.Any(
                        x => x.Identifier == identifier
                             && x.User.Active
                             && x.User.Email == user.Email
                             && (includeExpired || x.ExpiresOn > DateTime.UtcNow
                                ))
                );

            mock.Setup(s => s.CreateSession(It.IsAny<IUser>()))
                .Returns((IUser user) => _sessionBuilder
                                             .Build(s => { s.User = user; }));

            mock.Setup(s => s.InsertSession(It.IsAny<ISession>()))
                .Callback((ISession session) => Sessions.Add(session));

            return mock.Object;
        }
开发者ID:MrAntix,项目名称:Poci,代码行数:27,代码来源:SessionDataServiceBuilder.cs

示例7: FunctionReturnValueNotUsed_ReturnsResult_AddressOf

        public void FunctionReturnValueNotUsed_ReturnsResult_AddressOf()
        {
            const string inputCode =
@"Public Function Foo(ByVal bar As String) As Integer
    Foo = 42
End Function
Public Sub Bar()
    Bar AddressOf Foo
End Sub";
            //Arrange
            var builder = new MockVbeBuilder();
            VBComponent component;
            var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
            var mockHost = new Mock<IHostApplication>();
            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState());

            parser.Parse();
            if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }

            var inspection = new FunctionReturnValueNotUsedInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(1, inspectionResults.Count());
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:25,代码来源:FunctionReturnValueNotUsedInspectionTests.cs

示例8: EmptyStringLiteral_ReturnsResult_PassToProcedure

        public void EmptyStringLiteral_ReturnsResult_PassToProcedure()
        {
            const string inputCode =
@"Public Sub Bar()
    Foo """"
End Sub

Public Sub Foo(ByRef arg1 As String)
End Sub";

            //Arrange
            var builder = new MockVbeBuilder();
            VBComponent component;
            var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
            var mockHost = new Mock<IHostApplication>();
            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState());

            parser.Parse();
            if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }

            var inspection = new EmptyStringLiteralInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(1, inspectionResults.Count());
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:26,代码来源:EmptyStringLiteralInspectionTests.cs

示例9: FindMixedCaseFileWIthLowerCaseSearch

        public void FindMixedCaseFileWIthLowerCaseSearch()
        {
            var fileNameToFind = "caseSensitiveFile.gpg";
            var anotherFile = "somefile.gpg";
            var fileMockOne = new Mock<IFileProvider>();
            var fileMockTwo = new Mock<IFileProvider>();
            fileMockOne.SetupAllProperties();
            fileMockOne.Object.Name = fileNameToFind;
            fileMockOne.Object.FullName = fileNameToFind;
            fileMockTwo.SetupAllProperties();
            fileMockTwo.Object.Name = anotherFile;
            fileMockTwo.Object.FullName = anotherFile;
            var fileProviderMockList = new List<IFileProvider>
            {
                fileMockOne.Object,
                fileMockTwo.Object
            };

            var directoryProviderMock = Setup.Scope.Resolve<Mock<IDirectoryProvider>>();
            directoryProviderMock.Setup(
                m => m.GetFiles(It.IsAny<string>(), It.Is<SearchOption>(so => so == SearchOption.AllDirectories)))
                .Returns(fileProviderMockList.ToArray());
            var fsi = Setup.Scope.Resolve<FileSystemInterface>();
            fsi.Search(fileNameToFind.ToLower());
            Assert.AreEqual(1, fsi.SearchList.Count);
            Assert.AreEqual(fileNameToFind, fsi.SearchList[0]);
        }
开发者ID:shaleh,项目名称:Pass4Win,代码行数:27,代码来源:FileSystemInterfaceTests.cs

示例10: FixtureSetup

        public void FixtureSetup()
        {
            playerMock = new Mock<IPlayer> ();
            playerMock.SetupAllProperties ();
            /* Mock properties without setter */
            playerMock.Setup (p => p.CurrentTime).Returns (() => currentTime);
            playerMock.Setup (p => p.StreamLength).Returns (() => streamLength);
            playerMock.Setup (p => p.Play ()).Raises (p => p.StateChange += null, this, true);
            playerMock.Setup (p => p.Pause ()).Raises (p => p.StateChange += null, this, false);

            mtkMock = new Mock<IMultimediaToolkit> ();
            mtkMock.Setup (m => m.GetPlayer ()).Returns (playerMock.Object);
            mtkMock.Setup (m => m.GetMultiPlayer ()).Throws (new Exception ());
            Config.MultimediaToolkit = mtkMock.Object;

            var ftk = new Mock<IGUIToolkit> ();
            ftk.Setup (m => m.Invoke (It.IsAny<EventHandler> ())).Callback<EventHandler> (e => e (null, null));
            Config.GUIToolkit = ftk.Object;

            Config.EventsBroker = new EventsBroker ();

            mfs = new MediaFileSet ();
            mfs.Add (new MediaFile { FilePath = "test1", VideoWidth = 320, VideoHeight = 240, Par = 1 });
            mfs.Add (new MediaFile { FilePath = "test2", VideoWidth = 320, VideoHeight = 240, Par = 1 });

            evt = new TimelineEvent { Start = new Time (100), Stop = new Time (200),
                CamerasConfig = new List<CameraConfig> { new CameraConfig (0) }
            };
            plImage = new PlaylistImage (Utils.LoadImageFromFile (), new Time (5));
            playlist = new Playlist ();
            playlist.Elements.Add (new PlaylistPlayElement (evt));
            playlist.Elements.Add (plImage);
        }
开发者ID:GNOME,项目名称:longomatch,代码行数:33,代码来源:TestPlayerController.cs

示例11: Build

        public IUserDataService Build()
        {
            var mock = new Mock<IUserDataService>();
            mock.SetupAllProperties();

            mock.Setup(s => s.TryGetUser(It.IsAny<string>()))
                .Returns((string email) => Users.Single(u => u.Email == email));

            mock.Setup(s => s.UserExists(It.IsAny<string>()))
                .Returns((string email) => Users.Any(u => u.Email == email));

            mock.Setup(s => s.InsertUser(It.IsAny<IUser>()))
                .Callback((IUser user) => Users.Add(user));

            mock.Setup(s => s.CreateUser(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
                .Returns((
                    string name,
                    string email,
                    string passwordHash)
                         => _userBuilder
                                .Build(u =>
                                          {
                                              u.Email = email;
                                              u.PasswordHash = passwordHash;
                                              u.Name = name;
                                          })
                );

            return mock.Object;
        }
开发者ID:MrAntix,项目名称:Poci,代码行数:30,代码来源:UserDataServiceBuilder.cs

示例12: BasicCase2ShouldReturnBasicTriangles

        public void BasicCase2ShouldReturnBasicTriangles()
        {
            var vol1 = new Mock<IVolume>();
            vol1.SetupAllProperties();
            vol1.Setup(x => x.Height).Returns(1);
            vol1.Setup(x => x.Depth).Returns(1);
            vol1.Setup(x => x.Width).Returns(1);
            vol1.Setup(x => x.GetVoxelValueAt(0, 0, 0)).Returns(FullBlack);
            vol1.Setup(x => x.GetVoxelValueAt(0, 1, 0)).Returns(FullBlack);

            var t1 = new Triangle
            {
                Edge1 = new Point3D { X = 0.5, Y = 0.0, Z = 0.0 },
                Edge2 = new Point3D { X = 0.0, Y = 0.5, Z = 1.0 },
                Edge3 = new Point3D { X = 0.5, Y = 1.0, Z = 0.5 }
            };
            var t2 = new Triangle
            {
                Edge1 = new Point3D { X = 0.5, Y = 0.0, Z = 0.0 },
                Edge2 = new Point3D { X = 0.0, Y = 0.0, Z = 0.5 },
                Edge3 = new Point3D { X = 0.5, Y = 1.0, Z = 0.5 }
            };
            var expected = new List<ITriangle> { t1, t2 };

            Assert.AreEqual(expected, MarchingCubes.Instance.GetTriangles(vol1.Object, Threshold, GridSize));
        }
开发者ID:CookSlash,项目名称:MarchingCube,代码行数:26,代码来源:MarchingCubesTest.cs

示例13: UnassignedVariable_DoesNotReturnResult

        public void UnassignedVariable_DoesNotReturnResult()
        {
            const string inputCode =
@"Function Foo() As Boolean
    Dim var1 as String
    var1 = ""test""

    Goo var1
End Function

Sub Goo(ByVal arg1 As String)
End Sub";

            //Arrange
            var builder = new MockVbeBuilder();
            VBComponent component;
            var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
            var mockHost = new Mock<IHostApplication>();
            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState());

            parser.Parse();
            if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }

            var inspection = new VariableNotUsedInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(0, inspectionResults.Count());
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:29,代码来源:VariableNeverUsedInspectionTests.cs

示例14: OnStartup

 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
     // init stubs
     var fakeExplorer = new Mock<Explorer>();
     fakeExplorer.SetupAllProperties();
     var fakeMailItem = new Mock<MailItem>();
     fakeMailItem.SetupAllProperties();
     fakeMailItem.Object.Subject = "test subj";
     fakeMailItem.Object.Body = "test body";
     var atts = new Mock<Attachments>();
     atts.Setup(a => a.GetEnumerator()).Returns(ProductList);
     fakeMailItem.SetupGet(m => m.Attachments).Returns(atts.Object);
     var _container = new SimpleContainer()
         .RegisterSingle(fakeExplorer)
         .Register<IView>(container => new NewWorkItem())
         .Register<AppViewModel>(container => new AppViewModel())
         .Register<IPresenter>(container => new Presenter
         {
             View = container.Create<IView>(),
             ViewModel = container.Create<AppViewModel>()
         });
     
     var form = _container.Create<IPresenter>();
     form.Initialize(fakeMailItem.Object);
 }
开发者ID:brainboost,项目名称:OutlookTfsAddin,代码行数:26,代码来源:App.xaml.cs

示例15: FixtureSetup

        public void FixtureSetup()
        {
            mfs = new MediaFileSet ();
            mfs.Add (new MediaFile { FilePath = "test1", VideoWidth = 320, VideoHeight = 240, Par = 1 });
            mfs.Add (new MediaFile { FilePath = "test2", VideoWidth = 320, VideoHeight = 240, Par = 1 });

            mockAnalysisWindow = new Mock<IAnalysisWindowBase> ();
            mockPlayerController = new Mock<IPlayerController> ();
            mockPlayerController.SetupAllProperties ();
            mockPlayerController.SetupGet (x => x.CurrentTime).Returns (new Time (1000));
            MediaFileSet mf = new MediaFileSet ();
            mf.Add (new MediaFile ("path", 34000, 25, true, true, "mp4", "h264",
                "aac", 320, 240, 1.3, null, "Test asset"));
            mockPlayerController.SetupGet (m => m.FileSet).Returns (mf);
            mockAnalysisWindow.SetupGet (m => m.Player).Returns (mockPlayerController.Object);
            mockVideoRenderer = new Mock<IJobsManager> ();
            mockDiaklogs = new Mock<IDialogs> ();

            playerMock = new Mock<IPlayer> ();
            playerMock.SetupAllProperties ();
            Mock<IMultiPlayer> multiplayerMock = new Mock<IMultiPlayer> ();

            multimediaToolkitMock = new Mock<IMultimediaToolkit> ();
            multimediaToolkitMock.Setup (m => m.GetPlayer ()).Returns (playerMock.Object);
            App.Current.MultimediaToolkit = multimediaToolkitMock.Object;

            App.Current.LowerRate = 1;
            App.Current.UpperRate = 30;
            App.Current.RatePageIncrement = 3;
            App.Current.RateList = new List<double> { 0.04, 0.08, 0.12, 0.16, 0.20, 0.24, 0.28, 0.32, 0.36, 0.40, 0.44,
                    0.48, 0.52, 0.56, 0.60, 0.64, 0.68, 0.72, 0.76, 0.80, 0.84, 0.88, 0.92, 0.96, 1, 2, 3, 4, 5
                };
            App.Current.DefaultRate = 25;
        }
开发者ID:LongoMatch,项目名称:longomatch,代码行数:34,代码来源:TestPlaylistManager.cs


注:本文中的Mock.SetupAllProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。