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)); }
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)); }
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)); }
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); }
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); }
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); }
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)); } }
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); }
public void CommandBase_T_NonGenericFrameworkMethodsMustBeCalledWithDataOfTypeCompatibleWithGenericTypeParameter() { ICommand command = new TestCommand <float>(); Assert.Throws <InvalidCastException>(() => command.CanExecute(240.0)); Assert.Throws <InvalidCastException>(() => command.Execute(240.0)); }
public void TestExecute() { var command = new TestCommand(); Assert.That(command.IsExecuted, Is.False); command.Execute(); Assert.That(command.IsExecuted, Is.True); }
public void PublishFailsWhenProjectRootIsEmpty() { using (var dir = new DisposableDirectory(Temp)) { var command = new TestCommand("dotnet"); command.Execute($"publish {dir.Path}").Should().Fail(); } }
public void Execute_RobotNull_ThrowsArgumentNullException() { // Arrange var command = new TestCommand(); // Act & Assert Assert.Throws <ArgumentNullException>("robot", () => command.Execute(null)); }
public void Execute_WhenExceptionIsThrown_PropagatesOriginalException() { var command = new TestCommand() { Console = Mock.Of <IConsole>() }; Assert.Throws <DivideByZeroException>(() => command.Execute()); }
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); }
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(); } }
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); }
/// <summary> /// Method that performs actually performs the work. /// </summary> protected override void PerformWork() { try { testResult = _command.Execute(Context); } finally { WorkItemComplete(); } }
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); }
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); }
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); }
public void TestDotnetRun() { var restoreCommand = new TestCommand("dotnet"); restoreCommand.Execute($"restore {TestProject}") .Should() .Pass(); var runCommand = new RunCommand(TestProject); runCommand.Execute() .Should() .Pass(); }
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); }
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); } }
/// <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(); } }
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); }
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); } }
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); } }
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(); } }