コード例 #1
0
        public async void Execute_WithCorrectModel_Successful()
        {
            // arrange
            var issueModel = new IssueModel
            {
                UserId  = Guid.NewGuid(),
                Title   = "title",
                Content = "content"
            };

            User existingUser = new User {
                Id = issueModel.UserId
            };

            this.userAccessMock
            .Setup(x => x.TryGetById(issueModel.UserId))
            .Returns(new Maybe <User>(existingUser));

            this.issueAccessMock
            .Setup(x => x.Update(issueModel.Id, issueModel.Title, issueModel.Content, false));

            var command = this.commandRepository.UpdateIssue(issueModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsSuccessful(commandResult);
        }
コード例 #2
0
        public async void Execute_WithCorrectModel_Successful()
        {
            var issueId = Guid.NewGuid();

            // arrange
            var issueEntity = new Issue
            {
                Id       = issueId,
                UserId   = Guid.NewGuid(),
                Title    = "title",
                Content  = "content",
                IsClosed = false
            };

            this.issueAccessMock
            .Setup(x => x.TryGet(issueId))
            .Returns(new Maybe <Issue>(issueEntity));

            var command = this.commandRepository.GetIssueById(issueId);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsSuccessful(commandResult);
            Assert.AreEqual(issueId, commandResult.SuccessData.Id);
        }
コード例 #3
0
        public async void Initialize_WithNull_NotSuccessful()
        {
            // arrange
            IssueModel issueModel = null;
            var        command    = this.commandRepository.UpdateIssue(issueModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsFailure(commandResult);
        }
コード例 #4
0
        public async void Initialize_WithNull_NotSuccessful()
        {
            // arrange
            RegisterUserModel registrationModel = null;
            var command = this.commandRepository.RegisterNewUser(registrationModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsFailure(commandResult);
        }
コード例 #5
0
        public async void Initialize_WithEmptyGuid_NotSuccessful()
        {
            // arrange
            Guid emptyId = Guid.Empty;
            var  command = this.commandRepository.GetIssueById(emptyId);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsFailure(commandResult);
        }
コード例 #6
0
        public async void Execute_WithNullUsername_NotSuccessful()
        {
            // arrange
            RegisterUserModel registrationModel = new RegisterUserModel {
                Username = null
            };
            var command = this.commandRepository.RegisterNewUserIfUnknown(registrationModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsFailure(commandResult);
        }
コード例 #7
0
        public void TestAppendAsserts()
        {
            List <CommandAssert> commandAsserts = new List <CommandAssert>(3);
            CommandAssert        obj            = new CommandAssert("a", "1");
            CommandAssert        obj1           = new CommandAssert("b", "2");

            commandAsserts.Add(obj);
            commandAsserts.Add(obj1);

            textEditorCommand.AppendAsserts(commandAsserts);
            Assert.AreEqual("a", textEditorCommand.Asserts[0].PropertyName);
            Assert.AreEqual("1", textEditorCommand.Asserts[0].PropertyValue);
            Assert.AreEqual("b", textEditorCommand.Asserts[1].PropertyName);
            Assert.AreEqual("2", textEditorCommand.Asserts[1].PropertyValue);
        }
コード例 #8
0
        public async void Execute_WithUnknownId_Failure()
        {
            var issueId = Guid.NewGuid();

            // arrange
            this.issueAccessMock
            .Setup(x => x.TryGet(issueId))
            .Returns(Maybe <Issue> .Empty);

            var command = this.commandRepository.GetIssueById(issueId);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsFailure(commandResult);
        }
コード例 #9
0
        public async void Execute_WithNullContent_NotSuccessful()
        {
            // arrange
            var issueModel = new IssueModel
            {
                UserId  = Guid.NewGuid(),
                Title   = "title",
                Content = null
            };

            var command = this.commandRepository.UpdateIssue(issueModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsFailure(commandResult);
        }
コード例 #10
0
        public async void Execute_WithValidModel_NotSuccessful()
        {
            // arrange
            RegisterUserModel registrationModel = new RegisterUserModel {
                Username = "******"
            };
            var existingUser = new User {
                Name = registrationModel.Username
            };

            this.userAccessMock.Setup(x => x.TryGetByName(registrationModel.Username)).Returns(new Maybe <User>(existingUser));
            var command = this.commandRepository.RegisterNewUser(registrationModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsFailure(commandResult);
        }
コード例 #11
0
        public async void Execute_WithValidModel_Successful()
        {
            // arrange
            RegisterUserModel registrationModel = new RegisterUserModel {
                Username = "******"
            };

            this.userAccessMock.Setup(x => x.TryGetByName(registrationModel.Username)).Returns(Maybe <User> .Empty);
            this.userAccessMock.Setup(x => x.Add(registrationModel.Username)).Returns(new User {
                Name = registrationModel.Username
            });
            var command = this.commandRepository.RegisterNewUser(registrationModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsSuccessful(commandResult);
            Assert.AreEqual(registrationModel.Username, commandResult.SuccessData.Name);
        }
コード例 #12
0
        public async void Execute_WithUnknownUser_NotSuccessful()
        {
            // arrange
            var issueModel = new IssueModel
            {
                UserId  = Guid.NewGuid(),
                Title   = "title",
                Content = "content"
            };

            this.userAccessMock
            .Setup(x => x.TryGetById(issueModel.UserId))
            .Returns(Maybe <User> .Empty);

            var command = this.commandRepository.UpdateIssue(issueModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsFailure(commandResult);
        }
コード例 #13
0
        internal string ToolTipTextFromPoint(System.Windows.Point cursor)
        {
            int x     = (int)Math.Floor(cursor.X / (dimension + margin));
            int y     = (int)Math.Floor(cursor.Y / (dimension + margin));
            int index = (y * boxesPerRow) + x;

            if (null == commandIndices || (index == mouseOverIndex))
            {
                return(string.Empty); // No change, skip all processing!
            }
            mouseOverIndex = index;
            if (index < 0 || (index >= commandIndices.Count))
            {
                return(null); // If there's a tool-tip, hide it.
            }
            // If a command has the associated assertions, then they will all
            // show up right after the command itself. For an example:
            //
            //   [3][4][5][5][5][5][6][7]...
            //
            // If the mouse hovers over the 3rd '5' for example, 'index' would
            // have been '4'. Here we need to back trace to the first '5',
            // which would have at position '2'. In such case, 'startIndex'
            // will point to '2' and the 'index' will be '5'.
            //
            int startIndex = index;

            while (startIndex > 0)
            {
                if (commandIndices[startIndex - 1] != commandIndices[index])
                {
                    break;
                }
                startIndex = startIndex - 1;
            }

            int globalIndex = commandIndices[index];

            if (globalIndex < 0 || (globalIndex >= editorCommands.Count))
            {
                return(null); // If there's a tool-tip, hide it.
            }
            string toolTipText = string.Empty;

            if (startIndex == index) // This is a command node.
            {
                TextEditorCommand command   = editorCommands[globalIndex];
                string            arguments = string.Empty;

                int currentArgument = 1;
                if (null != command.Arguments)
                {
                    foreach (object obj in command.Arguments)
                    {
                        arguments += string.Format("Argument {0}: {1}\n",
                                                   currentArgument++, obj.ToString());
                    }
                }

                toolTipText = string.Format("Command index: {0}\nCommand name: {1}\n{2}",
                                            command.CommandNumber, command.MethodName.ToString(), arguments);
            }
            else // This appears to be an assert node.
            {
                int assertIndex           = index - startIndex - 1;
                TextEditorCommand command = editorCommands[globalIndex];

                List <CommandAssert> asserts = command.Asserts;
                if (assertIndex < 0 || (assertIndex >= asserts.Count)) // Invalid index?!
                {
                    toolTipText = string.Format("Houston, we have a problem! " +
                                                "The index of assertion '{0}' for command '{1}' is invalid!",
                                                assertIndex, command.CommandNumber);
                }
                else
                {
                    CommandAssert assertion = asserts[assertIndex];
                    toolTipText = string.Format("Assert property: {0} ({1})\n" +
                                                "Status: {2}\nExpected value: {3}", assertion.PropertyName,
                                                assertion.AssertNumber, assertion.Passed ? "Passed" : "Failed",
                                                assertion.PropertyValue);
                }
            }

            return(toolTipText);
        }