Exemplo n.º 1
0
        public void Equals_DifferentValues_False()
        {
            var comparer = ProjectionEqualityComparer <Foo> .Create(f => new { f.Bar, f.Baz });

            Assert.IsFalse(comparer.Equals(
                               new Foo {
                Bar = "foo", Baz = 2, Qux = DateTime.Now
            },
                               new Foo {
                Bar = "foo", Baz = 3, Qux = DateTime.Now.AddHours(-1)
            })
                           );
        }
Exemplo n.º 2
0
        public async Task <ActionResult <List <UserDTO> > > GetCourseMembers(Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var cachedMembers = await cache.GetCourseMembersAsync(id);

            if (!(cachedMembers is null))
            {
                return(cachedMembers);
            }

            var course = await _context.Courses.FindAsync(id);

            if (course is null)
            {
                return(NotFound());
            }

            var courseGroups = await _context.Courses
                               .Where(c => c.Id == id)
                               .Select(c => c.Groups.Select(g => g.Group))
                               .FirstOrDefaultAsync();

            var members = new List <UserDTO>();

            foreach (var group in courseGroups)
            {
                var users = await userManager.GetUsersForClaimAsync(new System.Security.Claims.Claim("study_group", group.Code));

                members.AddRange(users.Select(user => courseMapper.MapUser(user)));
            }

            var nonGroupMembers = await _context.Courses
                                  .Where(c => c.Id == id)
                                  .Select(c => c.Students.Select(s => s.Student.User))
                                  .FirstOrDefaultAsync();

            members.AddRange(nonGroupMembers.Select(user => courseMapper.MapUser(user)));

            members = members.Distinct(ProjectionEqualityComparer <UserDTO> .Create(u => u.Id))
                      .OrderBy(u => u.FirstName)
                      .ToList();

            await cache.SetCourseMembersAsync(id, members);

            return(members);
        }
Exemplo n.º 3
0
        public static IEnumerable <TArg> Except <TArg, TProjection>(this IEnumerable <TArg> first, IEnumerable <TArg> second, Func <TArg, TProjection> projection)
        {
            if (first == null)
            {
                throw new ArgumentNullException(nameof(first));
            }
            if (second == null)
            {
                throw new ArgumentNullException(nameof(second));
            }
            if (projection == null)
            {
                throw new ArgumentNullException(nameof(projection));
            }
            if (ReferenceEquals(first, projection))
            {
                throw new ArgumentException(paramName: nameof(projection), message: "Projection must be an anonymous type.");
            }

            return(first.Except(second, ProjectionEqualityComparer <TArg> .Create(projection)));
        }
Exemplo n.º 4
0
        public static bool operator ==(CXmlFileNodeImp node1, CXmlFileNodeImp node2)
        {
            bool mattributesFlag, textFlag, childNodesFlag;

            #region compair the text of the node

            /**********************************************************************************
            * compair the text of the node
            **********************************************************************************/
            textFlag = (node1.text == node2.text) ? true : false;
            if (!textFlag)
            {
                CLog loger = CLog.CreateInstance();
                loger.Append(XmlSettingRptDicCategory.ChangedNodeText.ToString(),
                             node2.name,
                             node2.key,
                             node2.xPath,
                             "Inner Xml Text",
                             node1.text,
                             node2.text);
            }
            #endregion

            #region compair the attributes of the nodes

            /**********************************************************************************
            * compair the attributes of the node
            **********************************************************************************/
            mattributesFlag = true;
            // Union the two Node m_mattributes by key,
            //    if the value is different for the key, keep the first Node attribute
            IEnumerable <KeyValuePair <string, string> > attrUnion = node1.m_attributes.
                                                                     Union <KeyValuePair <string, string> >(node2.m_attributes,
                                                                                                            ProjectionEqualityComparer <KeyValuePair <string, string> > .Create(a => a.Key));
            foreach (KeyValuePair <string, string> tempKeyValPair in attrUnion)
            {
                // find the new added attributes
                if (!node1.m_attributes.Keys.Any <string>((string temKey) => temKey == tempKeyValPair.Key))
                {
                    CLog loger = CLog.CreateInstance();
                    loger.Append(XmlSettingRptDicCategory.AddedAttribute.ToString(),
                                 node2.name,
                                 node2.key,
                                 node2.xPath,
                                 tempKeyValPair.Key,
                                 "[New Added]",
                                 tempKeyValPair.Value);
                    mattributesFlag = false;
                }

                // find the deleted attribute and changed attributes
                if (!node2.m_attributes.Keys.Any <string>((string temKey) => temKey == tempKeyValPair.Key))
                {
                    //deleted attribute
                    CLog loger = CLog.CreateInstance();
                    loger.Append(XmlSettingRptDicCategory.DeletedAttribute.ToString(),
                                 node2.name,
                                 node2.key,
                                 node2.xPath,
                                 tempKeyValPair.Key,
                                 tempKeyValPair.Value,
                                 "[Deleted]");
                    mattributesFlag = false;
                }
                else if (node2.m_attributes[tempKeyValPair.Key] != tempKeyValPair.Value)
                {
                    //changed attribute
                    CLog loger = CLog.CreateInstance();
                    loger.Append(XmlSettingRptDicCategory.ChangedAttribute.ToString(),
                                 node2.name,
                                 node2.key,
                                 node2.xPath,
                                 tempKeyValPair.Key,
                                 node1.m_attributes[tempKeyValPair.Key],
                                 node2.m_attributes[tempKeyValPair.Key]);
                    mattributesFlag = false;
                }
            }
            #endregion

            #region compair the child nodes of the nodes
            childNodesFlag = true;

            IEnumerable <KeyValuePair <string, IXmlFileNode> > childUnion = node1.m_childNodes.
                                                                            Union <KeyValuePair <string, IXmlFileNode> >(node2.m_childNodes,
                                                                                                                         ProjectionEqualityComparer <KeyValuePair <string, IXmlFileNode> > .Create(a => a.Key));
            foreach (KeyValuePair <string, IXmlFileNode> tempKeyValPair in childUnion)
            {
                // find the new added child nodes
                if (!node1.m_childNodes.Keys.Any <string>((string temKey) => temKey == tempKeyValPair.Key))
                {
                    // new nodes
                    CLog loger = CLog.CreateInstance();
                    loger.Append(XmlSettingRptDicCategory.AddedChildNode.ToString(),
                                 node2.name,
                                 node2.key,
                                 node2.xPath,
                                 "[Child Notes]",
                                 "[New Added]",
                                 tempKeyValPair.Key);
                    childNodesFlag = false;
                }
                // find the deleted child nodes and changed child nodes
                if (!node2.m_childNodes.Keys.Any <string>((string temKey) => temKey == tempKeyValPair.Key))
                {
                    // deleted nodes
                    CLog loger = CLog.CreateInstance();
                    loger.Append(XmlSettingRptDicCategory.DeletedChildNode.ToString(),
                                 node2.name,
                                 node2.key,
                                 node2.xPath,
                                 "[Child Notes]",
                                 tempKeyValPair.Key,
                                 "[Deleted]");
                    childNodesFlag = false;
                }
                else
                {
                    CXmlFileNodeImp tmpNode1 = (CXmlFileNodeImp)tempKeyValPair.Value;
                    CXmlFileNodeImp tmpNode2 = (CXmlFileNodeImp)node2.m_childNodes[tempKeyValPair.Key];
                    if (!(tmpNode1 == tmpNode2))
                    {
                        childNodesFlag = false;
                    }
                }
            }
            #endregion

            if (mattributesFlag && textFlag && childNodesFlag)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public void ProjectToNumberWithGenericType()
 {
     TestNumberComparison(ProjectionEqualityComparer <NameAndNumber> .Create(x => x.Number));
 }
 public void ProjectToNumberWithExplicitType()
 {
     TestNumberComparison(ProjectionEqualityComparer.Create((NameAndNumber x) => x.Number));
 }
 public void ProjectToNumberWithIgnoredParameter()
 {
     TestNumberComparison(ProjectionEqualityComparer.Create(A10, x => x.Number));
 }
 public void ProjectToStringWithGenericType()
 {
     TestNameComparison(ProjectionEqualityComparer <NameAndNumber> .Create(x => x.Name));
 }
 public void ProjectToStringWithExplicitType()
 {
     TestNameComparison(ProjectionEqualityComparer.Create((NameAndNumber x) => x.Name));
 }
 public void ProjectToStringWithIgnoredParameter()
 {
     TestNameComparison(ProjectionEqualityComparer.Create(A10, x => x.Name));
 }
Exemplo n.º 11
0
 static OrderExpressionComparer()
 {
     Comparer = ProjectionEqualityComparer <OrderExpression> .Create(o => new { o.AttributeName, o.OrderType });
 }
Exemplo n.º 12
0
 static PagingInfoComparer()
 {
     Comparer = ProjectionEqualityComparer <PagingInfo> .Create(i => new { i.Count, i.PageNumber, i.PagingCookie, i.ReturnTotalRecordCount });
 }