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);
        }
        private T GetPrivateField <T>(string fieldName) where T : class
        {
            var field = _baseChannelEditorPrivate.GetField(fieldName) as T;

            field.ShouldNotBeNull($"Private field {fieldName} of type {typeof(T).Name} should not be null");
            return(field);
        }
示例#3
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);
        }
        public void Constructor_ShouldInstantiateObjectWhichContainsTheObjectsPassedAsParameters()
        {
            var mockedCreaturesFactory = new Mock <ICreaturesFactory>();
            var mockedLogger           = new Mock <ILogger>();

            var battleManager =
                new BattleManager(
                    mockedCreaturesFactory.Object,
                    mockedLogger.Object);

            var wrappedBattleManager =
                new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(battleManager);

            var battleManagerCreaturesFactory =
                wrappedBattleManager.GetField("creaturesFactory");
            var battleManagerLogger =
                wrappedBattleManager.GetField("logger");

            Assert.AreSame(mockedCreaturesFactory.Object, battleManagerCreaturesFactory);
            Assert.AreSame(mockedLogger.Object, battleManagerLogger);
        }
示例#5
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");
        }
        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.");
        }
示例#7
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);
        }
示例#8
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.");
        }
示例#9
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");
        }