Beispiel #1
0
        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.RequestToPublish();

            Assert.Equal(ClassifiedAd.ClassifiedAdState.PendingReview,
                         _classifiedAd.State);
        }
Beispiel #2
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);
 }
        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://localhost/storage/123.jpg"), new PictureSize(1200, 620));

            _classifiedAd.RequestToPublish();

            Assert.Equal(ClassifiedAd.ClassifiedAdState.PendingReview,
                         _classifiedAd.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;

            // Let's not repeat ourselves!

            case ClassifiedAds.V1.UpdatePrice cmd:
                await HandleUpdate(cmd.Id, c => c.UpdatePrice(Price.FromDecimal(cmd.Price, cmd.Currency, _currencyLookup)));

                break;

            case ClassifiedAds.V1.RequestToPublish cmd:
                await HandleUpdate(cmd.Id, c => c.RequestToPublish());

                break;

            default:
                throw new InvalidOperationException($"Command type { command.GetType().FullName } is unknown");
            }
        }
Beispiel #5
0
        public void Request_publishing_should_fail_when_price_is_missing()
        {
            var ad = new ClassifiedAd(new ClassifiedAdId(Guid.NewGuid()), new UserId(Guid.NewGuid()));

            ad.SetTitle(ClassifiedAdTitle.FromTextOrHtml("Fine car!"));
            ad.UpdateText(ClassifiedAdText.FromString("1981 Talbot. Mint condition, no rust"));

            Assert.Throws <InvalidEntityStateException>(() => ad.RequestToPublish());
        }
Beispiel #6
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());
        }
Beispiel #7
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);
        }