예제 #1
0
        public async Task DeleteCustomerValidTest()
        {
            var result = await _customersController.Delete(CustomerMotherObject.ValidCustomer().PublicId);

            var contentResult = (NoContentResult)result;

            Assert.IsType <NoContentResult>(contentResult);
            Assert.Equal(204, contentResult.StatusCode);
        }
예제 #2
0
        public async Task EditCustomerValidTest()
        {
            var result = await _customersController.Put(CustomerMotherObject.ValidCustomer().PublicId, CustomerMotherObject.ValidCustomerInput());

            var contentResult = (AcceptedResult)result;

            Assert.IsType <AcceptedResult>(contentResult);
            Assert.Equal(202, contentResult.StatusCode);
        }
예제 #3
0
        public async Task CreateCustomerValidTest()
        {
            var result = await _customersController.Post(CustomerMotherObject.ValidCustomerInput());

            var contentResult       = (CreatedResult)result;
            var contentResultObject = (CustomerOutput)contentResult.Value;

            Assert.IsType <CreatedResult>(contentResult);
            Assert.Equal(201, contentResult.StatusCode);
            Assert.NotNull(contentResult.Value);
            Assert.Equal(CustomerMotherObject.ValidCustomerInput().Name, contentResultObject.Name);
        }
        public async Task AddValidCustomerTest()
        {
            using var scope = _serviceProvider.CreateScope();
            var _customerService = scope.ServiceProvider.GetService <ICustomerService>();

            var customerSaved = await _customerService.AddAsync(CustomerMotherObject.ValidCustomer());

            var customerFound = await _customerService.FindByIdAsync(customerSaved.PublicId);

            Assert.NotNull(customerFound);
            Assert.Equal(CustomerMotherObject.ValidCustomer().Name, customerFound.Name);
            Assert.True(customerFound.CustomerId > 0);
        }
예제 #5
0
        public async Task GetCustomerValidTest()
        {
            var result = await _customersController.Get(CustomerMotherObject.ValidCustomer().PublicId);

            var contentResult = (OkObjectResult)result;
            var customer      = (CustomerOutput)contentResult.Value;

            Assert.IsType <OkObjectResult>(contentResult);
            Assert.Equal(200, contentResult.StatusCode);

            Assert.IsType <CustomerOutput>(contentResult.Value);
            Assert.Equal(CustomerMotherObject.ValidCustomer().Name, customer.Name);
        }
        public async Task ListCustomerPaginatedQuantityTest()
        {
            const int expectedQuantity = 1;

            using var scope = _serviceProvider.CreateScope();
            var _customerService = scope.ServiceProvider.GetService <ICustomerService>();

            await _customerService.AddAsync(CustomerMotherObject.ValidCustomer());

            var customerList = await _customerService.ListPaginate(new CustomerFilter { Quantity = expectedQuantity });

            Assert.NotNull(customerList);
            Assert.Equal(expectedQuantity, customerList.Items.Count);
        }
        public async Task ListCustomerPaginatedTest()
        {
            using var scope = _serviceProvider.CreateScope();
            var _customerService = scope.ServiceProvider.GetService <ICustomerService>();

            var customerSaved = await _customerService.AddAsync(CustomerMotherObject.ValidCustomer());

            var customerSaved2 = await _customerService.AddAsync(CustomerMotherObject.ValidCustomer2());

            var customerList = await _customerService.ListPaginate(new CustomerFilter { });

            Assert.NotNull(customerList);

            Assert.True(customerList.Items.Where(x => x.Name.Equals(CustomerMotherObject.ValidCustomer().Name)).Any());
            Assert.True(customerList.Items.Where(x => x.Name.Equals(CustomerMotherObject.ValidCustomer2().Name)).Any());
        }
        public async Task RemoveCustomerTest()
        {
            using var scope = _serviceProvider.CreateScope();
            var _customerService = scope.ServiceProvider.GetService <ICustomerService>();

            var customerSaved = await _customerService.AddAsync(CustomerMotherObject.ValidCustomer());

            var customerFound = await _customerService.FindByIdAsync(customerSaved.PublicId);

            Assert.NotNull(customerFound);

            await _customerService.DeleteAsync(customerFound.PublicId);

            var customerDeleted = await _customerService.FindByIdAsync(customerSaved.PublicId);

            Assert.Null(customerDeleted);
        }
        public async Task EditCustomerTest()
        {
            using var scope = _serviceProvider.CreateScope();
            var _customerService = scope.ServiceProvider.GetService <ICustomerService>();

            var customerSaved = await _customerService.AddAsync(CustomerMotherObject.ValidCustomer());

            var customerFound = await _customerService.FindByIdAsync(customerSaved.PublicId);

            Assert.NotNull(customerFound);

            customerFound.Name = "Jane";

            await _customerService.UpdateAsync(customerFound);

            await _customerService.FindByIdAsync(customerSaved.PublicId);

            var customerEdited = await _customerService.FindByIdAsync(customerSaved.PublicId);

            Assert.Equal(customerFound.Name, customerEdited.Name);
        }
예제 #10
0
        private void SetupServiceMock()
        {
            var customerServiceMock = new Mock <ICustomerService>();
            var customerList        = new List <Customer>
            {
                CustomerMotherObject.ValidCustomer(),
                CustomerMotherObject.ValidCustomer(),
                CustomerMotherObject.ValidCustomer(),
                CustomerMotherObject.ValidCustomer()
            };

            var customerListPaginated = new PagedList <Customer>(customerList, 4);

            customerServiceMock.Setup(x => x.FindByIdAsync(CustomerMotherObject.ValidCustomer().PublicId)).ReturnsAsync(CustomerMotherObject.ValidCustomer());
            customerServiceMock.Setup(x => x.AddAsync(It.IsAny <Customer>())).ReturnsAsync(CustomerMotherObject.ValidCustomer());
            customerServiceMock.Setup(x => x.UpdateAsync(It.IsAny <Customer>())).Verifiable();
            customerServiceMock.Setup(x => x.DeleteAsync(CustomerMotherObject.ValidCustomer().PublicId)).Verifiable();
            customerServiceMock.Setup(x => x.ListPaginate(It.IsAny <CustomerFilter>())).
            ReturnsAsync(customerListPaginated);

            _customersController = new CustomersController(customerServiceMock.Object, _mapper);
        }