Exemplo n.º 1
0
        public async Task GetOrders_ShouldReturnBadRequestIfInvalidCustomerId(string customerId)
        {
            // Arrange
            var data = MockCustomers.GetCustomers();
            var mockCustomersRepository = new Mock <ICustomerRepository>();
            var mockOrderRepository     = new Mock <IOrderRepository>();

            var controller = CreateControllerInstance(mockCustomersRepository.Object, mockOrderRepository.Object);

            // Act
            IHttpActionResult result = await controller.GetOrders(customerId) as BadRequestErrorMessageResult;

            // Assert
            Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult));
        }
Exemplo n.º 2
0
        public async Task Index_ModelShouldReturnCustomersFromTheApi()
        {
            // Arrange
            var customers     = MockCustomers.GetCustomers();
            var mockApiClient = new Mock <IApiClient>();

            mockApiClient.Setup(x => x.GetCustomers(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(customers));
            var controller = new HomeController(mockApiClient.Object);

            // Act
            var result = await controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(IEnumerable <CustomerListVM>));
            Assert.AreEqual(customers.Count(), (result.Model as IEnumerable <CustomerListVM>).Count());
        }
Exemplo n.º 3
0
            public async Task GetCustomers_ShouldReturnAllCustomers()
            {
                // Arrange
                var data = MockCustomers.GetCustomers();

                var customerRepo = new Mock <ICustomerRepository>();

                customerRepo.Setup(x => x.GetCustomersByName(It.IsAny <string>(), It.IsAny <CancellationToken>()))
                .Returns(Task.FromResult(data));
                var mockOrderRepository = new Mock <IOrderRepository>();

                var controller = CreateControllerInstance(customerRepo.Object, mockOrderRepository.Object);

                // Act
                var response = await controller.GetCustomers() as OkNegotiatedContentResult <IEnumerable <CustomerListVM> >;

                var content = response.Content;

                // Assert
                Assert.IsNotNull(content);
                Assert.AreEqual(data.Count(), content.Count());
            }
 protected override void OnInitRecords() => Records.AddRange(MockCustomers.GetCustomers());