Пример #1
0
        public void CRUD_User()
        {
            // Create

            User expected = new User()
            {
                Name = "Test",
                LastName = "Test",
                Username = "******",
                Password = "******"
            };

            Assert.AreEqual(expected.ID, Guid.Empty);

            UserService.Save(expected);

            Assert.AreNotEqual(expected.ID, Guid.Empty);

            User actual = UserService.GetByID(expected.ID);

            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.LastName, actual.LastName);
            Assert.AreEqual(expected.Username, actual.Username);
            Assert.AreEqual(expected.Password, actual.Password);

            // Update

            expected.Name = "Test2";
            expected.LastName = "Test2";
            expected.Username = "******";
            expected.Password = "******";

            UserService.Update(expected);

            actual = UserService.GetByID(expected.ID);

            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.LastName, actual.LastName);
            Assert.AreEqual(expected.Username, actual.Username);
            Assert.AreEqual(expected.Password, actual.Password);

            // Delete

            UserService.Delete(expected);

            actual = UserService.GetByID(expected.ID);

            Assert.IsNull(actual);
        }
Пример #2
0
        public UserEditor(User user)
        {
            try
            {
                InitializeComponent();

                this.User = user;
                this.Roles = new BindingList<Role>(UserService.GetRoles(user));

                this.txtName.DataBindings.Add(new Binding("Text", User, "Name"));
                this.txtLastName.DataBindings.Add(new Binding("Text", User, "LastName"));
                this.txtUsername.DataBindings.Add(new Binding("Text", User, "Username"));

                this.lstRoles.DataSource = Roles;

                this.btnRemoveRole.Click += (s, e) =>
                {
                    if (lstRoles.SelectedItem == null)
                        return;

                    Roles.Remove((Role)lstRoles.SelectedItem);
                };

                this.btnAddRole.Click += (s, e) =>
                {
                    using (LookupForm<Role> lookup = new LookupForm<Role>())
                    {
                        lookup.DataSource = RoleService
                            .GetAll(r => r.Name)
                            .Where(r => !Roles.Contains(r))
                            .ToList();

                        var dr = lookup.ShowDialog();
                        if (dr != DialogResult.OK)
                            return;

                        Role role = lookup.SelectedItem;
                        if (role != null)
                            Roles.Add(role);
                    }
                };

            }
            catch (Exception ex)
            {
                ex.ShowMessageBox();
            }
        }
        public void InitializeData()
        {
            Role vendedor = new Role { Name = "Vendedor" };
            vendedor.Actions.Add(new RoleAction { Action = SystemAction.Sales });
            RoleService.Save(vendedor);

            User testuser = new User
            {
                Username = "******",
                Name = "test",
                LastName = "test",
                Password = "******".GetMD5Hash()
            };

            UserService.Save(testuser);

            UserService.Update(testuser, new List<Role> { vendedor });

            Measurement units = new Measurement { Name = "Unidad/es", Abbreviation = "Un." };
            MeasurementService.Save(units);

            ItemType cigarrillos = new ItemType { Name = "Cigarrillos" };
            ItemTypeService.Save(cigarrillos);

            Item item1 = new Item
            {
                Name = "Marlboro Box 10",
                InternalCode = "321",
                ExternalCode = "321",
                ItemTypeID = cigarrillos.ID,
                BaseMeasurementID = units.ID,
                MovesStock = true,
                MinimumStock = 10
            };
            item1.CurrentPrice = new Price
            {
                Date = DateTime.Now,
                Value = 2.5
            };

            Item item2 = new Item
            {
                Name = "Marlboro Box 20",
                InternalCode = "987",
                ExternalCode = "987",
                ItemTypeID = cigarrillos.ID,
                BaseMeasurementID = units.ID,
                MovesStock = true,
                MinimumStock = 10
            };
            item2.CurrentPrice = new Price
            {
                Date = DateTime.Now,
                Value = 5
            };
            Item item3 = new Item
            {
                Name = "Marlboro Comun 20",
                InternalCode = "654",
                ExternalCode = "654",
                ItemTypeID = cigarrillos.ID,
                BaseMeasurementID = units.ID,
                MovesStock = true,
                MinimumStock = 10
            };
            item3.CurrentPrice = new Price
            {
                Date = DateTime.Now,
                Value = 4.5
            };

            ItemService.Save(item1);
            ItemService.Save(item2);
            ItemService.Save(item3);
        }