コード例 #1
0
        public void GetTruck_WithData_OkResult()
        {
            var resultData = new GetTruckResult
            {
                Id              = Guid.NewGuid().ToString(),
                TruckType       = TruckType.FH,
                ModelYear       = DateTime.Now.Year,
                FabricationYear = DateTime.Now.Year,
                Name            = "Truck",
                Plate           = "AAA0000"
            };

            var mockService = new Mock <ITruckService>();

            mockService.Setup(m => m.GetSingle(It.IsAny <string>())).Returns(resultData);

            var subject  = new TrucksController(Mock.Of <ILogger <TrucksController> >(), mockService.Object);
            var response = subject.GetTruck(resultData.Id);

            Assert.NotNull(response);
            Assert.IsType <ActionResult <GetTruckResult> >(response);

            var result = response.Result;

            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);

            var value = (result as OkObjectResult).Value as GetTruckResult;

            Assert.NotNull(value);
            Assert.Equal(resultData, value);
        }
コード例 #2
0
        public void GetTruck_EmptyData_NotFoundResult()
        {
            var mockService = new Mock <ITruckService>();

            mockService.Setup(m => m.GetSingle(It.IsAny <string>())).Returns(null as GetTruckResult);

            var subject  = new TrucksController(Mock.Of <ILogger <TrucksController> >(), mockService.Object);
            var response = subject.GetTruck(string.Empty);

            Assert.NotNull(response);
            Assert.IsType <ActionResult <GetTruckResult> >(response);

            var result = response.Result;

            Assert.NotNull(result);
            Assert.IsType <NotFoundResult>(result);
        }