示例#1
0
        public void CanCreatePerson()
        {
            //Arrange
            bool insertWasCalled = false;
            var  person          = new Domain.Entity.Person()
            {
                FirstName = "Michael",
                LastName  = "Jackson",
                Age       = 55
            };

            _personRepoMock.Setup(p => p.Insert(It.IsAny <Domain.Entity.Person>())).Callback <Domain.Entity.Person>(p => insertWasCalled = true);
            //Act
            _personService.Create(person);
            //Assert
            Assert.True(insertWasCalled, "Person's insert repository was never called therefore Trip could not be created.");
            Assert.True(_transactionWasCommited, "Unit of Work transaction was not committed.");
        }
示例#2
0
        public void ShouldNotEditPersonWithoutId()
        {
            //Arrange
            bool edittWasCalled = false;
            var  person         = new Domain.Entity.Person()
            {
                FirstName = "Michael",
                LastName  = "Jackson",
                Age       = 55
            };

            _personRepoMock.Setup(p => p.Edit(It.IsAny <Domain.Entity.Person>())).Callback <Domain.Entity.Person>(p => edittWasCalled = true);
            //Act
            Assert.Throws(typeof(Exception), () => _personService.Edit(person));
            //Assert
            Assert.False(edittWasCalled, "Person's edit repository was called but it should because age smaller than 0");
            Assert.False(_transactionWasCommited, "Unit of Work transaction was not committed but it should not.");
        }
示例#3
0
        public void ShouldNotCreatePersonWithInvalidAge()
        {
            //Arrange
            bool CreatetWasCalled = false;
            var  person           = new Domain.Entity.Person()
            {
                Id        = 33,
                FirstName = "Michael",
                LastName  = "Jackson",
                Age       = -1
            };

            _personRepoMock.Setup(p => p.Insert(It.IsAny <Domain.Entity.Person>())).Callback <Domain.Entity.Person>(p => CreatetWasCalled = true);
            //Act
            Assert.Throws(typeof(Exception), () => _personService.Create(person));
            //Assert
            Assert.False(CreatetWasCalled, "Person's Create repository was called but it should because age smaller than 0");
            Assert.False(_transactionWasCommited, "Unit of Work transaction was committed but it should not.");
        }