Ejemplo n.º 1
0
        public void WhenExecuteCommand_CommandManager_ShouldAddAlias()
        {
            string aliasName          = "myalias";
            string commandName        = "mycommand";
            string commandNamespace   = "name.space";
            string commandDescription = "description";

            var storedDataService = new StoredDataServiceMock(false);

            var mockCommand = new CommandMock(commandNamespace, commandName, commandDescription);
            var instance    = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(mockCommand);

            var commandDefinition = new AddAliasCommand(storedDataService, instance.Commands);

            instance.RegisterCommand(commandDefinition);


            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandNameParameter.GetInvokeName(),
                mockCommand.GetInvocationCommandName(),
                commandDefinition.CommandAliasParameter.GetInvokeName(),
                aliasName);

            instance.ExecuteInputRequest(inputRequest);

            var storedAlias = storedDataService.AddedCommand == mockCommand.GetInvocationCommandName();

            var actual = storedAlias;

            Assert.True(actual);
        }
        public void Execute_When_correct_request_Then_validates_Then_calls_execute()
        {
            var request = ProductCreateRequestBuilder.Create()
                          .WithProduct(ProductDtoBuilder.Create()
                                       .WithName("TEST")
                                       .WithCategoryId(1)
                                       .WithDescription("TEST DESCRIPTION")
                                       .WithOption(ProductOptionDtoBuilder.Create()
                                                   .WithIndex(1)
                                                   .WithName("TEST")
                                                   .Build())
                                       .WithVariant(ProductVariantDtoBuilder.Create()
                                                    .WithPrice(10)
                                                    .WithQuantity(10)
                                                    .WithOptionValue(ProductVariantOptionValueDtoBuilder.Create()
                                                                     .WithIndex(1)
                                                                     .WithValue("TEST")
                                                                     .Build())
                                                    .Build())
                                       .Build())
                          .Build();

            SetupMocks(request);

            CommandMock.Setup(c => c.ValidateRequestCustom());

            CommandMock.Object.Execute(request);

            CommandMock.Protected().Verify("ValidateRequest", Times.Once());
            CommandMock.Verify(c => c.ValidateRequestCustom(), Times.Once);
        }
Ejemplo n.º 3
0
        public void WhenExecuteCommandWithRepeatedAliasParameter_CommandManager_ShouldThrowException()
        {
            string aliasName          = "myalias";
            string commandName        = "mycommand";
            string commandNamespace   = "name.space";
            string commandDescription = "description";
            var    storedDataService  = new StoredDataServiceMock(true);

            var mockCommand = new CommandMock(commandNamespace, commandName, commandDescription);
            var instance    = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(mockCommand);


            var commandDefinition = new AddAliasCommand(storedDataService, instance.Commands);

            instance.RegisterCommand(commandDefinition);


            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandNameParameter.GetInvokeName(),
                mockCommand.GetInvocationCommandName(),
                commandDefinition.CommandAliasParameter.GetInvokeName(),
                aliasName);

            Assert.Throws <AliasRepeatedException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
        private static void AssertInvalidArguments(string expectedMessage, params string[] arguments)
        {
            var jiraProxyMock = new Mock<IJiraProxy>();
            var commandMock = new CommandMock<SetOrderCommand, IJiraProxy>(new SetOrderCommand(jiraProxyMock.Object, "Help"), jiraProxyMock);
            var contextMock = ContextMockFor("some-user", arguments);

            var result = commandMock.Process(contextMock.Object);
            Assert.AreEqual(expectedMessage, result.HumanReadable);
            Assert.AreEqual(string.Empty, result.PipeValue);
        }
        public void TestAddThenExecuteCommand()
        {
            Assert.ThrowsException <ArgumentNullException>(() => _commandsManager.AddThenExecuteCommand(null));
            var command = new CommandMock();

            _commandsManager.AddThenExecuteCommand(command);
            Assert.AreSame(command, _undoStack.Pop());
            Assert.AreEqual(_redoStack.Count, 0);
            Assert.IsTrue(command.IsCalledExecute);
        }
        public void Process()
        {
            var command = new CommandMock();
            // dynamic workflow = _sp.GetService(typeof(IWorkflow<,>).MakeGenericType(command.GetType(), typeof(object)));

            // var workflow = _sp.GetService<IWorkflow<CommandMock, object>>();
            // var result = workflow.Process(command, _sp);

            var wf = new HandlerWorkflow <CommandMock, object>();

            wf.Process(command, _sp);
        }
Ejemplo n.º 7
0
        private static CommandMock GetCommandWithGenericParameter()
        {
            var commandDefinition = new CommandMock(
                GenericNameSpace,
                GenericCompleteCommandName,
                GenericDescription);

            commandDefinition.CanExecuteFunction = (inputParameters) =>
            {
                return(commandDefinition.IsParamOk(inputParameters, GenericParameterName.ToLowerInvariant()));
            };
            return(commandDefinition);
        }
        public void TestUndo()
        {
            var undoCommand = new CommandMock();

            _undoStack.Push(undoCommand);
            int count = 0;

            _commandsManager.UndoRedoStacksChanged += () => count++;
            _commandsManager.Undo();
            Assert.AreEqual(_undoStack.Count, 0);
            Assert.AreSame(_redoStack.Pop(), undoCommand);
            Assert.IsTrue(undoCommand.IsCalledReverseExecution);
            Assert.AreEqual(count, 1);
        }
Ejemplo n.º 9
0
        public void SingleParameterDoWillInvokeMethodWithCorrectParameter(
            int expected)
        {
            // Fixture setup
            var builder = new DelegatingSpecimenBuilder();
            builder.OnCreate = (r, c) => expected;

            var verified = false;
            var mock = new CommandMock<int>();
            mock.OnCommand = x => verified = expected == x;
            // Exercise system
            builder.Do((int i) => mock.Command(i));
            // Verify outcome
            Assert.True(verified, "Mock wasn't verified.");
            // Teardown
        }
Ejemplo n.º 10
0
        public void DoubleParameterDoWillInvokeMethodWithCorrectParameters(
            int expectedNumber,
            string expectedText)
        {
            // Fixture setup
            var fixture = new Fixture();
            fixture.Inject(expectedNumber);
            fixture.Inject(expectedText);

            var verified = false;
            var mock = new CommandMock<int, string>();
            mock.OnCommand = (x, y) => verified =
                expectedNumber == x &&
                expectedText == y;
            // Exercise system
            fixture.Do((int x, string y) => mock.Command(x, y));
            // Verify outcome
            Assert.True(verified, "Mock wasn't verified.");
            // Teardown
        }
        public void TestAddCommand()
        {
            const string MEMBER_FUNCTION_NAME_ADD_COMMAND = "AddCommand";
            var          arguments = new object[] { null };
            TargetInvocationException expectedException = Assert.ThrowsException <TargetInvocationException>(() => _target.Invoke(MEMBER_FUNCTION_NAME_ADD_COMMAND, arguments));

            Assert.IsInstanceOfType(expectedException.InnerException, typeof(ArgumentNullException));
            _redoStack.Push(new CommandMock());
            _redoStack.Push(new CommandMock());
            int count = 0;

            _commandsManager.UndoRedoStacksChanged += () => count++;
            var command = new CommandMock();

            arguments = new object[] { command };
            _target.Invoke(MEMBER_FUNCTION_NAME_ADD_COMMAND, arguments);
            Assert.AreSame(command, _undoStack.Pop());
            Assert.AreEqual(_redoStack.Count, 0);
            Assert.AreEqual(count, 1);
        }
Ejemplo n.º 12
0
        public void DoOnCommandWithThreeParametersWillInvokeMethodWithCorrectSecondParameter()
        {
            // Fixture setup
            TimeSpan expectedTimeSpan = TimeSpan.FromHours(53);

            var sut = new Fixture();
            sut.Register<TimeSpan>(() => expectedTimeSpan);

            var mock = new CommandMock<uint, TimeSpan, TimeSpan>();
            mock.OnCommand = (x1, x2, x3) => Assert.Equal<TimeSpan>(expectedTimeSpan, x2);
            // Exercise system
            sut.Do((uint x1, TimeSpan x2, TimeSpan x3) => mock.Command(x1, x2, x3));
            // Verify outcome (done by mock)
            // Teardown
        }
Ejemplo n.º 13
0
        public void DoOnCommandWithThreeParametersWillInvokeMethodWithCorrectFirstParameter()
        {
            // Fixture setup
            DateTime expectedDateTime = new DateTime(1004328837);

            var sut = new Fixture();
            sut.Register<DateTime>(() => expectedDateTime);

            var mock = new CommandMock<DateTime, long, short>();
            mock.OnCommand = (x1, x2, x3) => Assert.Equal<DateTime>(expectedDateTime, x1);
            // Exercise system
            sut.Do((DateTime x1, long x2, short x3) => mock.Command(x1, x2, x3));
            // Verify outcome (done by mock)
            // Teardown
        }
Ejemplo n.º 14
0
        public void DoOnCommandWithThreeParametersWillInvokeMethod()
        {
            // Fixture setup
            bool methodInvoked = false;
            var sut = new Fixture();

            var mock = new CommandMock<object, object, object>();
            mock.OnCommand = (x1, x2, x3) => methodInvoked = true;
            // Exercise system
            sut.Do((object x1, object x2, object x3) => mock.Command(x1, x2, x3));
            // Verify outcome
            Assert.True(methodInvoked, "Command method invoked");
            // Teardown
        }
Ejemplo n.º 15
0
        public void DoOnCommandWithSingleParameterWillInvokeMethodWithCorrectParameter()
        {
            // Fixture setup
            int expectedNumber = 94;

            var sut = new Fixture();
            sut.Register<int>(() => expectedNumber);

            var mock = new CommandMock<int>();
            mock.OnCommand = x => Assert.Equal<int>(expectedNumber, x);
            // Exercise system
            sut.Do((int i) => mock.Command(i));
            // Verify outcome (done by mock)
            // Teardown
        }
Ejemplo n.º 16
0
        public void DoOnCommandWithFourParametersWillInvokeMethodWithCorrectThirdParameter()
        {
            // Fixture setup
            Guid expectedGuid = Guid.NewGuid();

            var sut = new Fixture();
            sut.Register<Guid>(() => expectedGuid);

            var mock = new CommandMock<bool, string, Guid, string>();
            mock.OnCommand = (x1, x2, x3, x4) => Assert.Equal<Guid>(expectedGuid, x3);
            // Exercise system
            sut.Do((bool x1, string x2, Guid x3, string x4) => mock.Command(x1, x2, x3, x4));
            // Verify outcome (done by mock)
            // Teardown
        }
Ejemplo n.º 17
0
        public void TripleParameterDoWillInvokeMethodWithCorrectParameters(
            string expectedText,
            int expectedNumber,
            bool expectedBool)
        {
            // Fixture setup
            var fixture = new Fixture();
            fixture.Inject(expectedText);
            fixture.Inject(expectedNumber);
            fixture.Inject(expectedBool);
            var builder = fixture.Compose();

            var verified = false;
            var mock = new CommandMock<string, int, bool>();
            mock.OnCommand = (x, y, z) => verified =
                expectedText == x &&
                expectedNumber == y &&
                expectedBool == z;
            // Exercise system
            builder.Do((string x, int y, bool z) => mock.Command(x, y, z));
            // Verify outcome
            Assert.True(verified, "Mock wasn't verified.");
            // Teardown
        }
Ejemplo n.º 18
0
        public void DoOnCommandWithTwoParametersWillInvokeMethodWithCorrectFirstParameter()
        {
            // Fixture setup
            double expectedNumber = 25364.37;

            var sut = new Fixture();
            sut.Register<double>(() => expectedNumber);

            var mock = new CommandMock<double, object>();
            mock.OnCommand = (x1, x2) => Assert.Equal<double>(expectedNumber, x1);
            // Exercise system
            sut.Do((double x1, object x2) => mock.Command(x1, x2));
            // Verify outcome (done by mock)
            // Teardown
        }
Ejemplo n.º 19
0
        public void DoOnCommandWithThreeParametersWillInvokeMethodWithCorrectThirdParameter()
        {
            // Fixture setup
            var expectedText = "Anonymous text";

            var sut = new Fixture();
            sut.Register<string>(() => expectedText);

            var mock = new CommandMock<double, uint, string>();
            mock.OnCommand = (x1, x2, x3) => Assert.Equal<string>(expectedText, x3);
            // Exercise system
            sut.Do((double x1, uint x2, string x3) => mock.Command(x1, x2, x3));
            // Verify outcome (done by mock)
            // Teardown
        }
Ejemplo n.º 20
0
 internal RunCommandTests()
 {
     helloCommand = CommandMock.Create(new string[] { "hello", "hi" }, new string[] { "This is the hello command" });
     echoCommand  = CommandMock.Create(new string[] { "echo", "helloShell" }, new string[] { "This is the echo command" });
 }
Ejemplo n.º 21
0
        public void DoOnCommandWithTwoParametersWillInvokeMethod()
        {
            // Fixture setup
            bool methodInvoked = false;
            var sut = new Fixture();

            var mock = new CommandMock<string, long>();
            mock.OnCommand = (x1, x2) => methodInvoked = true;
            // Exercise system
            sut.Do((string x1, long x2) => mock.Command(x1, x2));
            // Verify outcome
            Assert.True(methodInvoked, "Command method invoked");
            // Teardown
        }
Ejemplo n.º 22
0
        public void DoOnCommandWithFourParametersWillInvokeMethod()
        {
            // Fixture setup
            bool methodInvoked = false;
            var sut = new Fixture();

            var mock = new CommandMock<uint, ushort, int, bool>();
            mock.OnCommand = (x1, x2, x3, x4) => methodInvoked = true;
            // Exercise system
            sut.Do((uint x1, ushort x2, int x3, bool x4) => mock.Command(x1, x2, x3, x4));
            // Verify outcome
            Assert.True(methodInvoked, "Command method invoked");
            // Teardown
        }
Ejemplo n.º 23
0
        public void DoOnCommandWithTwoParametersWillInvokeMethodWithCorrectSecondParameter()
        {
            // Fixture setup
            short expectedNumber = 3734;

            var sut = new Fixture();
            sut.Register<short>(() => expectedNumber);

            var mock = new CommandMock<DateTime, short>();
            mock.OnCommand = (x1, x2) => Assert.Equal<short>(expectedNumber, x2);
            // Exercise system
            sut.Do((DateTime x1, short x2) => mock.Command(x1, x2));
            // Verify outcome (done by mock)
            // Teardown
        }
Ejemplo n.º 24
0
        public void DoOnCommandWithFourParametersWillInvokeMethodWithCorrectFirstParameter()
        {
            // Fixture setup
            uint expectedNumber = 294;

            var sut = new Fixture();
            sut.Register<uint>(() => expectedNumber);

            var mock = new CommandMock<uint, bool, string, Guid>();
            mock.OnCommand = (x1, x2, x3, x4) => Assert.Equal<uint>(expectedNumber, x1);
            // Exercise system
            sut.Do((uint x1, bool x2, string x3, Guid x4) => mock.Command(x1, x2, x3, x4));
            // Verify outcome (done by mock)
            // Teardown
        }
Ejemplo n.º 25
0
        public void QuadrupleParameterDoWillInvokeMethodWithCorrectParameters(
            int expectedNumber,
            string expectedText,
            Type expectedType,
            bool expectedBool)
        {
            // Fixture setup
            var fixture = new Fixture();
            fixture.Inject(expectedNumber);
            fixture.Inject(expectedText);
            fixture.Inject(expectedType);
            fixture.Inject(expectedBool);
            var builder = fixture.Compose();

            var verified = false;
            var mock = new CommandMock<int, string, Type, bool>();
            mock.OnCommand = (x, y, z, æ) => verified =
                expectedNumber == x &&
                expectedText == y &&
                expectedType == z &&
                expectedBool == æ;
            // Exercise system
            builder.Do(
                (int x, string y, Type z, bool æ) => mock.Command(x, y, z, æ));
            // Verify outcome
            Assert.True(verified, "Mock wasn't verified.");
            // Teardown
        }
Ejemplo n.º 26
0
        public void DoOnCommandWithFourParametersWillInvokeMethodWithCorrectFourthParameter()
        {
            // Fixture setup
            var expectedOS = new OperatingSystem(PlatformID.Win32NT, new Version(5, 0));

            var sut = new Fixture();
            sut.Register<OperatingSystem>(() => expectedOS);

            var mock = new CommandMock<int?, DateTime, TimeSpan, OperatingSystem>();
            mock.OnCommand = (x1, x2, x3, x4) => Assert.Equal<OperatingSystem>(expectedOS, x4);
            // Exercise system
            sut.Do((int? x1, DateTime x2, TimeSpan x3, OperatingSystem x4) => mock.Command(x1, x2, x3, x4));
            // Verify outcome (done by mock)
            // Teardown
        }
Ejemplo n.º 27
0
 public RegisterCommandTests() : base()
 {
     command  = CommandMock.CreateDefault();
     command2 = CommandMock.Create(new string[] { "mock2" }, new string[] { "mockDescripton" });
 }
Ejemplo n.º 28
0
        public void DoOnCommandWithFourParametersWillInvokeMethodWithCorrectSecondParameter()
        {
            // Fixture setup
            decimal expectedNumber = 92183.28m;

            var sut = new Fixture();
            sut.Register<decimal>(() => expectedNumber);

            var mock = new CommandMock<ushort, decimal, Guid, bool>();
            mock.OnCommand = (x1, x2, x3, x4) => Assert.Equal<decimal>(expectedNumber, x2);
            // Exercise system
            sut.Do((ushort x1, decimal x2, Guid x3, bool x4) => mock.Command(x1, x2, x3, x4));
            // Verify outcome (done by mock)
            // Teardown
        }