Exemplo n.º 1
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.º 2
0
        public void Throws_on_invalid_sequences()
        {
            Assert.Throws <InvalidOperationException>(() =>
            {
                _service.InsertSyncMappings(
                    "App", "Entity",
                    new int[] { 1, 2, 3, 4, 5, 6, 7, 8 },
                    new string[] { "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "e10" }
                    );
            });

            Assert.Throws <InvalidOperationException>(() =>
            {
                _service.InsertSyncMappings(
                    "App", "Entity",
                    new int[] { },
                    new string[] { }
                    );
            });
        }
Exemplo n.º 3
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"}
            );
        }