示例#1
0
        public void Can_Map_EntityCollection_To_EntityCollectionDisplay()
        {
            //// Arrange
            var key = Guid.NewGuid();
            var entityTfKey = Core.Constants.TypeFieldKeys.Entity.EntityCollectionKey;
            const EntityType EntityType = EntityType.EntityCollection;
            var providerKey = Guid.NewGuid();
            var ec = new EntityCollection(entityTfKey, providerKey)
                         {
                             Key = key,
                             Name = "AutoMapper Test"
                         };

            //// Act
            var ecd = AutoMapper.Mapper.Map<EntityCollectionDisplay>(ec);

            //// Assert
            Assert.AreEqual(key, ecd.Key);
            Assert.AreEqual(entityTfKey, ecd.EntityTfKey);
            Assert.AreEqual("AutoMapper Test", ecd.Name);
            Assert.AreEqual(providerKey, ecd.ProviderKey);
            Assert.AreEqual(EntityType, ecd.EntityType);
        }
        /// <summary>
        /// The create entity collection.
        /// </summary>
        /// <param name="entityTfKey">
        /// The entity type field key.
        /// </param>
        /// <param name="providerKey">
        /// The provider key.
        /// </param>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IEntityCollection"/>.
        /// </returns>
        internal IEntityCollection CreateEntityCollection(Guid entityTfKey, Guid providerKey, string name, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(!Guid.Empty.Equals(entityTfKey), "entityTfKey");
            Mandate.ParameterCondition(!Guid.Empty.Equals(providerKey), "providerKey");
            var collection = new EntityCollection(entityTfKey, providerKey) { Name = name };

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IEntityCollection>(collection), this))
            {
                collection.WasCancelled = true;
                return collection;
            }

            return collection;
        }