Ejemplo n.º 1
0
        public void TestMethod1()
        {
            ServiceRepository  repo    = new ServiceRepository();
            ManagementServices manage  = new ManagementServices(repo);
            ServicesController service = new ServicesController(manage);
            var prueba = service.Get();

            Assert.AreEqual(1, 1);
        }
        public async Task Get_ReturnsNotFound_GivenNull()
        {
            // Arrange
            var mockRepo  = new Mock <IServiceService <Service> >();
            var returning = "invalid";
            var dbMock    = GetService(null, returning);

            mockRepo.Setup(x => x.Get(It.IsAny <int>())).Returns(dbMock);

            var controller = new ServicesController(mockRepo.Object);

            // Act
            var result = await controller.Get(1);

            // Assert
            Assert.IsType <NotFoundResult>(result);
        }
        public async Task Get_ReturnsServiceDTO_GivenService()
        {
            // Arrange
            var mockRepo = new Mock <IServiceService <Service> >();
            var dbMock   = GetService(CodeServiceUsersControllerTests.GetListSync());

            mockRepo.Setup(x => x.Get(It.IsAny <int>())).Returns(dbMock);

            var controller = new ServicesController(mockRepo.Object);

            // Act
            var result = await controller.Get(1);

            // Assert
            var okResult      = Assert.IsType <OkObjectResult>(result);
            var returnService = Assert.IsType <ServiceDTO>(okResult.Value);

            Assert.Equal("Test One", returnService.Name);
        }
        public async Task Get_ReturnsEmptyListServiceDTO_GivenEmptyList()
        {
            // Arrange
            var mockRepo  = new Mock <IServiceService <Service> >();
            var returning = "empty";
            var dbMock    = GetServices(null, returning);

            mockRepo.Setup(x => x.Get()).Returns(dbMock);

            var controller = new ServicesController(mockRepo.Object);

            // Act
            var result = await controller.Get();

            // Assert
            var okResult       = Assert.IsType <OkObjectResult>(result);
            var returnServices = Assert.IsType <List <ServiceDTO> >(okResult.Value);

            Assert.Empty(returnServices);
        }
        public async Task Get_ReturnsListServiceDTO_GivenListService()
        {
            // Arrange
            var mockRepo = new Mock <IServiceService <Service> >();
            var dbMock   = GetServices(CodeServiceUsersControllerTests.GetListSync());

            mockRepo.Setup(x => x.Get()).Returns(dbMock);

            var controller = new ServicesController(mockRepo.Object);

            // Act
            var result = await controller.Get();

            // Assert
            var okResult       = Assert.IsType <OkObjectResult>(result);
            var returnServices = Assert.IsType <List <ServiceDTO> >(okResult.Value);

            Assert.Equal(3, returnServices.Count);
            Assert.Equal("Test One", returnServices.First().Name);
            Assert.Equal("Test Three", returnServices[1].Name);
            Assert.Equal("Test Two", returnServices.Last().Name);
        }