Ejemplo n.º 1
0
        public void NotSave_GivenMissingExistingWord()
        {
            var commandReceivedEventArgs = new CommandReceivedEventArgs {
                Arguments = new[] { "add" }
            };
            var mockRepo          = new Mock <IRepository>();
            var addAliasOperation = new AddAliasOperation(mockRepo.Object);

            addAliasOperation.TryToExecute(commandReceivedEventArgs);

            mockRepo.Verify(x => x.Create(It.IsAny <CommandWordEntity>()), Times.Never);
        }
Ejemplo n.º 2
0
        public void NotSave_GivenAliasAlreadyUsed()
        {
            var commandReceivedEventArgs = new CommandReceivedEventArgs {
                Arguments = new[] { "add", "foo", "bar" }
            };
            var mockRepo          = new Mock <IRepository>();
            var addAliasOperation = new AddAliasOperation(mockRepo.Object);
            var existingWord      = new CommandWordEntity {
                CommandWord = Guid.NewGuid().ToString()
            };

            mockRepo.Setup(x => x.Single(It.IsAny <CommandWordPolicy>())).Returns(existingWord);

            string message = addAliasOperation.TryToExecute(commandReceivedEventArgs);

            mockRepo.Verify(x => x.Create(It.IsAny <CommandWordEntity>()), Times.Never);
            message.Should().Contain(existingWord.CommandWord);
        }
Ejemplo n.º 3
0
        public void SaveAlias_GivenValidArguments()
        {
            var newAlias = Guid.NewGuid().ToString();
            var commandReceivedEventArgs = new CommandReceivedEventArgs {
                Arguments = new[] { "add", "foo", newAlias }
            };
            var mockRepo          = new Mock <IRepository>();
            var addAliasOperation = new AddAliasOperation(mockRepo.Object);
            var existingWord      = new CommandEntity {
                CommandWord = Guid.NewGuid().ToString()
            };

            mockRepo.SetupSequence(x => x.Single(It.IsAny <CommandPolicy>()))
            .Returns(existingWord)           // call for type to alias
            .Returns(null as CommandEntity); // check for existing

            string message = addAliasOperation.TryToExecute(commandReceivedEventArgs);

            mockRepo.Verify(x => x.Update(It.IsAny <CommandEntity>()), Times.Once);
            message.Should().Contain(newAlias);
        }