public void ControllerHasProducesAtttributeWithTheCorrectContentType()
 {
     var sut = new ResourceApiController(null);
     var attribute = sut.GetAttributes().OfType<ProducesAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.ContentTypes.Select(x => x.MediaType).First(), "application/json");
 }
 public void ControllerHasRouteAtttributeWithTheCorrectTemplate()
 {
     var sut = new ResourceApiController(null);
     var attribute = sut.GetAttributes().OfType<RouteAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Template, "api/resource");
 }
        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));
        }
        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);
        }
        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)));
        }