예제 #1
0
        public void Delete_ReturnsOK()
        {
            int clientId = 1115;
            var client   = new ClientDto()
            {
                ClientId        = 1115,
                ClientName      = "Sakib",
                ClientTypeId    = 1,
                CustomerId      = 1,
                AddressId       = 1,
                CreatedByUserId = 6,
                DateCreated     = System.DateTime.Now,
                IsDeleted       = false,
                DateModified    = null
            };
            var mockRepo = new Mock <NSI.Repository.Interfaces.IClientRepository>();

            mockRepo.Setup(x => x.CreateClient(It.IsAny <ClientDto>())).Returns(client);
            mockRepo.Setup(x => x.DeleteClientById(1115)).Returns(true);
            var cliManipulation = new ClientManipulation(mockRepo.Object);
            var controller      = new ClientsController(cliManipulation);

            controller.CreateNewClient(client);
            var result = controller.DeleteClient(clientId);

            // Assert
            Assert.IsType <OkObjectResult>(result);
        }
예제 #2
0
        public void UpdateClient_ReturnsNoContentResult()
        {
            var client = new ClientDto()
            {
                ClientId        = 1115,
                ClientName      = "Sakib",
                ClientTypeId    = 1,
                CustomerId      = 1,
                AddressId       = 1,
                CreatedByUserId = 6,
                DateCreated     = System.DateTime.Now,
                IsDeleted       = false,
                DateModified    = null
            };

            var mockRepo = new Mock <IClientRepository>();

            mockRepo.Setup(x => x.CreateClient(It.IsAny <ClientDto>())).Returns(client);
            mockRepo.Setup(x => x.EditClient(It.IsAny <ClientDto>())).Returns(false);
            var clientManipulation = new ClientManipulation(mockRepo.Object);
            var controller         = new ClientsController(clientManipulation);

            controller.CreateNewClient(client);

            client.ClientName = "Sakib Kurtic";

            var result = controller.EditClient(client);

            Assert.IsType <NoContentResult>(result);
        }
예제 #3
0
        public void AddClientEmptyModelState()
        {
            var client = new ClientDto()
            {
                ClientId        = 1,
                ClientName      = "Sakib",
                ClientTypeId    = 1,
                CustomerId      = 1,
                AddressId       = 1,
                CreatedByUserId = 6,
                DateCreated     = System.DateTime.Now,
                IsDeleted       = false,
                DateModified    = null
            };

            var mockRepo = new Mock <IClientRepository>();

            mockRepo.Setup(x => x.CreateClient(It.IsAny <ClientDto>())).Returns(client);
            var clientManipulation = new ClientManipulation(mockRepo.Object);
            var controller         = new ClientsController(clientManipulation);

            controller.ModelState.AddModelError("error", "some error");
            var result = controller.CreateNewClient(new ClientDto());

            Assert.IsType <BadRequestObjectResult>(result);
        }
예제 #4
0
        public InsertClientViewModel()
        {
            _client             = new Client();
            _clientManipulation = new ClientManipulation();

            InsertClientCommand    = new Command(async() => await InsertClient());
            CancelInsertionCommand = new Command(async() => await ShowClientList());
        }
예제 #5
0
        /* Inicialização da VM */
        public EditClientViewModel(int selectedClientId)
        {
            _client             = new Client();
            _client.Id          = selectedClientId;
            _clientManipulation = new ClientManipulation();

            EditClientCommand   = new Command(async() => await EditClient());
            DeleteClientCommand = new Command(async() => await DeleteClient());

            FoundClientDetails(selectedClientId);
        }
예제 #6
0
        public void GetClientById_ReturnsNOKModel()
        {
            var mockRepo = new Mock <IClientRepository>();

            mockRepo.Setup(x => x.GetClientById(It.IsAny <int>())).Returns((ClientDto)null);
            var clientManipulation = new ClientManipulation(mockRepo.Object);
            var controller         = new ClientsController(clientManipulation);
            var result             = controller.GetClientById(1);

            Assert.IsType <BadRequestObjectResult>(result);
        }
예제 #7
0
        /* Inicialização da VM */
        public ClientListViewModel()
        {
            _clientManipulation = new ClientManipulation();

            // Direcionamento para os métodos que tratam cada um dos comandos */
            OrderByIdCommand    = new Command(OrderById);
            OrderByNameCommand  = new Command(OrderByName);
            OrderByAgeCommand   = new Command(OrderByAge);
            InsertClientCommand = new Command(async() => await ShowInsertClient());

            FillClientList();
        }
예제 #8
0
        public void AddClientEmptyModel()
        {
            var client = new ClientDto()
            {
            };
            var mockRepo = new Mock <IClientRepository>();

            mockRepo.Setup(x => x.CreateClient(It.IsAny <ClientDto>())).Returns(client);
            var clientManipulation = new ClientManipulation(mockRepo.Object);
            var controller         = new ClientsController(clientManipulation);

            var result = controller.CreateNewClient(client);

            Assert.IsType <NoContentResult>(result);
        }
예제 #9
0
        public void AddClientBadModel()
        {
            var client = new ClientDto()
            {
                ClientId = 1
            };
            var mockRepo = new Mock <IClientRepository>();

            mockRepo.Setup(x => x.CreateClient(It.IsAny <ClientDto>())).Throws <NSIException>();
            var clientManipulation = new ClientManipulation(mockRepo.Object);
            var controller         = new ClientsController(clientManipulation);

            var result = controller.CreateNewClient(client);

            Assert.IsType <BadRequestObjectResult>(result);
        }