Exemplo n.º 1
0
        public static SyncMapping InsertSyncMapping <T>(this ISyncMappingService svc, T entity, string contextName, string sourceKey) where T : BaseEntity
        {
            Guard.NotNull(entity, nameof(entity));
            Guard.NotEmpty(contextName, nameof(contextName));
            Guard.NotEmpty(sourceKey, nameof(sourceKey));

            if (entity is SyncMapping)
            {
                throw Error.InvalidOperation("Cannot insert a sync mapping record for a SyncMapping entity");
            }

            if (entity.IsTransientRecord())
            {
                throw Error.InvalidOperation("Cannot insert a sync mapping record for a transient (unsaved) entity");
            }

            var mapping = new SyncMapping
            {
                ContextName = contextName,
                EntityId    = entity.Id,
                EntityName  = typeof(T).Name,
                SourceKey   = sourceKey
            };

            return(mapping);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Inserts a range of sync mapping entities by specifying two equal sized sequences for entity ids and source keys.
        /// </summary>
        /// <param name="contextName">Context name for all mappings</param>
        /// <param name="entityName">Entity name for all mappings</param>
        /// <param name="entityIds">A sequence of entity ids</param>
        /// <param name="sourceKeys">A sequence of source keys</param>
        /// <returns>List of persisted sync mappings</returns>
        /// <remarks>Both sequences must contain at least one element and must be of equal size.</remarks>
        public static IList <SyncMapping> InsertSyncMappings(this ISyncMappingService svc, string contextName, string entityName, IEnumerable <int> entityIds, IEnumerable <string> sourceKeys)
        {
            Guard.NotEmpty(contextName, nameof(contextName));
            Guard.NotEmpty(entityName, nameof(entityName));
            Guard.NotNull(entityIds, nameof(entityIds));
            Guard.NotNull(sourceKeys, nameof(sourceKeys));

            if (!entityIds.Any() || !sourceKeys.Any() || entityIds.Count() != sourceKeys.Count())
            {
                throw Error.InvalidOperation("Both sequences must contain at least one element and must be of equal size.");
            }

            var mappings = new List <SyncMapping>();
            var arrIds   = entityIds.ToArray();
            var arrKeys  = sourceKeys.ToArray();

            for (int i = 0; i < arrIds.Length; i++)
            {
                mappings.Add(new SyncMapping
                {
                    ContextName = contextName,
                    EntityName  = entityName,
                    EntityId    = arrIds[i],
                    SourceKey   = arrKeys[i]
                });
            }

            svc.InsertSyncMappings(mappings);

            return(mappings);
        }
Exemplo n.º 3
0
        public static SyncMapping GetSyncMappingByEntity <T>(this ISyncMappingService svc, T entity, string contextName) where T : BaseEntity
        {
            Guard.NotNull(entity, nameof(entity));
            Guard.NotEmpty(contextName, nameof(contextName));

            if (entity is SyncMapping)
            {
                throw Error.InvalidOperation("Cannot get a sync mapping record for a SyncMapping entity");
            }

            if (entity.IsTransientRecord())
            {
                throw Error.InvalidOperation("Cannot get a sync mapping record for a transient (unsaved) entity");
            }

            return(svc.GetSyncMappingByEntity(entity.Id, typeof(T).Name, contextName));
        }
Exemplo n.º 4
0
        public new void SetUp()
        {
            _rs      = new MemoryRepository <SyncMapping>();
            _service = new SyncMappingService(_rs);

            _service.InsertSyncMappings(
                "App1", "Product",
                new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                new string[] { "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "e10" }
                );

            _service.InsertSyncMappings(
                "App1", "Order",
                new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                new string[] { "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "e10" }
                );

            _service.InsertSyncMappings(
                "App2", "Product",
                new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                new string[] { "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "e10" }
                );

            _service.InsertSyncMappings(
                "App2", "Order",
                new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                new string[] { "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "e10" }
                );

            int i = 1;

            foreach (var m in _rs.Table)
            {
                m.Id = i;
                i++;
            }
        }
        public new void SetUp()
        {
            _rs = new MemoryRepository<SyncMapping>();
            _service = new SyncMappingService(_rs);

            _service.InsertSyncMappings(
                "App1", "Product",
                new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                new string[] { "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "e10" }
            );

            _service.InsertSyncMappings(
                "App1", "Order",
                new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                new string[] { "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "e10" }
            );

            _service.InsertSyncMappings(
                "App2", "Product",
                new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                new string[] { "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "e10" }
            );

            _service.InsertSyncMappings(
                "App2", "Order",
                new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                new string[] { "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "e10"}
            );
        }