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


C# PrivateObject.SetField方法代码示例

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


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

示例1: TestMethod_ClearEditNumber

        public void TestMethod_ClearEditNumber()
        {
            CalcServicesApi api = new CalcServicesApi();
            var obj = new PrivateObject(api);

            obj.SetField("statement", "11+22-");
            obj.SetField("editNumber", "120");

            obj.Invoke("ClearEditNumber");

            Assert.IsTrue(api.STATEMENT.Equals("11+22-"));
            Assert.IsTrue(api.EDIT.Equals("0"));
        } 
开发者ID:tasiyo7333,项目名称:DENTAKU.,代码行数:13,代码来源:UnitTestApi.cs

示例2: ServerProxy_FallbackOnConnect

        public void ServerProxy_FallbackOnConnect()
        {
            //------------Setup for test--------------------------
            var serverProxy = new ServerProxy(new Uri("http://bob"));
            var serverGuid = Guid.NewGuid();
            PrivateObject p = new PrivateObject(serverProxy);
            var wrapped = new Mock<IEnvironmentConnection>();
            wrapped.Setup(a => a.DisplayName).Returns("moo");
            wrapped.Setup(a => a.Connect(It.IsAny<Guid>())).Throws(new FallbackException());
            wrapped.Setup(a => a.WebServerUri).Returns( new Uri("http://bob"));
            p.SetField("_wrappedConnection", wrapped.Object);
   
            try
            {
                serverProxy.Connect(serverGuid);

            }
            // ReSharper disable EmptyGeneralCatchClause
            catch(Exception err)
            {

               Assert.IsNotNull(err);
            }
            var con = p.GetField("_wrappedConnection") as IEnvironmentConnection;
            Assert.IsNotNull(con);
            Assert.AreNotEqual(con,wrapped.Object);
            Assert.AreEqual("moo",con.DisplayName);
            

        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:30,代码来源:ServerProxyWithFallbackTests.Specs.cs

示例3: TestValueOnePair

 public void TestValueOnePair()
 {
     Yahtzee yahtzee = new Yahtzee();
     PrivateObject priv = new PrivateObject(yahtzee);
     int[] example = new int[5] { 1, 5, 5, 1, 1 };
     priv.SetField("dies", example);
     Assert.AreEqual(10, yahtzee.valueOnePair());
 }
开发者ID:Larvalis,项目名称:Yatzy,代码行数:8,代码来源:UnitTest1.cs

示例4: MoveTest

 public void MoveTest()
 {
     Cow cow = new Cow(Vector2.Zero, 0, null, new Random());
     PrivateObject cowObject = new PrivateObject(cow);
     cowObject.SetField("moveRight", true);
     cowObject.Invoke("Move");
     Assert.IsTrue(((Vector2)cowObject.GetField("speed")).X > 0);
 }
开发者ID:csce3513,项目名称:Team12,代码行数:8,代码来源:CowTest.cs

示例5: Application_Start

        protected void Application_Start()
        {
            var setting = ConfigurationManager.AppSettings["TestApp.SendTelemetyIntemOnAppStart"];
            if (false == string.IsNullOrWhiteSpace(setting) && true == bool.Parse(setting))
            {
                new TelemetryClient().TrackTrace("Application_Start");
            }

            GlobalConfiguration.Configure(WebApiConfig.Register);

            var module = new PerformanceCollectorModule();

            // we're running under IIS Express, so override the default behavior designed to prevent a deadlock
            module.EnableIISExpressPerformanceCounters = true;

            // set test-friendly timings
            var privateObject = new PrivateObject(module);
            privateObject.SetField("collectionPeriod", TimeSpan.FromMilliseconds(10));
            privateObject.SetField(
                "defaultCounters",
                new List<string>() { @"\Memory\Available Bytes", @"Will not parse;\Does\NotExist" });

            module.Counters.Add(
                new PerformanceCounterCollectionRequest(@"Will not parse", "Custom counter - will not parse"));

            module.Counters.Add(
                new PerformanceCounterCollectionRequest(@"\Does\NotExist", "Custom counter - does not exist"));

            module.Counters.Add(
                new PerformanceCounterCollectionRequest(
                                          @"\Process(??APP_WIN32_PROC??)\Handle Count",
                    "Custom counter one"));

            module.Counters.Add(
                new PerformanceCounterCollectionRequest(
                                          @"\ASP.NET Applications(??APP_W3SVC_PROC??)\Anonymous Requests/Sec",
                    "Custom counter two"));

            // necessary for .NET CLR Memory counters to start reporting process ID
            GC.Collect();

            module.Initialize(TelemetryConfiguration.Active);

            TelemetryModules.Instance.Modules.Add(module);
        }
开发者ID:xornand,项目名称:ApplicationInsights-dotnet-server,代码行数:45,代码来源:Global.asax.cs

示例6: GetFakeHttpApplication

        public static HttpApplication GetFakeHttpApplication()
        {
            var httpContext = GetFakeHttpContext();
            var httpApplicationWrapper = new PrivateObject(typeof(HttpApplication), null);

            httpApplicationWrapper.SetField("_context", httpContext);

            return (HttpApplication)httpApplicationWrapper.Target;
        }
开发者ID:gregjhogan,项目名称:ApplicationInsights-server-dotnet,代码行数:9,代码来源:HttpModuleHelper.cs

示例7: TestLoadInvalidFile

 public void TestLoadInvalidFile()
 {
     // Arrange
     Appointments testApps = new Appointments();
     PrivateObject privApps = new PrivateObject(testApps);
     privApps.SetField("fileName", "UnitTests/LoadInvalid.xml");
     // Act
     bool successfullLoad = testApps.Load();
     // Assert
     Assert.IsFalse(successfullLoad, "The appointment loaded an invalid file.");
 }
开发者ID:JamieSharpe,项目名称:CalendarApplication,代码行数:11,代码来源:UnitTestAppointments.cs

示例8: SouthPointingState_Handle_NavigationMove_ExpectDecrementinYaxis

 public void SouthPointingState_Handle_NavigationMove_ExpectDecrementinYaxis()
 {
     //Arrange
     PrivateObject _marsRover = new PrivateObject(_roverInstance);
     _marsRover.SetField("_currentNavigator", 'M');
     RoverState target = CreateTarget();
     //Act
     target.Handle(_roverInstance);
     //Assert
     Assert.AreEqual<int>(1, _roverInstance.CurrentPosition.Xaxis);
 }
开发者ID:Gokilarajan,项目名称:Clever-Mars-Robot,代码行数:11,代码来源:SouthPointingStateTest.cs

示例9: TestLoadNoFile

 public void TestLoadNoFile()
 {
     // Arrange
     Appointments testApps = new Appointments();
     PrivateObject privApp = new PrivateObject(testApps);
     privApp.SetField("fileName", String.Empty);
     // Act
     bool successfullLoad = testApps.Load();
     // Assert
     Assert.IsFalse(successfullLoad, "The appointment didn't load from a file!");
 }
开发者ID:JamieSharpe,项目名称:CalendarApplication,代码行数:11,代码来源:UnitTestAppointments.cs

示例10: SouthPointingState_Handle_NavigationRight_ExpectWest

 public void SouthPointingState_Handle_NavigationRight_ExpectWest()
 {
     //Arrange
     PrivateObject _marsRover = new PrivateObject(_roverInstance);
     _marsRover.SetField("_currentNavigator", 'R');
     RoverState target = CreateTarget();
     //Act
     target.Handle(_roverInstance);
     //Assert
     Assert.AreEqual<Enum_Direction>(Enum_Direction.Direction_W, _roverInstance.CurrentPosition.Direction);
 }
开发者ID:Gokilarajan,项目名称:Clever-Mars-Robot,代码行数:11,代码来源:SouthPointingStateTest.cs

示例11: ProcessSpaceInputTest

        public void ProcessSpaceInputTest()
        {
            Spaceship spaceship = new Spaceship();
            InputManager input = new InputManager();
            PrivateObject privateInput = new PrivateObject(input);
            privateInput.SetField("currentState", new KeyboardState(Keys.Space));

            SpaceshipController controller = new SpaceshipController(spaceship, input);

            controller.ProcessInput();
            Assert.IsTrue(spaceship.BeamOn);
        }
开发者ID:csce3513,项目名称:Team12,代码行数:12,代码来源:SpaceshipControllerTest.cs

示例12: UpInputTest

        public void UpInputTest()
        {
            Spaceship spaceship = new Spaceship();
            InputManager input = new InputManager();
            PrivateObject privateInput = new PrivateObject(input);
            privateInput.SetField("currentState", new KeyboardState(Keys.W));

            SpaceshipController controller = new SpaceshipController(spaceship, input);

            spaceship.Y = 300;
            controller.ProcessInput();
            Assert.AreEqual(300 - spaceship.Speed, spaceship.Y);
        }
开发者ID:csce3513,项目名称:Team12,代码行数:13,代码来源:SpaceshipControllerTest.cs

示例13: TestSearchUsers

        public void TestSearchUsers()
        {
            // Arrange
            var query = "sTEn";
            var allUsers = new List<Model.User>()
            {
                new Model.User() { FirstName = "Petra" },
                new Model.User() { FirstName = "Carsten" },
                new Model.User() { FirstName = "Philipp" }
            };
            var currentUsers = new ObservableCollection<Model.User>(allUsers);

            var repository = CreateUserRepository();
            var po = new PrivateObject(repository);
            po.SetField("_allUsers", allUsers);
            po.SetField("_currentUsers", currentUsers);

            // Act
            po.Invoke("SearchUsers", query);
            var result = (ObservableCollection<Model.User>)po.GetField("_currentUsers");

            // Assert
            Assert.IsTrue(result.Count() == 1);
        }
开发者ID:GrillPhil,项目名称:EnterpriseApps,代码行数:24,代码来源:UserRepositoryTests.cs

示例14: TestLoadValid

 public void TestLoadValid()
 {
     // Arrange
     Appointments testApps = new Appointments();
     PrivateObject privApps = new PrivateObject(testApps);
     privApps.SetField("fileName", "UnitTests/Load.xml");
     DateTime dt = new DateTime(DateTime.Now.Year + 1, 1, 1, 0, 0, 0);
     // Act
     bool successfullLoad = testApps.Load();
     // Assert
     Assert.IsTrue(successfullLoad, "The file wasn't loaded!");
     for (int i = 0; i < testApps.Count; ++i)
     {
         Assert.AreEqual("Description: Test Appointment " + i + "\nLocation: Test Location", testApps[i].DisplayableDescription, "The appointments description doesn't match!");
         Assert.AreEqual(30, testApps[i].Length, "The appointments length is not the same!");
         Assert.AreEqual(dt, testApps[i].Start, "The appointments starting time is not the same!");
     }
 }
开发者ID:JamieSharpe,项目名称:CalendarApplication,代码行数:18,代码来源:UnitTestAppointments.cs

示例15: ServerProxy_FallbackOnConnectWithError

        public void ServerProxy_FallbackOnConnectWithError()
        {
            //------------Setup for test--------------------------
            var serverProxy = new ServerProxy(new Uri("http://bob"));
            var serverGuid = Guid.NewGuid();
            PrivateObject p = new PrivateObject(serverProxy);
            var wrapped = new Mock<IEnvironmentConnection>();
            var fallback = new Mock<IEnvironmentConnection>();
            wrapped.Setup(a => a.Connect(It.IsAny<Guid>())).Throws(new FallbackException());
            p.SetField("_wrappedConnection",wrapped.Object);
            try
            {
                serverProxy.Connect(serverGuid);
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch
            // ReSharper restore EmptyGeneralCatchClause
            {

            }
            var con = p.GetField("_wrappedConnection");
            Assert.IsNotNull(con);
           
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:24,代码来源:ServerProxyWithFallbackTests.Specs.cs


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