Exemple #1
0
        public async Task Get_Returns_Instance_Of_Enumerable_CityGroupViewModel()
        {
            // Act
            var result = await addressController.Get();

            // Assert
            Assert.IsInstanceOf <IEnumerable <CityGroupViewModel> >(result);
        }
        public async void Test_Controller_Get()
        {
            var resultMany = await _controller.Get();

            var resultFail = await _controller.Get(0);

            var resultOne = await _controller.Get(1);

            Assert.NotNull(resultMany);
            Assert.NotNull(resultFail);
            Assert.NotNull(resultOne);
        }
Exemple #3
0
        public void Get_InvalidAddress_ReturnsError()
        {
            var addressController = new AddressController();
            var expectedResult    = "Address has no outputs to spend or is invalid.\n";

            var result = addressController.Get("1Aff4FgrtA1dZDwajmknWTwU2WtwUvfiXa");

            Assert.AreEqual(result, expectedResult);
        }
        public void GetNotFoundAddress()
        {
            var options = TestDbContext.TestDbInitalizer("TestingGetNotFoundAddressControllerConstructor");

            using (var database = TestDbContext.CreateTestDb(options))
            {
                _AC = new AddressController();
                _AC._addressHelper = Api.Helpers.AddressHelper.ChangeRepository(database);
                var result = _AC.Get();
                Assert.IsType <NotFoundObjectResult>(result);
            }
        }
        public void getAddress()
        {
            // Arrange
            AddressController controller = new AddressController();

            var actResult = controller.Get(1);
            // Act
            var result = actResult as OkNegotiatedContentResult <Address>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Content.ID == 1);
        }
Exemple #6
0
 public override async Task Index()
 {
     //Connect to Internal API - Must be done within action.
     using (AddressController api = new AddressController(await this.Account()))
     {
         //Make Call to API to Get Addresses:
         var addresses = api.Get();
         //Return the list only to Connecting ID.
         Clients.Client(Context.ConnectionId).indexBack(addresses);
         //Or, return to a list of specific Connection Ids - can also return to all Clients, instead of adding a parameter.
         Clients.Clients((await this.ConnectionIds()).ToList()).postBack(Address);
     }
 }
        public void GetNotFoundAddressByKeyController()
        {
            var options = TestDbContext.TestDbInitalizer("TestingGetNotFoundAddressKeyControllerConstructor");

            using (var database = TestDbContext.CreateTestDb(options))
            {
                database.Add(AddressTestData.ValidAddress1());
                database.SaveChanges();

                _AC = new AddressController();
                _AC._addressHelper = Api.Helpers.AddressHelper.ChangeRepository(database);
                var validKey = new Guid("9bc7edd6-71e6-464e-a900-05eff8ab144d");
                var result   = _AC.Get(validKey);
                Assert.IsType <NotFoundObjectResult>(result);
            }
        }
        public void GetFoundAddressByKey()
        {
            var options = TestDbContext.TestDbInitalizer("TestingGetAddressKeyControllerConstructor");

            using (var database = TestDbContext.CreateTestDb(options))
            {
                database.Add(AddressTestData.ValidAddress1());
                database.SaveChanges();

                _AC = new AddressController();
                _AC._addressHelper = Api.Helpers.AddressHelper.ChangeRepository(database);
                var validKey = AddressTestData.ValidAddress1().Key;
                var result   = _AC.Get(validKey);
                Assert.IsType <OkObjectResult>(result);
            }
        }
        public async void Get_Not_Exists()
        {
            AddressControllerMockFacade mock = new AddressControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiAddressResponseModel>(null));
            AddressController controller = new AddressController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Get(default(int));

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public void CorrectNumberOfResultsReturned()
        {
            testRepo.data.Add(a);
            testRepo.data.Add(b);
            testRepo.data.Add(c);

            var okObjectResult = controller.Get() as OkObjectResult;

            var model = (object[][])okObjectResult.Value;

            Assert.NotNull(okObjectResult.Value);

            var actual = model.Length;

            Assert.AreEqual(2, actual);
        }
        public async void Get_Exists()
        {
            AddressControllerMockFacade mock = new AddressControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new ApiAddressServerResponseModel()));
            AddressController controller = new AddressController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Get(default(int));

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var record = (response as OkObjectResult).Value as ApiAddressServerResponseModel;

            record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public void GetAddress()
        {
            var mock = new Mock <IRepository <Address> >();

            mock.Setup(repo => repo.GetById(It.IsAny <int>())).Returns(GetByIdTest(1));
            var factoryMock = new Mock <IRepositoryFactory>();

            factoryMock.Setup(f => f.GetRepository <Address>()).Returns(mock.Object);
            var serviceMock = new Mock <ICleaningServiceServiceFactory>();

            factoryMock.Setup(f => f.GetRepository <Address>()).Returns(mock.Object);
            _addressController = new AddressController(serviceMock.Object, factoryMock.Object);

            var json    = _addressController.Get(1);
            var address = json.Value as Address;

            Assert.NotNull(json);
            Assert.NotNull(address);
            Assert.AreEqual(address.Id, 1);
            Assert.AreEqual(address.City, "Lviv");
        }
        public void TestPostValidInput()
        {
            var options = TestDbContext.TestDbInitalizer("TestingPostAddressController");

            using (var database = TestDbContext.CreateTestDb(options))
            {
                Api.Helpers.AddressHelper.ChangeRepository(database);
                _AC = new AddressController();
                _AC._addressHelper = Api.Helpers.AddressHelper.ChangeRepository(database);
                var newAddy = new AddressApiModel
                {
                    Street        = "123 Unit Test St",
                    City          = "Arlington",
                    StateProvince = "TX",
                    PostalCode    = "76019",
                    Country       = "USA"
                };
                var result = _AC.Post(newAddy);
                result = _AC.Post(newAddy);
                Assert.IsType <OkObjectResult>(result);
                result = _AC.Get();
                Assert.IsType <OkObjectResult>(result);
            }
        }
        public void ShouldReturnJsonCollectionOfUserAddresses()
        {
            // arrange
            var controller = new AddressController(this.formsAuthentication, this.addressService);

            // act
            var actual = controller.Get() as JsonNetResult;

            // assert
            Assert.That(actual, Is.Not.Null);
            Debug.Assert(actual != null, "actual != null");
            var model = actual.Data as List<DeliveryAddressViewModel>;
            Debug.Assert(model != null, "model != null");
            Assert.That(model.Count, Is.GreaterThan(0));
        }
Exemple #15
0
        public static void runProgram()
        {
            var continuar = true;

            while (continuar)
            {
                try
                {
                    Random            rand         = new Random();
                    Customer          customer     = new Customer();
                    Address           address      = new Address();
                    var               customerCont = new CustomerController();
                    var               addressCont  = new AddressController();
                    IHttpActionResult resp;


                    Console.WriteLine("\n Bienvenido a CENFOBANK \n");
                    Console.WriteLine("Que desea realizar?");
                    Console.WriteLine("1.Registrar un nuevo cliente");
                    Console.WriteLine("2.Buscar cliente");
                    Console.WriteLine("3.Listar todos los clientes");
                    Console.WriteLine("4.Salir");
                    Console.WriteLine("Digite la opcion deseada: ");
                    var option = Console.ReadLine();
                    //MENU GENERAL
                    switch (option)
                    {
                    case "1":

                        string   userInfo;
                        string[] userArray;

                        Console.WriteLine("***************************");
                        Console.WriteLine("----- REGISTRAR CLIENTE -----");
                        Console.WriteLine("***************************");
                        Console.WriteLine("Digite numero de cedula, nombre, apellido, fecha de nacimiento, edad, estado civil, genero");
                        userInfo = Console.ReadLine();
                        Console.WriteLine("Ingrese la direccion en el siguiente orden: Provincia, Canton, Distrito. ***CON TILDES");
                        var addressInput = Console.ReadLine();

                        addressInput = addressInput.ToUpper();
                        userArray    = userInfo.Split(',');
                        var addressArray = addressInput.Split(',');
                        trimString(userArray);
                        trimString(addressArray);

                        address = new Address(addressArray);
                        //retorna el id de la direccion ingresada
                        resp = addressCont.Get(address);
                        var addressId = resp as OkNegotiatedContentResult <int>;
                        //resgistra el cliente con el id de la direccion proporcionada
                        if (addressId == null)
                        {
                            Console.WriteLine("La direccion ingresada no existe");
                        }
                        else
                        {
                            customer = new Customer(userArray, addressId.Content);
                            resp     = customerCont.Post(customer);
                            var creRespCont = resp as OkNegotiatedContentResult <string>;

                            if (creRespCont != null)
                            {
                                Console.WriteLine(creRespCont.Content);
                            }
                            else
                            {
                                var errorMsg = resp as NegotiatedContentResult <string>;
                                Console.WriteLine(errorMsg.Content);
                            }
                        }
                        break;

                    case "2":

                        Console.WriteLine("***************************");
                        Console.WriteLine("----- BUSCAR CLIENTE -----");
                        Console.WriteLine("***************************");
                        Console.WriteLine("Digite el numero de cedula del usuario:");

                        string customerId = Console.ReadLine();
                        resp = customerCont.Get(customerId);
                        var contentResult = resp as OkNegotiatedContentResult <Customer>;
                        customer = contentResult.Content;

                        if (customer != null)
                        {
                            Console.WriteLine(" ==> CLIENTE: " + customer.GetEntityInformation());
                            Console.WriteLine("*** Gestionar cliente ***");
                            Console.WriteLine("1. Cuentas bancarias del usuario");
                            Console.WriteLine("2. Operaciones de creditos del usuario");
                            Console.WriteLine("3. Modificar perfil del usuario");
                            Console.WriteLine("4. Eliminar usuario");
                            Console.Write("Digite la opcion deseada: ");
                            option = Console.ReadLine();
                            //MENU DE USUARIO
                            switch (option)
                            {
                            case "1":
                                AccountMenu.ControlAccounts(customer.Id);
                                break;

                            case "2":
                                CreditMenu.ControlCredits(customer.Id);
                                break;

                            case "3":
                                Console.WriteLine("\n Ingrese la informacion actualizada");
                                Console.Write("Nombre: ");
                                customer.Name = Console.ReadLine();
                                Console.Write("Apellido: ");
                                customer.LastName = Console.ReadLine();
                                Console.Write("Fecha de nacimiento en el siguiente formato (aaaa-mm-dd): ");
                                customer.BirthDate = Convert.ToDateTime(Console.ReadLine());
                                Console.Write("Edad: ");
                                customer.Age = Convert.ToInt32(Console.ReadLine());
                                Console.Write("Estado civil: ");
                                customer.CivilStatus = Convert.ToChar(Console.ReadLine());
                                Console.WriteLine("Genero: ");
                                customer.Gender = Convert.ToChar(Console.ReadLine());
                                resp            = customerCont.Put(customer);
                                var updRespCont = resp as OkNegotiatedContentResult <string>;

                                if (updRespCont != null)
                                {
                                    Console.WriteLine(updRespCont.Content);
                                }
                                else
                                {
                                    var erroMsg = resp as NegotiatedContentResult <string>;
                                    Console.WriteLine(erroMsg.Content);
                                }
                                break;

                            case "4":
                                resp = customerCont.Delete(customer);
                                var delRespCont = resp as OkNegotiatedContentResult <string>;

                                if (delRespCont != null)
                                {
                                    Console.WriteLine(delRespCont.Content);
                                }
                                else
                                {
                                    var erroMsg = resp as NegotiatedContentResult <string>;
                                    Console.WriteLine(erroMsg.Content);
                                }
                                break;
                            }
                        }
                        else
                        {
                            throw new Exception("El usuario no esta registrado");
                        }

                        break;

                    case "3":

                        Console.WriteLine("***************************");
                        Console.WriteLine("----- LISTAR CLIENTES -----");
                        Console.WriteLine("***************************");

                        resp = customerCont.Get();
                        var contentResp  = resp as OkNegotiatedContentResult <List <Customer> >;
                        var lstCustomers = contentResp.Content;
                        Console.WriteLine(lstCustomers);
                        var count = 0;

                        foreach (var c in lstCustomers)
                        {
                            count++;
                            Console.WriteLine(count + " ==> " + c.GetEntityInformation());
                        }

                        break;

                    case "4":
                        continuar = false;
                        break;
                    }
                }
                catch (BussinessException bex)
                {
                    Console.WriteLine("***************************");
                    Console.WriteLine("ERROR: \n");
                    Console.WriteLine(bex.AppMessage.Message);
                    Console.WriteLine("***************************");
                }
            }

            Console.ReadLine();
        }