示例#1
0
        /// <summary>
        /// Creates a <see cref="IDigitalMedia"/> and saves it to the database.
        /// </summary>
        /// <param name="productVariantKey">
        /// Tkey for the item to work
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IDigitalMedia"/>.
        /// </returns>
        public IDigitalMedia CreateDigitalMediaForProductVariant(Guid productVariantKey, bool raiseEvents = true)
        {
            var digitalMedia = new DigitalMedia()
            {
                FirstAccessed     = null,
                ProductVariantKey = productVariantKey
            };

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

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateDigitalMediaRepository(uow))
                {
                    repository.AddOrUpdate(digitalMedia);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IDigitalMedia>(digitalMedia), this);
            }

            return(digitalMedia);
        }
示例#2
0
        public void Digital_media_product_should_have_a_name()
        {
            const string name = "aBook.epub";

            var digitalMedia = new DigitalMedia(name);

            Assert.Equal(name, digitalMedia.Name);
        }
示例#3
0
        public void Should_send_a_mail_to_costumer_informing_the_digital_media_was_purchased()
        {
            var product             = new DigitalMedia("Johnny B. Goode.mp3");
            var customer            = new Customer("*****@*****.**");
            var expectedMailMessage = $"You purchased a {product.Name}";
            var mailSender          = Substitute.For <MailSender>();

            new NotifyDigitalMediaWasPurchased(mailSender).Handle(new DigitalMediaSold(customer, product));

            mailSender.Received(1).Send(customer.Mail, expectedMailMessage);
        }
示例#4
0
 public OrderTests()
 {
     _domainEventNotifier = Substitute.For <DomainEventNotifier>();
     DomainEventNotifier.CurrentNotifier = _domainEventNotifier;
     _digitalMedia  = new DigitalMedia("despacito.mp3");
     _book          = new Book("Sapiens");
     _customer      = new Customer("*****@*****.**");
     _address       = new Address("79042-656");
     _membership    = new Membership("Premium service");
     _paymentMethod = CreditCard.FetchByHashed("123");
     _physicalItem  = new PhysicalItem("broom");
 }
示例#5
0
        /// <summary>
        /// Responsible for building <see cref="IDigitalMedia"/>.
        /// </summary>
        /// <param name="dto">
        /// The dto.
        /// </param>
        /// <returns>
        /// The <see cref="IDigitalMedia"/>.
        /// </returns>
        public IDigitalMedia BuildEntity(DigitalMediaDto dto)
        {
            var digitalMedia = new DigitalMedia
            {
                Key               = dto.Key,
                FirstAccessed     = dto.FirstAccessed,
                ProductVariantKey = dto.ProductVariantKey,
                CreateDate        = dto.CreateDate,
                UpdateDate        = dto.UpdateDate
            };


            //Lets check for any extended data
            digitalMedia.ExtendedData = string.IsNullOrEmpty(dto.ExtendedData)
                ? new ExtendedDataCollection()
                : new ExtendedDataCollection(dto.ExtendedData);

            digitalMedia.ResetDirtyProperties();
            return(digitalMedia);
        }
示例#6
0
        private static void Main(string[] args)
        {
            ConfigureApplication();

            var foolano      = new Customer("*****@*****.**");
            var book         = new Book("Awesome book");
            var broom        = new PhysicalItem("Broom");
            var membership   = new Membership("Premium account");
            var address      = new Address("79042-656");
            var digitalMedia = new DigitalMedia("AwesomeBook.epub");
            var creditCard   = CreditCard.FetchByHashed("43567890-987654367");

            var order = new Order(foolano, address);

            order.AddProduct(book);
            order.AddProduct(broom);
            order.AddProduct(membership);
            order.AddProduct(digitalMedia);
            order.Pay(creditCard);

            Console.WriteLine(order.IsPaid);
            Console.WriteLine(order.Items[0].Product);
            Console.WriteLine(foolano.Memberships.First().Activated);
        }