コード例 #1
0
        public void GetResourcesByCategory()
        {
            //Arrange
            var mockAllReadyDataAccess = new Mock <IAllReadyDataAccess>();

            string resourceCat1 = "1", resourceCat2 = "2";
            var    cat1Resources = new List <Resource>()
            {
                new Resource()
                {
                    Id = 1
                }
            };

            var cat2Resources = new List <Resource>()
            {
                new Resource()
                {
                    Id = 2
                }
            };

            mockAllReadyDataAccess.Setup(x => x.GetResourcesByCategory(resourceCat1)).Returns(cat1Resources);
            mockAllReadyDataAccess.Setup(x => x.GetResourcesByCategory(resourceCat2)).Returns(cat2Resources);

            var controller = new ResourceApiController(mockAllReadyDataAccess.Object);

            //Act
            var cat1ResourceResults = controller.GetResourcesByCategory(resourceCat1);
            var cat2ResourceResults = controller.GetResourcesByCategory(resourceCat2);

            //Assert
            Assert.True(cat1ResourceResults.Any(x => x.Id == 1));
            Assert.True(cat2ResourceResults.Any(x => x.Id == 2));
        }
コード例 #2
0
        public void GetResourcesByCategoryReturnsCorrectModel()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.Send(It.IsAny <ResourcesByCategoryQuery>())).Returns(new List <Resource> {
                new Resource()
            });

            var sut     = new ResourceApiController(mediator.Object);
            var results = sut.GetResourcesByCategory(It.IsAny <string>());

            Assert.IsType <List <ResourceViewModel> >(results);
        }
コード例 #3
0
        public void GetResourcesByCategorySendsResourcesByCategoryQueryWithCorrectData()
        {
            const string category = "category";

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.Send(It.IsAny <ResourcesByCategoryQuery>())).Returns(new List <Resource>());

            var sut = new ResourceApiController(mediator.Object);

            sut.GetResourcesByCategory(category);

            mediator.Verify(x => x.Send(It.Is <ResourcesByCategoryQuery>(y => y.Category == category)));
        }