Exemplo n.º 1
0
        public void CommandBase_FrameworkMethodsMustBeCalledWithoutData()
        {
            ICommand command = new TestCommand();

            bool canExecute = command.CanExecute(null);

            Assert.True(canExecute);
            Assert.Throws <ArgumentException>("parameter", () => command.CanExecute(240));

            command.Execute(null);
            Assert.Throws <ArgumentException>("parameter", () => command.Execute(240));
        }
Exemplo n.º 2
0
        public void CommandBase_T_FrameworkMethodsMustBeCalledWithData_ValueType()
        {
            ICommand command = new TestCommand <int>();

            bool canExecute = command.CanExecute(240);

            Assert.True(canExecute);
            Assert.Throws <NullReferenceException>(() => command.CanExecute(null));

            command.Execute(240);
            Assert.Throws <NullReferenceException>(() => command.Execute(null));
        }
Exemplo n.º 3
0
        public void CommandBase_T_FrameworkMethodsMustBeCalledWithData_ReferenceType()
        {
            ICommand command = new TestCommand <string>();

            bool canExecute = command.CanExecute("240");

            Assert.True(canExecute);
            Assert.Throws <ArgumentNullException>("parameter", () => command.CanExecute(null));

            command.Execute("240");
            Assert.Throws <ArgumentNullException>("parameter", () => command.Execute(null));
        }
Exemplo n.º 4
0
        public void UnitTests()
        {
            var command = new TestCommand();

            command.Execute();
            Assert.AreEqual(1, command.value);
            Assert.IsFalse(command.didRedo);
            command.Undo();
            Assert.AreEqual(0, command.value);
            command.Execute();
            Assert.AreEqual(1, command.value);
            Assert.IsTrue(command.didRedo);
        }
Exemplo n.º 5
0
        public void PublishOptionsTest(string testIdentifier, string framework, string runtime, string config, string outputDir)
        {
            TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary", identifier: testIdentifier)
                                    .WithLockFiles()
                                    .WithBuildArtifacts();

            string testRoot = _getProjectJson(instance.TestRoot, "TestApp");

            outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(instance.TestRoot, outputDir);
            var publishCommand = new PublishCommand(testRoot, output: outputDir);

            publishCommand.Execute().Should().Pass();

            // verify the output executable generated
            var publishedDir = publishCommand.GetOutputDirectory();
            var outputExe    = publishCommand.GetOutputExecutable();
            var outputPdb    = Path.ChangeExtension(outputExe, "pdb");

            // lets make sure that the output exe is runnable
            var outputExePath = Path.Combine(publishedDir.FullName, publishCommand.GetOutputExecutable());
            var command       = new TestCommand(outputExePath);

            command.Execute("").Should().ExitWith(100);

            // the pdb should also be published
            publishedDir.Should().HaveFile(outputPdb);
        }
Exemplo n.º 6
0
        public void StandaloneAppHasResourceDependency()
        {
            // WindowsAzure.Services brings in en, zh etc. resource DLLs.
            // The host has to be able to find these assemblies from the deps file
            // from the standalone app base under the ietf tag directory.

            var          testName = "TestAppWithResourceDeps";
            TestInstance instance =
                TestAssetsManager
                .CreateTestInstance(testName)
                .WithLockFiles()
                .WithBuildArtifacts();

            var publishCommand = new PublishCommand(instance.TestRoot);

            publishCommand.Execute().Should().Pass();

            var publishedDir = publishCommand.GetOutputDirectory();
            var extension    = publishCommand.GetExecutableExtension();
            var outputExe    = testName + extension;

            publishedDir.Should().HaveFiles(new[] { $"{testName}.dll", outputExe });

            var command = new TestCommand(Path.Combine(publishedDir.FullName, outputExe));

            command.Execute("").Should().ExitWith(0);
        }
Exemplo n.º 7
0
        public void PublishAppWithOutputAssemblyName()
        {
            TestInstance instance =
                TestAssetsManager
                .CreateTestInstance("AppWithOutputAssemblyName")
                .WithLockFiles()
                .WithBuildArtifacts();

            var testRoot       = _getProjectJson(instance.TestRoot, "AppWithOutputAssemblyName");
            var publishCommand = new PublishCommand(testRoot, output: testRoot);

            publishCommand.Execute().Should().Pass();

            var publishedDir = publishCommand.GetOutputDirectory();
            var extension    = publishCommand.GetExecutableExtension();
            var outputExe    = "MyApp" + extension;

            publishedDir.Should().HaveFiles(new[] { "MyApp.dll", outputExe });
            publishedDir.Should().NotHaveFile("AppWithOutputAssemblyName" + extension);
            publishedDir.Should().NotHaveFile("AppWithOutputAssemblyName.dll");

            var command = new TestCommand(Path.Combine(publishedDir.FullName, outputExe));

            command.Execute("").Should().ExitWith(0);
        }
        public void CanExecuteWithinUnitOfWorkScope()
        {
            using (new TestUnitOfWork())
            {
                _command.EntityObject = new EntityObject
                {
                    Name        = "Candy",
                    Description = "Delicious"
                };

                _command.Execute();

                Assert.That(_command.EntityObject.Id,
                            Is.GreaterThan(0));
            }
        }
Exemplo n.º 9
0
        public void PublishOptionsTest(string framework, string runtime, string config, string outputDir)
        {
            // create unique directories in the 'temp' folder
            var root       = Temp.CreateDirectory();
            var testAppDir = root.CreateDirectory("TestApp");
            var testLibDir = root.CreateDirectory("TestLibrary");

            //copy projects to the temp dir
            CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
            CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);

            RunRestore(testAppDir.Path);
            RunRestore(testLibDir.Path);

            // run publish
            outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(root.Path, outputDir);
            var testProject    = GetProjectPath(testAppDir);
            var publishCommand = new PublishCommand(testProject, output: outputDir);

            publishCommand.Execute().Should().Pass();

            // verify the output executable generated
            var publishedDir = publishCommand.GetOutputDirectory();
            var outputExe    = publishCommand.GetOutputExecutable();
            var outputPdb    = Path.ChangeExtension(outputExe, "pdb");

            // lets make sure that the output exe is runnable
            var outputExePath = Path.Combine(publishedDir.FullName, publishCommand.GetOutputExecutable());
            var command       = new TestCommand(outputExePath);

            command.Execute("").Should().ExitWith(100);

            // the pdb should also be published
            publishedDir.Should().HaveFile(outputPdb);
        }
Exemplo n.º 10
0
        public void CommandBase_T_NonGenericFrameworkMethodsMustBeCalledWithDataOfTypeCompatibleWithGenericTypeParameter()
        {
            ICommand command = new TestCommand <float>();

            Assert.Throws <InvalidCastException>(() => command.CanExecute(240.0));
            Assert.Throws <InvalidCastException>(() => command.Execute(240.0));
        }
Exemplo n.º 11
0
        public void TestExecute()
        {
            var command = new TestCommand();

            Assert.That(command.IsExecuted, Is.False);
            command.Execute();
            Assert.That(command.IsExecuted, Is.True);
        }
Exemplo n.º 12
0
 public void PublishFailsWhenProjectRootIsEmpty()
 {
     using (var dir = new DisposableDirectory(Temp))
     {
         var command = new TestCommand("dotnet");
         command.Execute($"publish {dir.Path}").Should().Fail();
     }
 }
Exemplo n.º 13
0
        public void Execute_RobotNull_ThrowsArgumentNullException()
        {
            // Arrange
            var command = new TestCommand();

            // Act & Assert
            Assert.Throws <ArgumentNullException>("robot", () => command.Execute(null));
        }
Exemplo n.º 14
0
        public void Execute_WhenExceptionIsThrown_PropagatesOriginalException()
        {
            var command = new TestCommand()
            {
                Console = Mock.Of <IConsole>()
            };

            Assert.Throws <DivideByZeroException>(() => command.Execute());
        }
Exemplo n.º 15
0
 private void PerformOneTimeTearDown()
 {
     // Our child tests or even unrelated tests may have
     // executed on the same thread since the time that
     // this test started, so we have to re-establish
     // the proper execution environment
     this.Context.EstablishExecutionEnvironment();
     _teardownCommand.Execute(this.Context);
 }
Exemplo n.º 16
0
 public void PublishFailsWhenProjectJsonDoesNotExist()
 {
     using (var dir = new DisposableDirectory(Temp))
     {
         var    command = new TestCommand("dotnet");
         string temp    = Path.Combine(dir.Path, "project.json");
         command.Execute($"publish {temp}").Should().Fail();
     }
 }
Exemplo n.º 17
0
        public void Execute()
        {
            var         viewModel = new TestViewModel();
            TestCommand cmd       = (TestCommand)viewModel.Commands[typeof(TestCommand)];

            Assert.IsFalse(cmd.Executed);

            cmd.Execute(viewModel);
            Assert.IsTrue(cmd.Executed);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Method that performs actually performs the work.
 /// </summary>
 protected override void PerformWork()
 {
     try
     {
         testResult = _command.Execute(Context);
     }
     finally
     {
         WorkItemComplete();
     }
 }
Exemplo n.º 19
0
        public void CommandBase_FrameworkMethodsCallIntoParameterlessImplementations()
        {
            string?  text    = null;
            ICommand command = new TestCommand(() => text = nameof(ICommand.CanExecute), () => text = nameof(ICommand.Execute));

            bool canExecute = command.CanExecute(null);

            Assert.Equal("CanExecute", text);
            Assert.True(canExecute);

            command.Execute(null);
            Assert.Equal("Execute", text);
        }
Exemplo n.º 20
0
        public void Execute_OK()
        {
            // Arrange
            var robot   = new Robot();
            var command = new TestCommand();

            // Act
            command.Execute(robot);

            // Assert
            Assert.Equal(1, robot.X);
            Assert.Equal(-1, robot.Y);
        }
Exemplo n.º 21
0
        public void ShouldCallInheritedCommandWhenUsingExecuteObject()
        {
            // Given
            var invokable = new Mock <IInvokable <bool> >();
            var command   = new TestCommand <bool>(invokable.Object);
            var parameter = (object)true;

            // When
            command.Execute(parameter);

            // Then
            invokable.Verify(i => i.Invoke(It.IsAny <bool>()), Times.Once);
        }
Exemplo n.º 22
0
        public void TestDotnetRun()
        {
            var restoreCommand = new TestCommand("dotnet");

            restoreCommand.Execute($"restore {TestProject}")
            .Should()
            .Pass();
            var runCommand = new RunCommand(TestProject);

            runCommand.Execute()
            .Should()
            .Pass();
        }
Exemplo n.º 23
0
        public void CommandBase_T_FrameworkMethodsCallIntoStronglyTypedImplementations()
        {
            string?  text    = null;
            ICommand command = new TestCommand <string>(t => text = t, t => text = t);

            bool canExecute = command.CanExecute(nameof(ICommand.CanExecute));

            Assert.Equal("CanExecute", text);
            Assert.True(canExecute);

            command.Execute(nameof(ICommand.Execute));
            Assert.Equal("Execute", text);
        }
        public override TestResult Execute(TestExecutionContext context)
        {
            TestResult testResults = null;

            try
            {
                command.Execute(context);
            }
            catch (Exception ex)
            {
                String msg = ex.Message;
            }
            testResults = context.CurrentResult;
            if (context.CurrentResult.FailCount > 0)
            {
                context.CurrentResult.SetResult(ResultState.Failure);
            }
            else
            {
                context.CurrentResult.SetResult(ResultState.Success);
            }

            TestMethodDataEntity testMethodDataEntity = new TestMethodDataEntity();

            testMethodDataEntity.TestMethodName    = context.CurrentTest.MethodName;
            testMethodDataEntity.TestClassName     = context.CurrentTest.ClassName;
            testMethodDataEntity.TestDataReference = JsonConvert.SerializeObject(context.CurrentTest.Arguments);
            testMethodDataEntity.Result            = (context.CurrentResult.ResultState == ResultState.Success) ? true : false;
            String message = "";

            if (!testMethodDataEntity.Result)
            {
                for (int i = 0; i < context.CurrentResult.AssertionResults.Count; i++)
                {
                    message += context.CurrentResult.AssertionResults[i].Message;
                }
                testMethodDataEntity.Message = message;
                // TODO: Buidling custom error messages
                // Classname, methodname and argument list is available.
                // Based on the argument list get the expected response object
                // Get the actual response object --------------------------------- NEED TO CHECK THIS
                // Get all the properties via reflection
                // Compare and build a custom error message
            }

            MongoDbConnection mongoDbConnection = new MongoDbConnection();

            mongoDbConnection.upsertTestResultsData(testMethodDataEntity);

            return(testResults);
        }
Exemplo n.º 25
0
        private void Listener_CommandReceived(ITestListener listener, TestCommand command)
        {
            if (command == null)
            {
                Console.WriteLine(" ** NULL COMMAND** ");
            }
            else
            {
                command.BeforeExecute();
                command.Execute(this);
                command.AfterExecute();


                listener.SendResult(command.Result);
            }
        }
Exemplo n.º 26
0
 /// <summary>
 /// Method that performs actually performs the work.
 /// </summary>
 protected override void PerformWork()
 {
     try
     {
         Result = _command.Execute(Context);
         // [DuongNT]: Write out the method's results
         if (!TSettings.GetInstance().IsSlaveMode&& !TSettings.GetInstance().IsManual)
         {
             TLogger.Write("##### Result of [" + Result.FullName + "] TC : " + Result.ResultState.ToString());
         }
     }
     finally
     {
         WorkItemComplete();
     }
 }
Exemplo n.º 27
0
        public void CoverNonFunctions()
        {
            var   model   = new ApplicationModel();
            ITile command = new TestCommand(model);

            OnCanExecuteChanged(this, EventArgs.Empty);
            command.CanExecuteChanged += OnCanExecuteChanged;
            command.CanExecuteChanged -= OnCanExecuteChanged;

            Assert.IsTrue(command.CanExecute(null));

            Assert.IsFalse(((TestCommand)command)._called);
            command.Execute(null);
            Assert.IsTrue(((TestCommand)command)._called);

            Assert.AreEqual("Wibble", command.Content);
        }
Exemplo n.º 28
0
        private void PerformOneTimeSetUp()
        {
            try
            {
                _setupCommand.Execute(Context);

                // SetUp may have changed some things in the environment
                Context.UpdateContextFromEnvironment();
            }
            catch (Exception ex)
            {
                if (ex is NUnitException || ex is TargetInvocationException)
                {
                    ex = ex.InnerException;
                }

                Result.RecordException(ex, FailureSite.SetUp);
            }
        }
Exemplo n.º 29
0
        private void PerformOneTimeSetUp()
        {
            try
            {
                _setupCommand.Execute(Context);

                // SetUp may have changed some things
                Context.UpdateContext();
            }
            catch (Exception ex)
            {
                if (ex is NUnitException || ex is System.Reflection.TargetInvocationException)
                {
                    ex = ex.InnerException;
                }

                Result.RecordException(ex);
            }
        }
Exemplo n.º 30
0
        protected override IEnumerable PerformWork()
        {
            if (m_Command is SkipCommand)
            {
                m_Command.Execute(Context);
                Result = Context.CurrentResult;
                WorkItemComplete();
                yield break;
            }

            if (m_Command is ApplyChangesToContextCommand)
            {
                var applyChangesToContextCommand = (ApplyChangesToContextCommand)m_Command;
                applyChangesToContextCommand.ApplyChanges(Context);
                m_Command = applyChangesToContextCommand.GetInnerCommand();
            }

            var enumerableTestMethodCommand = (IEnumerableTestMethodCommand)m_Command;

            try
            {
                var executeEnumerable = enumerableTestMethodCommand.ExecuteEnumerable(Context).GetEnumerator();

                var coroutineRunner = new CoroutineRunner(monoBehaviourCoroutineRunner, Context);
                yield return(coroutineRunner.HandleEnumerableTest(executeEnumerable));

                if (coroutineRunner.HasFailedWithTimeout())
                {
                    Context.CurrentResult.SetResult(ResultState.Failure, new UnityTestTimeoutException(Context.TestCaseTimeout).Message);
                }

                while (executeEnumerable.MoveNext())
                {
                }

                Result = Context.CurrentResult;
            }
            finally
            {
                WorkItemComplete();
            }
        }