public void Can_publish_a_valid_ad()
        {
            _classifiedAd.SetTitle(ClassifiedAddTitle.FromString("Test Ad"));
            _classifiedAd.UpdateText(ClassifiedAdText.FromString("Please buy my stuff"));
            _classifiedAd.UpdatePrice(Price.FromDecimal(100.10M, "EUR", new FakeCurrencyLookup()));
            _classifiedAd.RequestToPublish();

            Assert.Equal(ClassifiedAd.ClassifiedAdState.PendingReview, _classifiedAd.State);
        }
        public void Can_publish_a_valid_ad()
        {
            _classifiedAd.SetTitle(ClassifiedAdTitle.FromString("Test ad"));
            _classifiedAd.UpdateText(ClassifiedAdText.FromString("Please buy my stuff"));
            _classifiedAd.UpdatePrice(Price.FromDecimal(100.10m, "EUR", new FakeCurrencyLookup()));
            _classifiedAd.AddPicture(new Uri("http://www.google.de"), new PictureSize(1000, 1000));
            _classifiedAd.RequestToPublish();

            Assert.Equal(ClassifiedAd.ClassifiedAdState.PendingReview, _classifiedAd.State);
        }
Пример #3
0
 public void test_publish_a_valid_ad_should_be_success()
 {
     //Given
     _classifiedAd.SetTitle(ClassifiedAdTitle.FromString("covid-19 comming"));
     _classifiedAd.UpdateText(ClassifiedAdText.FromString("keeping social distancing"));
     _classifiedAd.UpdatePrice(Price.Create(100M, Currency.Default));
     _classifiedAd.AddPicture(new Uri("http://localhost/storage/123.jpg"), new PictureSize(800, 600));
     //When
     _classifiedAd.RequestToPublish();
     //Then
     Assert.Equal(ClassifiedAdState.PendingReview, _classifiedAd.State);
 }
Пример #4
0
        public void Request_publishing_should_fail_when_text_is_missing()
        {
            var ad = new ClassifiedAd(new ClassifiedAdId(Guid.NewGuid()), new UserId(Guid.NewGuid()));

            ad.SetTitle(ClassifiedAdTitle.FromTextOrHtml("Fine car!"));
            ad.UpdatePrice(Price.FromDecimal(1500m, "EUR", new FakeCurrencyLookup()));

            Assert.Throws <InvalidEntityStateException>(() => ad.RequestToPublish());
        }
Пример #5
0
        public void Request_publishing_should_fail_when_title_is_missing()
        {
            var ad = new ClassifiedAd(new ClassifiedAdId(Guid.NewGuid()), new UserId(Guid.NewGuid()));

            ad.UpdateText(ClassifiedAdText.FromString("1981 Talbot. Mint condition, no rust"));
            ad.UpdatePrice(Price.FromDecimal(1500m, "EUR", new FakeCurrencyLookup()));

            Assert.Throws <InvalidEntityStateException>(() => ad.RequestToPublish());
        }
Пример #6
0
        public void Request_publishing_should_succeed_when_ad_is_complete()
        {
            var ad = new ClassifiedAd(new ClassifiedAdId(Guid.NewGuid()), new UserId(Guid.NewGuid()));

            ad.AddPicture(new PictureId(Guid.NewGuid()), new PictureSize(800, 600), new Uri("http://example.com"));
            ad.SetTitle(ClassifiedAdTitle.FromTextOrHtml("Fine car!"));
            ad.UpdateText(ClassifiedAdText.FromString("1981 Talbot. Mint condition, no rust"));
            ad.UpdatePrice(Price.FromDecimal(1500m, "EUR", new FakeCurrencyLookup()));

            ad.RequestToPublish();
            Assert.Equal(ClassifiedAdState.PendingReview, ad.State);
        }
        public async Task Handle(object command)
        {
            ClassifiedAd classifiedAd; switch (command)
            {
            case ClassifiedAds.V1.Create cmd:
                if (await _store.Exists <ClassifiedAd>(cmd.Id.ToString()))
                {
                    throw new InvalidOperationException($"Entity with id {cmd.Id} already exists");
                }
                classifiedAd = new ClassifiedAd(new ClassifiedAdId(cmd.Id), new UserId(cmd.OwnerId));
                await _store.Save(classifiedAd); break;

            case ClassifiedAds.V1.SetTitle cmd:
                classifiedAd = await _store.Load <ClassifiedAd>(cmd.Id.ToString()); if (classifiedAd == null)
                {
                    throw new InvalidOperationException($"Entity with id {cmd.Id} cannot be found");
                }
                classifiedAd.SetTitle(ClassifiedAdTitle.FromString(cmd.Title)); await _store.Save(classifiedAd); break;

            case ClassifiedAds.V1.UpdateText cmd:
                classifiedAd = await _store.Load <ClassifiedAd>(cmd.Id.ToString()); if (classifiedAd == null)
                {
                    throw new InvalidOperationException($"Entity with id {cmd.Id} cannot be found");
                }
                classifiedAd.UpdateText(ClassifiedAdText.FromString(cmd.Text)); await _store.Save(classifiedAd); break;

            case ClassifiedAds.V1.UpdatePrice cmd:
                classifiedAd = await _store.Load <ClassifiedAd>(cmd.Id.ToString()); if (classifiedAd == null)
                {
                    throw new InvalidOperationException($"Entity with id {cmd.Id} cannot be found");
                }
                classifiedAd.UpdatePrice(Price.FromDecimal(cmd.Price, cmd.Currency, _currencyLookup)); await _store.Save(classifiedAd); break;

            case ClassifiedAds.V1.RequestToPublish cmd:
                classifiedAd = await _store.Load <ClassifiedAd>(cmd.Id.ToString()); if (classifiedAd == null)
                {
                    throw new InvalidOperationException($"Entity with id {cmd.Id} cannot be found");
                }
                classifiedAd.RequestToPublish(); await _store.Save(classifiedAd); break;

            default: throw new InvalidOperationException($"Command type {command.GetType().FullName} is unknown");
            }
        }