Пример #1
0
        public void TestMethod6()
        {
            var obj    = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(new Class1());
            var actual = obj.Invoke("addAndZeroFormat", 10, 3) as string;

            Assert.Equal("0000013", actual);
        }
        public void Constructor_ShouldSetUpAllFields_WhenNewTeleportStationIsCreatedWhithValidParameters()
        {
            // Arrange
            var expectedMockedOwner    = new Mock <IBusinessOwner>();
            var mockedPath             = new Mock <IPath>();
            var expectedmockedLocation = new Mock <ILocation>();
            var expectedgalacticMap    = new List <IPath>();

            expectedgalacticMap.Add(mockedPath.Object);

            var expectedgalacticMap1 = new Mock <List <IPath> >();

            // Act
            var teleportStation = new TeleportStation(expectedMockedOwner.Object, expectedgalacticMap1.Object,
                                                      expectedmockedLocation.Object);

            var wrapperTeleportStation = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(teleportStation);

            var actualResources   = wrapperTeleportStation.GetField("resources");
            var actualOwner       = wrapperTeleportStation.GetField("owner");
            var actualLocation    = wrapperTeleportStation.GetField("location");
            var actualGalacticMap = wrapperTeleportStation.GetField("galacticMap");

            // Assert
            Assert.AreSame(expectedMockedOwner.Object, actualOwner);
            Assert.AreSame(expectedgalacticMap1.Object, actualGalacticMap);
            Assert.AreSame(expectedmockedLocation.Object, actualLocation);
        }
Пример #3
0
        public void TestMethod5()
        {
            var obj    = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(new Class1());
            var actual = obj.Invoke("getDisplayName") as string;

            Assert.Equal("ConsoleApp1.Class1: Hello", actual);
        }
Пример #4
0
        public void XXXInit_Ok()
        {
            var studentRepositories = new StudentService();
            var obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(studentRepositories);

            Assert.True((bool)obj.Invoke("XXXInit"));
        }
Пример #5
0
        public void Pay_WhenParamIsValid_ShouldDecreaseUnitsResourcesByCorrectAmount()
        {
            //Arrange
            var unit           = new Unit(1, "Pesho");
            var mockedResource = new Mock <IResources>();

            mockedResource.SetupGet(x => x.GoldCoins).Returns(1);
            mockedResource.SetupGet(x => x.SilverCoins).Returns(1);
            mockedResource.SetupGet(x => x.BronzeCoins).Returns(1);

            var privateUnit = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(unit);

            var resources = privateUnit.GetFieldOrProperty("resources") as IResources;

            resources.BronzeCoins = 10;
            resources.SilverCoins = 10;
            resources.GoldCoins   = 10;

            //Act
            unit.Pay(mockedResource.Object);
            //Assert
            Assert.AreEqual(9, resources.GoldCoins);
            Assert.AreEqual(9, resources.SilverCoins);
            Assert.AreEqual(9, resources.BronzeCoins);
        }
Пример #6
0
        public void OnTeamCollectionBookStatusChange_TeamCollection_GivenCheckedOutByOther_WhenCheckedOutByNone_RemovesIcon()
        {
            // Setup //
            var collectionFolder = new TemporaryFolder("LibraryListViewTests");

            Book.BookCollectionTests.AddBook(collectionFolder, "book1");

            _view = new LibraryListView(new FakeLibraryModel(collectionFolder), new BookSelection(), new SelectedTabChangedEvent(), new LocalizationChangedEvent(), new BookStatusChangeEvent(), null);

            var primaryCollectionFlow = new FlowLayoutPanel();
            var obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(_view);

            obj.SetField("_primaryCollectionFlow", primaryCollectionFlow);
            _view.LoadPrimaryCollectionButtons();
            _view.OnTeamCollectionBookStatusChange(new BookStatusChangeEventArgs("book1", CheckedOutBy.Other));
            var button = primaryCollectionFlow.Controls.OfType <Button>().First();

            Assert.AreEqual(1, button.Controls.OfType <Label>().Count(), "Test was not set up properly. Wrong number of labels.");

            // System Under Test //
            _view.OnTeamCollectionBookStatusChange(new BookStatusChangeEventArgs("book1", CheckedOutBy.None));

            // Verification //
            var labelOfButton = button.Controls.OfType <Label>().FirstOrDefault();

            Assert.IsNull(labelOfButton);
        }
 public void Setup()
 {
     _shimsContext             = ShimsContext.Create();
     _baseChannelEditor        = new basechanneleditor();
     _baseChannelEditorPrivate = new PrivateObject(_baseChannelEditor);
     _user = new User
     {
         UserID = UserId
     };
     _baseChannelId                                       = default(int);
     _clientGroupSelectResult                             = null;
     _clientGroupSaveResult                               = default(int);
     _clientGroupPassedToSave                             = null;
     _clientGroupServicePassedToSave                      = null;
     _clientGroupServiceMapSaveResult                     = default(int);
     _clientGroupServiceFeatureMapSaveResult              = default(int);
     _clientGroupServiceFeatureMapPassedToSave            = null;
     _securityGroupTemplateNamePassedToCreateFromTemplate = null;
     _clientGroupIdPassedToCreateFromTemplate             = default(int);
     _administrativeLevelPassedToCreateFromTemplate       = null;
     _userPassedToCreateFromTemplate                      = null;
     _ecnSessionRemoveFromSessionCalled                   = default(bool);
     _contact                  = new Contact();
     _responseStream           = new MemoryStream();
     _responseStreamWriter     = new StreamWriter(_responseStream);
     _baseChannelPassedToSave  = null;
     _validateErrorToThrow     = null;
     _baseChannelSaveException = null;
     _clientGroupSaveException = null;
     InitializeFields();
     CommonShims();
 }
Пример #8
0
        public void XXX_Ok()
        {
            var private_function = new PrivateFunction();
            var obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(private_function);

            Assert.True((bool)obj.Invoke("XXX"));
        }
 public void ProcessTaskTest_InputTaskRecord_IsTaskLocked()
 {
     IET.Inspec.Fairburn.AgentTemplate.Task x = new IET.Inspec.Fairburn.AgentTemplate.Task();
     var privateObject = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(x);
     x.Initialise(new Host(), 0);
     TaskResponse resp = new TaskResponse();
     privateObject.SetField("_Task", resp);
     privateObject.Invoke("ProcessTask");
 }
Пример #10
0
 public void Setup()
 {
     _accountsHomePage        = new AccountsHomePage();
     _accountsHomePagePrivate = new PrivateObject(_accountsHomePage);
     _siteMapSecondLevelField = new SiteMapDataSource();
     _menuField    = new Menu();
     _shimsContext = ShimsContext.Create();
     InitializeFields();
 }
Пример #11
0
        public void BadCommandThrows()
        {
            Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(git);

            GitException ex = Assert.Throws <GitException>(() =>
            {
                obj.Invoke("GitCommand", new object[] { "boogers" });
            });

            Assert.True(ex.Message.ToLower().Contains("not a git command"));
        }
        public void ProcessTaskTest_InputTaskRecord_IsTaskLocked()
        {
            IET.Inspec.Fairburn.AgentTemplate.Task x = new IET.Inspec.Fairburn.AgentTemplate.Task();
            var privateObject = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(x);

            x.Initialise(new Host(), 0);
            TaskResponse resp = new TaskResponse();

            privateObject.SetField("_Task", resp);
            privateObject.Invoke("ProcessTask");
        }
 public void GetTaskTest_InputTestMode1_ExpectTaskRecord()
 {
     WcfSelfHost host = new WcfSelfHost(typeof(Service));
     IET.Inspec.Fairburn.AgentTemplate.Task x = new IET.Inspec.Fairburn.AgentTemplate.Task();
     var privateObject = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(x);
     x.Initialise(new Host(), 0);
     privateObject.SetField("_TestMode", 1);
     bool ok = Convert.ToBoolean(privateObject.Invoke("GetTask"));
     Assert.IsFalse(ok);
     host.Dispose();
     host = null;
 }
Пример #14
0
        internal static string GetsearchPath(this SearchPathHelper targetClass)
        {
            var po = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(targetClass);

            try
            {
                return((string)po.GetFieldOrProperty("searchPath"));
            }
            catch (System.MissingMethodException missingMethodException)
            {
                throw new System.NotSupportedException("searchPath with requested parameters is not found. Rerun code generation.", missingMethodException);
            }
        }
        internal static void SetMinor(this DatabaseVersion targetClass, string value)
        {
            var po = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(targetClass);

            try
            {
                po.SetFieldOrProperty("Minor", value);
            }
            catch (System.MissingMethodException missingMethodException)
            {
                throw new System.NotSupportedException("Minor with requested parameters is not found. Rerun code generation.", missingMethodException);
            }
        }
        internal static DatabaseVersion Getversion(this ExecutedFile targetClass)
        {
            var po = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(targetClass);

            try
            {
                return((DatabaseVersion)po.GetFieldOrProperty("version"));
            }
            catch (System.MissingMethodException missingMethodException)
            {
                throw new System.NotSupportedException("version with requested parameters is not found. Rerun code generation.", missingMethodException);
            }
        }
Пример #17
0
        internal static int CallGetExpressionEnd(this Parser targetClass)
        {
            var po = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(targetClass);

            try
            {
                return((int)po.Invoke("GetExpressionEnd", new object[] { }));
            }
            catch (System.MissingMethodException missingMethodException)
            {
                throw new System.NotSupportedException("GetExpressionEnd with requested parameters is not found. Rerun code generation.", missingMethodException);
            }
        }
Пример #18
0
        internal static void SetwasOutput(this SearchPathHelper targetClass, bool value)
        {
            var po = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(targetClass);

            try
            {
                po.SetFieldOrProperty("wasOutput", value);
            }
            catch (System.MissingMethodException missingMethodException)
            {
                throw new System.NotSupportedException("wasOutput with requested parameters is not found. Rerun code generation.", missingMethodException);
            }
        }
        internal static void SetExecutionDate(this ExecutedFile targetClass, DateTime value)
        {
            var po = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(targetClass);

            try
            {
                po.SetFieldOrProperty("ExecutionDate", value);
            }
            catch (System.MissingMethodException missingMethodException)
            {
                throw new System.NotSupportedException("ExecutionDate with requested parameters is not found. Rerun code generation.", missingMethodException);
            }
        }
Пример #20
0
        internal static void CallUpdateSchemas(this DifferenceCreator targetClass, Database database, StreamWriter writer, PgDatabase oldDatabase, PgDatabase newDatabase)
        {
            var po = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(targetClass);

            try
            {
                po.Invoke("UpdateSchemas", new object[] { database, writer, oldDatabase, newDatabase });
            }
            catch (System.MissingMethodException missingMethodException)
            {
                throw new System.NotSupportedException("UpdateSchemas with requested parameters is not found. Rerun code generation.", missingMethodException);
            }
        }
Пример #21
0
        internal static string CallParseIdentifierInternal(this Parser targetClass)
        {
            var po = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(targetClass);

            try
            {
                return((string)po.Invoke("ParseIdentifierInternal", new object[] { }));
            }
            catch (System.MissingMethodException missingMethodException)
            {
                throw new System.NotSupportedException("ParseIdentifierInternal with requested parameters is not found. Rerun code generation.", missingMethodException);
            }
        }
        public void UpdateExpression_WithDefaultConstructor_ShouldInitializeUpdateCommandsField()
        {
            // Arrange
            const string UpdateCommandsFieldName = "updateCommands";

            var updateExpression = new UpdateExpression <ITweet>();

            // Act
            var privateObject       = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(updateExpression);
            var updateCommandsField = privateObject.GetField(UpdateCommandsFieldName);

            // Assert
            Assert.IsNotNull(updateCommandsField, "UpdateCommands field should be correctly initialized.");
        }
 public void PostResultsTests_InputTestMode1_OutputSuccess()
 {
     WcfSelfHost host = new WcfSelfHost(typeof(Service));
     IET.Inspec.Fairburn.AgentTemplate.Task x = new IET.Inspec.Fairburn.AgentTemplate.Task();
     var privateObject = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(x);
     x.Initialise(new Host(), 0);
     PostResultsRequest req = new PostResultsRequest();
     req.TestMode = 1;
     privateObject.SetField("_Results", req);
     privateObject.Invoke("PostResults");
     //privateObject.Invoke("APrivateMethod", new object[] { param1, param2}); -- Call Private method with parameters
     host.Dispose();
     host = null;
 }
Пример #24
0
        public void UI_GameOver_ControlsAreCreated()
        {
            //Arrange
            Form1 form = new Form1();

            form.UI = new UI(form);
            Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject pvt = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(form.UI);
            //Act
            form.UI.GameOver();
            Label labelGameOver = (Label)pvt.GetField("labelGameOver");

            //Assert
            Assert.That(form.Controls.Contains(labelGameOver) && labelGameOver.Tag.ToString() == "GameOver");
        }
Пример #25
0
        public void Setup()
        {
            _shimContext               = ShimsContext.Create();
            _communicatorInstance      = new masterPage.Communicator();
            _shimCommunicator          = new ShimCommunicator(_communicatorInstance);
            _communicatorPrivateObject = new PrivateObject(_communicatorInstance);

            _drpClient = new DropDownList();
            _communicatorPrivateObject.SetField("drpClient", _drpClient);

            _drpclientgroup = new DropDownList();
            _drpclientgroup.Items.Add("5");
            _drpclientgroup.SelectedValue = "1";
            _communicatorPrivateObject.SetField("drpclientgroup", _drpclientgroup);
        }
        public void GetTaskTest_InputTestMode1_ExpectTaskRecord()
        {
            WcfSelfHost host = new WcfSelfHost(typeof(Service));

            IET.Inspec.Fairburn.AgentTemplate.Task x = new IET.Inspec.Fairburn.AgentTemplate.Task();
            var privateObject = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(x);

            x.Initialise(new Host(), 0);
            privateObject.SetField("_TestMode", 1);
            bool ok = Convert.ToBoolean(privateObject.Invoke("GetTask"));

            Assert.IsFalse(ok);
            host.Dispose();
            host = null;
        }
Пример #27
0
        public void Updater_WithValiUpdateExpression_ShouldCorrectlyInitializeUpdateExpressionField()
        {
            // Arrange
            const string UpdateExpressionFieldName = "updateExpression";

            var updateExpressionMock = new Mock <IUpdateExpression <ITweet> >();
            var updateExpression     = updateExpressionMock.Object;
            var updater = new Updater <ITweet>(updateExpression);

            // Act
            var privateObject = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(updater);
            var updateExpressionFieldValue = privateObject.GetField(UpdateExpressionFieldName);

            // Assert
            Assert.IsNotNull(updateExpressionFieldValue, "Updater.updateExpression should not be null.");
            Assert.AreSame(updateExpression, updateExpressionFieldValue, "Updater.updateExpression should be set correctly.");
        }
        public void PostResultsTests_InputTestMode1_OutputSuccess()
        {
            WcfSelfHost host = new WcfSelfHost(typeof(Service));

            IET.Inspec.Fairburn.AgentTemplate.Task x = new IET.Inspec.Fairburn.AgentTemplate.Task();
            var privateObject = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(x);

            x.Initialise(new Host(), 0);
            PostResultsRequest req = new PostResultsRequest();

            req.TestMode = 1;
            privateObject.SetField("_Results", req);
            privateObject.Invoke("PostResults");
            //privateObject.Invoke("APrivateMethod", new object[] { param1, param2}); -- Call Private method with parameters
            host.Dispose();
            host = null;
        }
Пример #29
0
        public void LongSubjectGetsTruncated()
        {
            InitialCommit();

            // Add an new commit
            File.AppendAllText(readmePath, "\nThis is for a fix commit");
            repo.Index.Add("README.md");
            repo.Commit("fix(README): This subject is way way over eighty characters, which it shouldn't be because that's basically useless for most commit parsing utilities, including this one.");

            var msg = git.GetCommits()[0];

            Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(git);

            int maxLength = Int32.Parse(obj.GetField("MAX_SUBJECT_LENGTH", BindingFlags.NonPublic | BindingFlags.Static).ToString());

            Assert.IsTrue(msg.Subject.Length == maxLength);
        }
Пример #30
0
        public void PlayButton_DefaultMode_Started()
        {
            //Arrange
            Form1 form = new Form1();

            form.UI = new UI(form);
            Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject pvt   = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(form);
            Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject pvtUI = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(form.UI);
            Button buttonPlay = (Button)pvt.GetField("buttonPlay");
            Label  labelScore = (Label)pvtUI.GetField("labelScore");

            //Act
            pvt.Invoke("buttonPlay_Click", new object[2] {
                this, new EventArgs()
            });
            //Assert
            Assert.That(form.IsPlaying && labelScore.Text == "Score: 0");
        }
Пример #31
0
        public void Form1_Run_ChecksCirclesAndThreads()
        {
            //Arrange
            Form1 form = new Form1();

            form.UI = new UI(form);
            Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject pvt = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(form);
            ComboBox cbModes = (ComboBox)pvt.GetField("comboBoxModes");

            //Act
            cbModes.SelectedIndex = 1;
            form.Run();
            Thread circleCreation = (Thread)pvt.GetField("circleCreation");
            Thread circleGrowth   = (Thread)pvt.GetField("circleGrowth");

            //Assert
            Assert.That(form.circles.Count == 0 && circleCreation.IsAlive && circleGrowth.IsAlive);
        }
Пример #32
0
        public void LoadPrimaryCollectionButtons_BookTitleHasAmpersand_ButtonUsesNonEscapedForm()
        {
            // Setup //
            var collectionFolder = new TemporaryFolder("LibraryListViewTests");

            Book.BookCollectionTests.AddBook(collectionFolder, "A&B Book");

            _view = new LibraryListView(new FakeLibraryModel(collectionFolder), new BookSelection(), new SelectedTabChangedEvent(), new LocalizationChangedEvent(), new BookStatusChangeEvent(), null);

            // System Under Test //
            _view.LoadPrimaryCollectionButtons();

            // Verification //
            var obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(_view);
            var primaryCollectionFlow = (FlowLayoutPanel)(obj.GetFieldOrProperty("_primaryCollectionFlow"));
            var firstBookButton       = primaryCollectionFlow.Controls.OfType <Button>().First();

            Assert.AreEqual("A&B Book", firstBookButton.Text, "Text");                  // Not escaped because the button has UseMnemonic = false
            Assert.AreEqual(false, firstBookButton.UseMnemonic, "UseMnemonic");
        }
Пример #33
0
        public void LoadPrimaryCollectionButtons_CollectionNameHasAmpersand_IsEscaped()
        {
            // Setup //
            var collectionFolder          = new TemporaryFolder("LibraryListViewTests");
            var collectionSettings        = new CollectionSettings();
            var privateCollectionSettings = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(collectionSettings);

            privateCollectionSettings.SetFieldOrProperty("CollectionName", "A&B");

            _view = new LibraryListView(new FakeLibraryModel(collectionFolder, collectionSettings), new BookSelection(), new SelectedTabChangedEvent(), new LocalizationChangedEvent(), new BookStatusChangeEvent(), null);

            // System Under Test //
            _view.LoadPrimaryCollectionButtons();

            // Verification //
            var obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(_view);
            var primaryCollectionFlow = (FlowLayoutPanel)(obj.GetFieldOrProperty("_primaryCollectionFlow"));
            var listHeader            = primaryCollectionFlow.Controls.OfType <ListHeader>().First();

            Assert.AreEqual("A&&B", listHeader.Label.Text);
        }