Exemplo n.º 1
0
 public override void because()
 {
     retreivedDateTime = new DateTimeOffset(originalDateTime.Year, originalDateTime.Month, originalDateTime.Day, originalDateTime.Hour, originalDateTime.Minute, originalDateTime.Second, originalDateTime.Offset);
     equalityComparer  = new DateTimeOffsetEqualityComparer(TimeSpan.FromSeconds(1));
 }
Exemplo n.º 2
0
    List <TMaster> GenerateObjects(Table table)
    {
        IEqualityComparer <object> comparer;
        var columnType = table.ColumnTypeMap[m_MasterKeyColumn];

        if (columnType == typeof(short))
        {
            comparer = new Int16EqualityComparer();
        }
        else if (columnType == typeof(int))
        {
            comparer = new Int32EqualityComparer();
        }
        else if (columnType == typeof(long))
        {
            comparer = new Int64EqualityComparer();
        }
        else if (columnType == typeof(Guid))
        {
            comparer = new GuidEqualityComparer();
        }
        else if (columnType == typeof(string))
        {
            comparer = new StringEqualityComparer();
        }
        else if (columnType == typeof(DateTime))
        {
            comparer = new DateTimeEqualityComparer();
        }
        else if (columnType == typeof(DateTimeOffset))
        {
            comparer = new DateTimeOffsetEqualityComparer();
        }
        else if (columnType == typeof(ulong))
        {
            comparer = new UInt64EqualityComparer();
        }
        else
        {
            throw new NotSupportedException($"Key column of type '{columnType.Name}' is not supported for Master/Detail collections.");
        }

        var groups = new Dictionary <object, List <Row> >(comparer);

        foreach (var row in table.Rows)
        {
            var key = row[m_MasterKeyColumn];
            if (key == null)
            {
                throw new MissingDataException($"A null was found in the master key column '{m_MasterKeyColumn}'");
            }

            if (!groups.TryGetValue(key, out var group))
            {
                group = new();
                groups.Add(key, group);
            }
            group.Add(row);
        }

        var result = new List <TMaster>();

        foreach (var group in groups.Values)
        {
            var master = MaterializerUtilities.ConstructObject <TMaster>(group[0], m_MasterConstructor, Converter);
            var target = m_Map(master);
            foreach (var row in group)
            {
                target.Add(MaterializerUtilities.ConstructObject <TDetail>(row, m_DetailConstructor, Converter));
            }
            result.Add(master);
        }

        return(result);
    }