Esempio n. 1
0
        public void ExecuteAllThreeMethodsOnce_WhenValidParametersArePassed()
        {
            //Arrange
            this.componentsFactoryMock
            .Setup(x => x.CreatePerson(this.validPersonName))
            .Returns(this.personMock.Object);

            var sut        = new CreatePersonCommand(this.historyEventWriterMock.Object, personsCollectionMock.Object, this.componentsFactoryMock.Object);
            var parameters = new List <string>()
            {
                this.validPersonName
            };

            //Act
            var returnMessage = sut.Execute(parameters);

            //Assert
            this.componentsFactoryMock.Verify(x => x.CreatePerson(this.validPersonName), Times.Once);
            this.personsCollectionMock.Verify(x => x.AddPerson(personMock.Object), Times.Once);
            this.historyEventWriterMock.
            Verify(x => x.AddHistoryEvent(
                       returnMessage,
                       personMock.Object,
                       null,
                       null,
                       null
                       ), Times.Once);
        }
        public void ReturnMessage_WhenPersonIsCreated()
        {
            var firstName = "Diana";
            var lastName  = "Krumova";
            var userName  = "******";

            var people          = new Dictionary <string, IPerson>();
            var expectedMessage = $" {firstName} {lastName} with username: {userName} was created.";

            var databaseMock = new Mock <IDataBase>();
            var factoryMock  = new Mock <IFactory>();

            var personMock = new Mock <IPerson>();

            var parameters = new List <string>()
            {
                userName, firstName, lastName,
            };

            personMock.SetupGet(p => p.UserName).Returns(userName);
            personMock.SetupGet(p => p.FirstName).Returns(firstName);
            personMock.SetupGet(p => p.LastName).Returns(lastName);

            databaseMock.SetupGet(x => x.People).Returns(people);
            factoryMock.Setup(x => x.CreatePerson(userName, firstName, lastName)).Returns(personMock.Object);

            var sut = new CreatePersonCommand(factoryMock.Object, databaseMock.Object);

            var message = sut.Execute(parameters);

            Assert.AreEqual(expectedMessage, message);
        }
        public void CreatePerson(string name, string nationality)
        {
            CreatePersonCommand command = new CreatePersonCommand(name, nationality);

            command.Execute();
            CreatePersonResult result = command.GetResult() as CreatePersonResult;

            Assert.IsTrue(result.Succeeded);
            Assert.AreEqual(name, result.Person.Name);
            Assert.AreEqual(nationality, result.Person.Nationality);
        }
        public void ThrowExeptionWhenCommandParametersAreLessThanItShouldCorrectly()
        {
            string  name   = "PersonName";
            IMember person = new Member(name);

            database.Members.Add(person);

            List <string> parameters = new List <string>
            {
            };

            CreatePersonCommand command = new CreatePersonCommand(parameters);

            command.Execute();
            Assert.IsTrue(database.Members.Any(x => x.Name == name));
        }
Esempio n. 5
0
        public void ThrowArgumentException_WhenNullPersonIsReturned()
        {
            //Arrange
            this.componentsFactoryMock
            .Setup(x => x.CreatePerson(this.validPersonName));

            var sut        = new CreatePersonCommand(this.historyEventWriterMock.Object, personsCollectionMock.Object, this.componentsFactoryMock.Object);
            var parameters = new List <string>()
            {
                this.validPersonName
            };

            var expectedReturn = string.Format(CommandsConsts.ObjectCreated, nameof(Person), validPersonName);

            //Act, Assert
            Assert.ThrowsException <ArgumentException>(() => sut.Execute(parameters));
        }
        public void CreatePersonCommand()
        {
            string  name   = "PersonName";
            IMember person = new Member(name);

            database.Members.Add(person);

            List <string> parameters = new List <string>
            {
                name
            };

            CreatePersonCommand command = new CreatePersonCommand(parameters);

            command.Execute();
            Assert.IsTrue(database.Members.Any(x => x.Name == name));
        }
        public void ThrowException_WhenPassedInvalidParametersCount()
        {
            var expectedMessage = "Failed to parse CreatePerson command parameters.";
            var databaseMock    = new Mock <IDataBase>();
            var factoryMock     = new Mock <IFactory>();

            var parameters = new List <string>()
            {
                "name", "name"
            };

            var sut = new CreatePersonCommand(factoryMock.Object, databaseMock.Object);

            var ex = Assert.ThrowsException <ArgumentException>(() => sut.Execute(parameters));

            Assert.AreEqual(expectedMessage, ex.Message);
        }
Esempio n. 8
0
        public void ReturnCorrectMessage_WhenCorrectParametrsArePassed()
        {
            //Arrange
            this.componentsFactoryMock
            .Setup(x => x.CreatePerson(this.validPersonName))
            .Returns(this.personMock.Object);

            var sut        = new CreatePersonCommand(this.historyEventWriterMock.Object, personsCollectionMock.Object, this.componentsFactoryMock.Object);
            var parameters = new List <string>()
            {
                this.validPersonName
            };

            var expectedReturn = string.Format(CommandsConsts.ObjectCreated, nameof(Person), validPersonName);

            //Act
            var actualReturn = sut.Execute(parameters);

            //Assert
            Assert.AreEqual(expectedReturn, actualReturn);
        }
        public void AddCreatedPersonToPeople_WhenUserNameNotExist()
        {
            var people = new Dictionary <string, IPerson>();

            var databaseMock = new Mock <IDataBase>();
            var factoryMock  = new Mock <IFactory>();

            var personMock = new Mock <IPerson>();
            var parameters = new List <string>()
            {
                "userName", "firstName", "lastName"
            };

            databaseMock.SetupGet(x => x.People).Returns(people);
            factoryMock.Setup(x => x.CreatePerson("userName", "firstName", "lastName")).Returns(personMock.Object);

            var sut = new CreatePersonCommand(factoryMock.Object, databaseMock.Object);

            sut.Execute(parameters);

            Assert.AreEqual(1, people.Count);
        }
        public void ReturnMessage_WhenUserNameExist()
        {
            var userName = "******";
            var people   = new Dictionary <string, IPerson>();

            var databaseMock = new Mock <IDataBase>();
            var factoryMock  = new Mock <IFactory>();
            var personMock   = new Mock <IPerson>();
            var parameters   = new List <string>()
            {
                userName, "firstName", "lastName"
            };

            people.Add(userName, personMock.Object);

            databaseMock.SetupGet(x => x.People).Returns(people);
            factoryMock.Setup(x => x.CreatePerson(userName, "firstName", "lastName")).Returns(personMock.Object);

            var sut = new CreatePersonCommand(factoryMock.Object, databaseMock.Object);

            var ex = Assert.ThrowsException <ArgumentException>(() => sut.Execute(parameters));

            Assert.AreEqual($" {userName} already exists.", ex.Message);
        }