Exemplo n.º 1
0
        public async void LoadByIsImmobilized_ShouldReturnsResponseBodyWithTwoElementInList_WhenPassIsImmobilizedTrueOrFalse_And_ServiceReturnFullList(bool isImmobilized)
        {
            var mockService = new Mock <IHardwareService>();

            mockService.Setup(s => s.LoadByIsImmobilizedAsync(It.Is <bool>(c => c)))
            .ReturnsAsync((bool value) =>
            {
                return(new List <HardwareDto>
                {
                    new HardwareDto
                    {
                        Id = Guid.NewGuid().ToString(),
                        Name = "Computador Lenovo",
                        ImmobilizerFloor = new FloorDto
                        {
                            Level = 1,
                            LevelName = "T.I"
                        }
                    },
                    new HardwareDto
                    {
                        Id = Guid.NewGuid().ToString(),
                        Name = "Computador HP",
                        ImmobilizerFloor = new FloorDto
                        {
                            Level = 1,
                            LevelName = "T.I"
                        }
                    }
                });
            });
            mockService.Setup(s => s.LoadByIsImmobilizedAsync(It.Is <bool>(c => !c)))
            .ReturnsAsync((bool value) =>
            {
                return(new List <HardwareDto>
                {
                    new HardwareDto
                    {
                        Id = Guid.NewGuid().ToString(),
                        Name = "Mouse Apple"
                    },
                    new HardwareDto
                    {
                        Id = Guid.NewGuid().ToString(),
                        Name = "Mouse Dell"
                    }
                });
            });
            var service    = mockService.Object;
            var controller = new HardwareController(service);
            var response   = await controller.LoadByIsImmobilized(isImmobilized);

            Assert.NotNull(response);
            Assert.NotEmpty(response);
            Assert.Equal(2, response.Count);
            Assert.All(response, (element) => Assert.Equal(isImmobilized, element.IsImmobilized));
        }
Exemplo n.º 2
0
        public async void LoadByIsImmobilized_ShouldReturnsResponseBodyWithNullList_WhenPassIsImmobilizedTrueOrFalse_And_ServiceReturnNullList(bool isImmobilized)
        {
            var mockService = new Mock <IHardwareService>();

            mockService.Setup(s => s.LoadByIsImmobilizedAsync(It.IsAny <bool>()))
            .ReturnsAsync((List <HardwareDto>)null);
            var service    = mockService.Object;
            var controller = new HardwareController(service);
            var response   = await controller.LoadByIsImmobilized(isImmobilized);

            Assert.Null(response);
        }