Exemplo n.º 1
0
        public void ShouldThrowArgumentNullException_WhenNullUserIsPassed()
        {
            // Arrange
            var contact                 = new Mock <Contact>();
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Contact> >();

            var contactsService = new ContactsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => contactsService.ChangeContactStatus(contact.Object, 2, "user-id", null));
        }
Exemplo n.º 2
0
        public void ShouldThrowInvalidCastException_WhenInvalidStatusTypeIsPassed()
        {
            // Arrange
            var contact                 = new Mock <Contact>();
            var user                    = new Mock <User>();
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Contact> >();

            mockedGenericRepository.Setup(gr => gr.Update(contact.Object)).Verifiable();

            var contactsService = new ContactsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act and Assert
            Assert.Throws <InvalidCastException>(() => contactsService.ChangeContactStatus(contact.Object, 4, "user-id", user.Object));
        }
Exemplo n.º 3
0
        public void ShouldThrowArgumentNullExceptionWithCorrectMessage_WhenNullUserIsPassed()
        {
            // Arrange
            var expectedExMessage = "User cannot be null.";

            var contact                 = new Mock <Contact>();
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Contact> >();

            var contactsService = new ContactsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act and Assert
            var exception = Assert.Throws <ArgumentNullException>(() => contactsService.ChangeContactStatus(contact.Object, 2, "user-id", null));

            StringAssert.Contains(expectedExMessage, exception.Message);
        }
Exemplo n.º 4
0
        public void ShouldAssignUserProccessedByWithPassedUser_WhenStatusTypeIsProccessedOrProccessing(int statusType, string userId)
        {
            // Arrange
            var user                    = new Mock <User>();
            var contact                 = new Contact();
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Contact> >();

            var contactsService = new ContactsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act
            contactsService.ChangeContactStatus(contact, statusType, userId, user.Object);

            // Assert
            Assert.AreEqual(userId, contact.UserProccessedById);
        }
Exemplo n.º 5
0
        public void ShouldAssignUserProccessedByIdToNull_WhenStatusTypeIsNotProcessed(int statusType)
        {
            // Arrange
            var user                    = new Mock <User>();
            var contact                 = new Contact();
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Contact> >();

            var contactsService = new ContactsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act
            contactsService.ChangeContactStatus(contact, statusType, "user-id", user.Object);

            // Assert
            Assert.AreEqual(null, contact.UserProccessedById);
        }
Exemplo n.º 6
0
        public void ShouldAssignNewContactStatus_WhenValidStatusTypeIsPassed(int statusType)
        {
            // Arrange
            var user                    = new Mock <User>();
            var contact                 = new Contact();
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Contact> >();

            var contactsService = new ContactsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act
            contactsService.ChangeContactStatus(contact, statusType, "user-id", user.Object);

            // Assert
            Assert.AreEqual((ContactStatusType)statusType, contact.ContactStatusType);
        }
Exemplo n.º 7
0
        public void ShouldCallCommitMethodOfUnitOfWorkOnce_WhenAContactIsPassed()
        {
            // Arrange
            var contact                 = new Mock <Contact>();
            var user                    = new Mock <User>();
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Contact> >();

            mockedUnitOfWork.Setup(uow => uow.Commit()).Verifiable();

            var contactsService = new ContactsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act
            contactsService.ChangeContactStatus(contact.Object, 2, "user-id", user.Object);

            // Assert
            mockedUnitOfWork.Verify(uow => uow.Commit(), Times.Once);
        }
Exemplo n.º 8
0
        public void ShouldThrowInvalidCastExceptionWithCorrectMessage_WhenInvalidStatusTypeIsPassed()
        {
            // Arrange
            var expectedExMessage = "Contact status type is out of enumeration range.";

            var contact                 = new Mock <Contact>();
            var user                    = new Mock <User>();
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Contact> >();

            mockedGenericRepository.Setup(gr => gr.Update(contact.Object)).Verifiable();

            var contactsService = new ContactsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act and Assert
            var exception = Assert.Throws <InvalidCastException>(() => contactsService.ChangeContactStatus(contact.Object, 4, "user-id", user.Object));

            StringAssert.Contains(expectedExMessage, exception.Message);
        }