public void Throw_WhenThePassedTopicIsNull()
        {
            //Arrange
            var            topicsMock     = new Mock <IRepository <Topic> >();
            TopicsServices topicsServices = new TopicsServices(topicsMock.Object);

            //Act & Assert
            Assert.Throws <ArgumentNullException>(() => topicsServices.Create(null));
        }
Ejemplo n.º 2
0
        public void ReturnNull_WhenIdParameterIsInvalid()
        {
            // Arrange
            var            topicsMock     = new Mock <IRepository <Topic> >();
            TopicsServices topicsServices = new TopicsServices(topicsMock.Object);

            // Act
            Topic topicResult = topicsServices.GetById(-1);

            // Assert
            Assert.IsNull(topicResult);
        }
Ejemplo n.º 3
0
        public void Invoke_TheRepositoryMethodGetAll_Once()
        {
            //Arrange
            var            topicsMock     = new Mock <IRepository <Topic> >();
            TopicsServices topicsServices = new TopicsServices(topicsMock.Object);

            //Act
            IEnumerable <Topic> topicResult = topicsServices.GetAll();

            //Assert
            topicsMock.Verify(c => c.All(), Times.Once);
        }
        public void InvokeRepositoryMethodAddOnce_WhenThePassedTopicIsValid()
        {
            //Arrange
            var            topicsMock     = new Mock <IRepository <Topic> >();
            TopicsServices topicsServices = new TopicsServices(topicsMock.Object);
            int            topicId        = 2;
            Topic          topic          = new Topic()
            {
                Id = topicId, Name = "Topic1"
            };

            //Act
            topicsServices.Create(topic);

            //Assert
            topicsMock.Verify(x => x.Add(It.IsAny <Topic>()), Times.Once);
        }
Ejemplo n.º 5
0
        public void ReturnNull_WhenReposityMethodGetAll_ReturnsNull()
        {
            //Arrange
            var topicsMock = new Mock <IRepository <Topic> >();

            topicsMock.Setup(c => c.All()).Returns(() =>
            {
                return(null);
            });

            TopicsServices topicsServices = new TopicsServices(topicsMock.Object);

            //Act
            IEnumerable <Topic> topicResult = topicsServices.GetAll();

            //Assert
            Assert.IsNull(topicResult);
        }
Ejemplo n.º 6
0
        public void ReturnResultOfCorrectType()
        {
            //Arrange
            var topicsMock = new Mock <IRepository <Topic> >();

            topicsMock.Setup(c => c.All()).Returns(() =>
            {
                IEnumerable <Topic> expectedResultCollection = new List <Topic>();
                return(expectedResultCollection);
            });

            TopicsServices topicsServices = new TopicsServices(topicsMock.Object);

            //Act
            IEnumerable <Topic> topicResult = topicsServices.GetAll();

            //Assert
            Assert.That(topicResult, Is.InstanceOf <IEnumerable <Topic> >());
        }
Ejemplo n.º 7
0
        public void ReturnResult_WhenInvokingRepositoryMethod_GetAll()
        {
            //Arrange
            var topicsMock = new Mock <IRepository <Topic> >();
            IEnumerable <Topic> expectedResultCollection = new List <Topic>();

            topicsMock.Setup(c => c.All()).Returns(() =>
            {
                return(expectedResultCollection);
            });

            TopicsServices topicsServices = new TopicsServices(topicsMock.Object);

            //Act
            IEnumerable <Topic> topicResult = topicsServices.GetAll();

            //Assert
            Assert.That(topicResult, Is.EqualTo(expectedResultCollection));
        }
Ejemplo n.º 8
0
        public void ReturnTopic_WhenIdIsValid()
        {
            //Arrange
            var   topicsMock = new Mock <IRepository <Topic> >();
            int   topicId    = 1;
            Topic topic      = new Topic()
            {
                Id = topicId, Name = "Topic1"
            };

            topicsMock.Setup(c => c.GetById(topicId)).Returns(topic);

            TopicsServices topicsServices = new TopicsServices(topicsMock.Object);

            //Act
            Topic topicResult = topicsServices.GetById(topicId);

            //Assert
            Assert.AreSame(topic, topicResult);
        }