Exemplo n.º 1
0
        public void Crud_EntityTest()
        {
            var customer = CustomerMock.GetCustomer();

            _configurationMock.Setup(x => x.GetSection(It.IsAny <string>()))
            .Returns(new Mock <IConfigurationSection>().Object);

            var entityContext      = new EntityContext(_entityOptions);
            var unitOfWork         = new UnitOfWork(entityContext);
            var dapperContext      = new DapperContext(_configurationMock.Object);
            var customerRepository = new CustomerRepository(entityContext, dapperContext);

            customerRepository.Add(customer);
            var IsSaveCustomer = unitOfWork.Commit();

            customerRepository.Update(customer);
            var IsUpdateCustomer = unitOfWork.Commit();

            customerRepository.Remove(customer);
            var IsRemoverCustomer = unitOfWork.Commit();

            Assert.Equal(1, IsSaveCustomer);
            Assert.Equal(1, IsUpdateCustomer);
            Assert.Equal(1, IsRemoverCustomer);
        }
        public void Remove_SucessTestAsync()
        {
            var customer = CustomerViewModelMock.GetCustomer();

            _mapperMock.Setup(x => x.Map <Customer>(It.IsAny <CustomerViewModel>()))
            .Returns(CustomerMock.GetCustomer());

            var customerService = new CustomerService(_customerRepositoryMock.Object,
                                                      _viaCEPServiceMock.Object, _domainNotificationMock.Object,
                                                      _unitOfWorkMock.Object, _mapperMock.Object);

            customerService.Remove(customer);

            Assert.NotNull(customer);
        }
        public async Task GetById_ReturnCustomerViewModelTestAsync()
        {
            int id         = 1;
            var customerId = CustomerViewModelMock.GetCustomerId(id);

            _customerRepositoryMock.Setup(x => x.GetByIdAsync(id))
            .ReturnsAsync(CustomerMock.GetCustomer());

            _mapperMock.Setup(x => x.Map <CustomerViewModel>(It.IsAny <Customer>()))
            .Returns(CustomerViewModelMock.GetCustomer());

            var customerService = new CustomerService(_customerRepositoryMock.Object,
                                                      _viaCEPServiceMock.Object, _domainNotificationMock.Object,
                                                      _unitOfWorkMock.Object, _mapperMock.Object);

            var customeMethod = await customerService.GetByIdAsync(customerId);

            var customerResult = Assert.IsAssignableFrom <CustomerViewModel>(customeMethod);

            Assert.NotNull(customerResult);
        }
        public void Add_ReturnCustomerViewModelTestAsync()
        {
            var customer = CustomerViewModelMock.GetCustomer();

            _mapperMock.Setup(x => x.Map <Customer>(It.IsAny <CustomerViewModel>()))
            .Returns(CustomerMock.GetCustomer());

            _mapperMock.Setup(x => x.Map <CustomerViewModel>(It.IsAny <Customer>()))
            .Returns(CustomerViewModelMock.GetCustomer());

            _customerRepositoryMock.Setup(x => x.GetByNameAsync(customer.Name))
            .ReturnsAsync(CustomerMock.GetCustomerAddress());

            var customerService = new CustomerService(_customerRepositoryMock.Object,
                                                      _viaCEPServiceMock.Object, _domainNotificationMock.Object,
                                                      _unitOfWorkMock.Object, _mapperMock.Object);

            customerService.Add(customer);

            Assert.NotNull(customer);
        }