예제 #1
0
 public IGroup CreateGroup(string groupName)
 {
     // call this constructor doesn't fire the group changed event
     DbGroup createdGroup = new DbGroup(groupName);
     createdGroup.AssignStores(this.groups, this.dispatcher, this.favorites);
     return createdGroup;
 }
예제 #2
0
        public void LongDbGroupName_ValidateNameOnly_ReturnsNameError()
        {
            var group = new DbGroup();

            group.Name = LongText;
            AssertNameOnlyValidation(this.validator, group);
        }
예제 #3
0
        private DbGroup AddNewGroupToPrimaryPersistence(string newGroupName)
        {
            DbGroup testGroup = this.CreateNewTestGroup(newGroupName);

            this.PrimaryPersistence.Groups.Add(testGroup);
            return(testGroup);
        }
예제 #4
0
 public static Group Convert(this DbGroup group)
 {
     return(new Group()
     {
         Id = group.GroupId, Name = group.Name
     });
 }
예제 #5
0
 public DBAL()
 {
     this.SQL              = AnySQL.CreateInstance();
     this.User             = new DbUser(this.SQL);
     this.Group            = new DbGroup(this.SQL);
     this.UserGroupMapping = new DbUserGroupMapping(this.SQL);
 }
예제 #6
0
        public int AddGroup(string name)
        {
            var item = Context.Groups.FirstOrDefault(x => x.Name == name);

            if (item != null)
            {
                return(item.GroupId);
            }
            item = new DbGroup()
            {
                Name = name
            };

            Context.Groups.Add(item);

            try
            {
                Context.SaveChanges();
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception:{ex.Message}");
                return(-1);
            }
            return(item.GroupId);
        }
예제 #7
0
        public async Task ShouldUpdateGroup()
        {
            //Given
            var updateGroupRequest = _fixture.Create <UpdateGroupRequest>();

            var dbGroup = new DbGroup();

            _unitOfWorkMock
            .Setup(r => r.GroupRepository.UpdateAsync(It.IsAny <DbGroup>()))
            .Callback((DbGroup s) =>
            {
                dbGroup = s;
            })
            .Returns(Task.CompletedTask).Verifiable();

            var sut = CreateSut();

            //When
            await sut.UpdateGroupAsync(updateGroupRequest);

            //Then
            _unitOfWorkMock.VerifyAll();

            dbGroup.Name.Should().Be(updateGroupRequest.Name);
        }
예제 #8
0
        public void AddGroup_AddsToDatabase()
        {
            DbGroup         childGroup    = this.AddGroupAToPrimaryPersistence();
            DbSet <DbGroup> checkedGroups = this.CheckDatabase.Groups;
            DbGroup         checkedChild  = checkedGroups.FirstOrDefault(group => group.Id == childGroup.Id);

            Assert.IsNotNull(checkedChild, "Group wasn't added to the database");
        }
예제 #9
0
        /// <summary>
        /// Returns the newly created groups in Primary persistence. Item1 = Parent, Item2 = Child.
        /// </summary>
        private Tuple <DbGroup, DbGroup> AssignParentToChildGroup()
        {
            DbGroup childGroup  = this.AddGroupAToPrimaryPersistence();
            DbGroup parentGroup = this.AddNewGroupToPrimaryPersistence("TestGroupB");

            childGroup.Parent = parentGroup; // don't use entities here, we are testing intern logic
            this.PrimaryPersistence.Groups.Update(childGroup);
            return(new Tuple <DbGroup, DbGroup>(parentGroup, childGroup));
        }
예제 #10
0
        public static string ConvertGroupToSourceId(DbGroup _group)
        {
            if (!string.IsNullOrWhiteSpace(_group.GroupPrefix))
            {
                return($"{_group.GroupPrefix}{_group.GroupId}");
            }

            return(_group.GroupId.ToString());
        }
예제 #11
0
        public void UpdateGroup_SavesParentPropertyToDatabase()
        {
            Tuple <DbGroup, DbGroup> created = this.AssignParentToChildGroup();
            DbGroup checkedParent            = this.FindCheckedGroupById(created.Item1.Id);
            DbGroup checkedChild             = this.FindCheckedGroupById(created.Item2.Id);

            Assert.IsNotNull(checkedChild, "Child group wasn't added to the database");
            Assert.IsNotNull(checkedParent, "Parent group wasn't added to the database");
            Assert.AreEqual(1, checkedParent.ChildGroups.Count, "Group wasn't added as child");
        }
예제 #12
0
        async Task AddGroup(string name, string description)
        {
            var newGroup = new DbGroup
            {
                Name        = name,
                Description = description,
                Type        = "THEMECAMP"
            };

            await Context.AddAsync(newGroup);
        }
예제 #13
0
        public void AddGroup_SavesParentToDatabase()
        {
            DbGroup parentGroup = this.AddNewGroupToPrimaryPersistence("TestGroupB");
            // dont save the group before parent is assigned.
            DbGroup childGroup = this.CreateNewTestGroup("TestGroupA");

            childGroup.Parent = parentGroup; // don't use entities here, we are testing intern logic
            this.PrimaryPersistence.Groups.Add(childGroup);

            var checkedChild = this.FindInSecondaryPersistence(childGroup.Id);

            Assert.IsNotNull(checkedChild.Parent, "Newly added group parent wasnt saved to the database.");
        }
예제 #14
0
        public void UpdateGroup_UpdatesName()
        {
            DbGroup      childGroup = this.AddGroupAToPrimaryPersistence();
            const string NEWNAME    = "UpdatedName";

            childGroup.Name = NEWNAME;
            this.PrimaryPersistence.Groups.Update(childGroup);

            DbGroup checkedChild = this.FindCheckedGroupById(childGroup.Id);

            Assert.IsNotNull(checkedChild, "Group wasn't added to the database");
            Assert.AreEqual(NEWNAME, checkedChild.Name, "Group name wasnt update properly");
        }
예제 #15
0
        private void ButtonNewGenerator(object sender, RoutedEventArgs e)
        {
            DbGroup dbgroup = new DbGroup();
            var     groups  = dbgroup.ReadAll(Data.Code);

            if (groups.Count == 0)
            {
                MessageBox.Show("Please add one group first!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                AddNewGeneratorWindow add = new AddNewGeneratorWindow();
                add.Show();
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DbGroup           dbGroup = new DbGroup();
            DbLocalController dblc    = new DbLocalController();

            Group group = new Group();

            group.LCCode            = Data.Code;
            group.Name              = txt_box_kod.Text;
            group.MaxProduction     = 0;
            group.NumOfUnits        = 0;
            group.CurrentProduction = 0;

            dbGroup.Create(group);

            Close();
        }
예제 #17
0
        public void AddGroupToUser(string _key, Group _group)
        {
            if (string.IsNullOrWhiteSpace(_key))
            {
                throw new ArgumentException("Key can not be null or white space!", nameof(_key));
            }

            if (_group == null)
            {
                throw new ArgumentNullException(nameof(_group));
            }

            using (var context = new GrabberDbContext())
            {
                var dbUser = context.DbUsers.FirstOrDefault(_dbUser => _dbUser.Key == _key);

                if (dbUser == null)
                {
                    throw new ArgumentException($"User with key {_key} not found!");
                }

                var existedGroup = context.DbGroups.FirstOrDefault(_dbGroup =>
                                                                   _dbGroup.GroupId == _group.GroupId && _dbGroup.DbUser.Id == dbUser.Id);

                if (existedGroup == null)
                {
                    var dbGroup = new DbGroup
                    {
                        GroupId            = _group.GroupId,
                        GroupPrefix        = _group.Prefix,
                        GroupName          = _group.Name,
                        UpdatePeriod       = _group.UpdatePeriod,
                        DbUser             = dbUser,
                        LastUpdateDateTime = DateTime.Now.ToUniversalTime()
                    };

                    context.DbGroups.Add(dbGroup);
                }
                else
                {
                    throw new ArgumentException($"User already has group with id {_group.GroupId}");
                }

                context.SaveChanges();
            }
        }
예제 #18
0
 public void Create(Group group)
 {
     _dbGroup = new DbGroup();
 }
예제 #19
0
        public static DbGroup Get(AnySQL sql, string groupName)
        {
            DbGroup dbGroup = new DbGroup(sql);

            return(dbGroup);
        }
예제 #20
0
        public static DbGroup Get(AnySQL sql, int groupId)
        {
            DbGroup dbGroup = new DbGroup(sql);

            return(dbGroup);
        }
예제 #21
0
 public GroupController()
 {
     dbGroup           = new DbGroup();
     dbActivity        = new DbActivity();
     profileController = new ProfileController();
 }