コード例 #1
0
        public async Task PostServiceRequest_Success()
        {
            // Arrange
            var mockServiceRequestService   = new Moq.Mock <IServiceRequestService>(MockBehavior.Strict);
            var expectectedServiceRequest   = CreateMockServiceRequest(Guid.NewGuid(), "Random Desc");
            var serviceRequestServiceResult = new ServiceRequestServiceResult
            {
                ServiceRequest = expectectedServiceRequest,
                Success        = true,
            };

            mockServiceRequestService
            .Setup(x => x.CreateAsync(It.IsAny <ServiceRequest>()))
            .ReturnsAsync(serviceRequestServiceResult);
            var serviceRequestsController = new ServiceRequestsController(mockServiceRequestService.Object);
            // Act
            var actualServiceRequestResult = await serviceRequestsController.PostServiceRequest(expectectedServiceRequest);

            // Assert

            var createdAtActionResult = (actualServiceRequestResult.Result as CreatedAtActionResult);

            Assert.IsTrue(this.IsSameServiceRequest(expectectedServiceRequest, (ServiceRequest)createdAtActionResult.Value));
            mockServiceRequestService.VerifyAll();
        }
コード例 #2
0
        public async Task GetServiceRequests_Success()
        {
            // Arrange
            var mockServiceRequestService  = new Moq.Mock <IServiceRequestService>(MockBehavior.Strict);
            var expectectedServiceRequests = new List <ServiceRequest>
            {
                CreateMockServiceRequest(Guid.NewGuid(), nameof(GetServiceRequests_Success) + "1"),
                CreateMockServiceRequest(Guid.NewGuid(), nameof(GetServiceRequests_Success) + "2"),
                CreateMockServiceRequest(Guid.NewGuid(), nameof(GetServiceRequests_Success) + "3"),
                CreateMockServiceRequest(Guid.NewGuid(), nameof(GetServiceRequests_Success) + "4")
            };

            mockServiceRequestService.Setup(x => x.ReadAllAsync()).ReturnsAsync(expectectedServiceRequests);
            var serviceRequestsController = new ServiceRequestsController(mockServiceRequestService.Object);
            // Act
            var actualServiceRequests = await serviceRequestsController.GetServiceRequests();

            // Assert
            Assert.AreEqual(4, actualServiceRequests.Value.Count());
            foreach (var expectectedServiceRequest in expectectedServiceRequests)
            {
                Assert.IsTrue(actualServiceRequests.Value.Any(x => x.Id.Equals(expectectedServiceRequest.Id)));
            }
            mockServiceRequestService.VerifyAll();
        }
コード例 #3
0
        public void SetUp()
        {
            _serviceRequestsRepository = new Mock <IServiceRequestsRepository>();
            _unitWork = new Mock <IUnitWork>();

            _serviceRequestsController = new ServiceRequestsController(_serviceRequestsRepository.Object,
                                                                       _unitWork.Object, ServiceProvider.GetService <IMapper>());

            SetupServiceRequestsRepository();
            SetUpUnitWork();
        }
コード例 #4
0
        public async Task GetServiceRequest_Success()
        {
            // Arrange
            var mockServiceRequestService = new Moq.Mock <IServiceRequestService>(MockBehavior.Strict);
            var expectectedServiceRequest = CreateMockServiceRequest(Guid.NewGuid(), nameof(GetServiceRequest_Success));

            mockServiceRequestService.Setup(x => x.ReadByIdAsync(It.IsAny <Guid>())).ReturnsAsync(expectectedServiceRequest);
            var serviceRequestsController = new ServiceRequestsController(mockServiceRequestService.Object);
            // Act
            var actualServiceRequestResult = await serviceRequestsController.GetServiceRequest(expectectedServiceRequest.Id);

            // Assert
            Assert.IsTrue(this.IsSameServiceRequest(expectectedServiceRequest, actualServiceRequestResult.Value));
            mockServiceRequestService.VerifyAll();
        }
コード例 #5
0
        public async Task DeleteServiceRequest_Success()
        {
            // Arrange
            var mockServiceRequestService = new Moq.Mock <IServiceRequestService>(MockBehavior.Strict);
            var expectectedServiceRequest = CreateMockServiceRequest(Guid.NewGuid(), "Random Desc");
            var serviceResult             = new ServiceResult
            {
                Success = true,
            };
            var deleteGuid = Guid.NewGuid();

            mockServiceRequestService
            .Setup(x => x.DeleteAsync(deleteGuid))
            .ReturnsAsync(serviceResult);
            var serviceRequestsController = new ServiceRequestsController(mockServiceRequestService.Object);
            // Act
            var actualServiceRequestResult = await serviceRequestsController.DeleteServiceRequest(deleteGuid);

            // Assert
            Assert.IsNotNull(actualServiceRequestResult);
            Assert.AreEqual(201, ((IStatusCodeActionResult)actualServiceRequestResult).StatusCode);
            mockServiceRequestService.VerifyAll();
        }