示例#1
0
        public async void GetFeedbackById_IfIdExist_ExpectedFeedbackId(int feedbackId, int expected)
        {
            //Arrange
            var     profile       = new MappedProfile();
            var     configuration = new MapperConfiguration(x => x.AddProfile(profile));
            IMapper mapper        = new Mapper(configuration);

            var testFeedback = GetFeedbacks();
            //mock dataContext
            var contextMock = new Mock <DataContext>();

            contextMock.Setup(x => x.Feedbacks).ReturnsDbSet(testFeedback);

            //mockRepo
            var logger       = Mock.Of <ILogger <FeedbackRepository> >();
            var feedbackRepo = new FeedbackRepository(contextMock.Object, logger);

            //Mock actionDescriptor
            var action = new List <ActionDescriptor>();
            var mockDescriptorProvider = new Mock <IActionDescriptorCollectionProvider>();

            mockDescriptorProvider.Setup(x => x.ActionDescriptors).Returns(new ActionDescriptorCollection(action, 0));

            //create new controller
            var controller = new FeedbackController(feedbackRepo, mapper, mockDescriptorProvider.Object);

            //Act
            var result = await controller.GetFeedbackByID(feedbackId, false);

            var         contentResult = result as OkObjectResult;
            FeedbackDTO dto           = (FeedbackDTO)contentResult.Value;

            //Assert
            Assert.Equal(feedbackId, expected);
        }