Exemplo n.º 1
0
        public void GivenICreatedAnItem(string itemName)
        {
            var itemCreated = new ItemCreated(itemName);

            this.ItemId = itemCreated.Id;
            this.EventStore.Save(itemCreated);
        }
Exemplo n.º 2
0
        public async Task <string> RegisterToEatAPI(string accessToken, SharePointSite spSite, SharePointList spList)
        {
            string   endpoint = "https://graph.microsoft.com/v1.0/sites/" + spSite.id + "/lists/" + spList.Id + "/items/";
            UserInfo me       = await getMe(accessToken);

            using (var client = new HttpClient())
            {
                using (var request = new HttpRequestMessage(HttpMethod.Post, endpoint))
                {
                    ItemCreated item = new ItemCreated()
                    {
                        fields = new FieldsCreated
                        {
                            Title       = "Je veux manger",
                            DisplayName = me.displayName,
                            UPN         = me.userPrincipalName
                        }
                    };
                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                    request.Content = new StringContent(JsonConvert.SerializeObject(item), Encoding.UTF8, "application/json");
                    using (var response = await client.SendAsync(request))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            return(Resource.Graph_RegisterToEatAPI_Success_Result);
                        }
                        return(response.ReasonPhrase);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void AddingButton_Click(object sender, EventArgs e)
        {
            string name       = _nameTextBox.Text;
            string surname    = _surnameTextBox.Text;
            string middleName = _middleNameTextBox.Text;
            string phone      = _phoneTextBox.Text;

            if (name == "" || surname == "" || middleName == "" || phone == "" || _seriesTextBox.Text == "" || _numberTextBox.Text == "")
            {
                DisplayError("Не все поля заполнены!");
                return;
            }

            string gender;

            if (_maleRadioButton.Checked)
            {
                gender = _maleRadioButton.Text;
            }
            else
            {
                gender = _femaleRadioButton.Text;
            }
            DateTime birthDate         = _birthdatePicker.Value;
            DateTime passportIssueDate = _issueDatePicker.Value;

            int passportSeries;
            int passportNumber;

            if (int.TryParse(_seriesTextBox.Text, out passportSeries) == false)
            {
                DisplayError("Некорректная серия паспорта!");
                return;
            }
            if (int.TryParse(_numberTextBox.Text, out passportNumber) == false)
            {
                DisplayError("Некорректный номер паспорта!");
                return;
            }

            if (_guestToChange == null)
            {
                Guest newGuest = new Guest(_newId, name, surname, middleName, birthDate, gender, phone, passportSeries, passportNumber, passportIssueDate);
                ItemCreated?.Invoke(newGuest);
            }
            else
            {
                _guestToChange.Name              = name;
                _guestToChange.Surname           = surname;
                _guestToChange.MiddleName        = middleName;
                _guestToChange.Phone             = phone;
                _guestToChange.Gender            = gender;
                _guestToChange.BirthDate         = birthDate;
                _guestToChange.PassportSeries    = passportSeries;
                _guestToChange.PassportNumber    = passportNumber;
                _guestToChange.PassportIssueDate = passportIssueDate;
            }

            Close();
        }
Exemplo n.º 4
0
        public async Task send_and_await_still_works()
        {
            var bus = theSender.Get <IMessageContext>();

            var item = new ItemCreated
            {
                Name = "Hat",
                Id   = Guid.NewGuid()
            };

            using (var conn = new SqlConnection(ConnectionSource.ConnectionString))
            {
                await conn.OpenAsync();

                var tx = conn.BeginTransaction();
                await bus.EnlistInTransaction(tx);

                await bus.SendAndWait(item);
            }



            var item2 = await loadItem(item.Id);

            item2.Name.ShouldBe("Hat");


            var deleted = thePersistor.AllIncomingEnvelopes().Any();

            if (!deleted)
            {
                Thread.Sleep(500);
                thePersistor.AllIncomingEnvelopes().Any().ShouldBeFalse();
            }
        }
Exemplo n.º 5
0
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            int number = (int)_numberInput.Value;
            int floors = (int)_floorsInput.Value;
            int rooms  = (int)_roomsInput.Value;

            string country = _countryInput.Text;
            string city    = _cityInput.Text;
            string street  = _streetInput.Text;
            string house   = _houseInput.Text;

            if (country == "" || city == "" || street == "" || house == "")
            {
                DisplayError("Не все поля заполнены!");
                return;
            }

            if (_existingHotel == null)
            {
                Hotel newHotel = new Hotel(_newId, number, floors, rooms, country, city, street, house);
                ItemCreated?.Invoke(newHotel);
            }
            else
            {
                _existingHotel.Number         = number;
                _existingHotel.FloorsCount    = floors;
                _existingHotel.RoomsCount     = rooms;
                _existingHotel.Adress.Country = country;
                _existingHotel.Adress.City    = city;
                _existingHotel.Adress.Street  = street;
                _existingHotel.Adress.House   = house;
            }

            Close();
        }
Exemplo n.º 6
0
 protected virtual void OnItemCreated(View view)
 {
     if (this.ItemCreated != null)
     {
         ItemCreated.Invoke(this, new RepeaterViewItemAddedEventArgs(view, view.BindingContext));
     }
 }
Exemplo n.º 7
0
        public void ThrowsDomainExceptionWhenDiableAnItemWIthUnits()
        {
            var itemCreated = new ItemCreated("item name");
            var item        = new Item(new Event[] { itemCreated, new UnitsAdded(itemCreated.Id, 5) });

            Check.ThatCode(() => item.Disable()).Throws <DomainException>();
        }
Exemplo n.º 8
0
        // SAMPLE: basic-sql-server-outbox-sample
        private static async Task outbox_sample(IMessageContext messaging, ItemCreated item)
        {
            using (var conn = new SqlConnection(ConnectionSource.ConnectionString))
            {
                await conn.OpenAsync();

                // Start your transaction
                var tx = conn.BeginTransaction();

                // enlist the current IMessageContext to persist
                // outgoing messages with the current transaction
                await messaging.EnlistInTransaction(tx);

                // enqueue outgoing messages
                await messaging.Send(item);

                tx.Commit();

                // Flush the outgoing messages into Jasper's outgoing
                // sending loops, but don't worry, the messages are
                // persisted where they can be recovered by other nodes
                // in case something goes wrong here
                await messaging.SendAllQueuedOutgoingMessages();
            }
        }
Exemplo n.º 9
0
        public async Task send_with_receiver_down_to_see_the_persisted_envelopes()
        {
            // Shutting it down
            theReceiver.Dispose();
            theReceiver = null;

            var bus         = theSender.Get <IMessageContext>();
            var senderStore = theSender.Get <IDocumentStore>();

            var item = new ItemCreated
            {
                Name = "Shoe",
                Id   = Guid.NewGuid()
            };

            var waiter = theTracker.WaitFor <ItemCreated>();

            using (var session = senderStore.LightweightSession())
            {
                await bus.EnlistInTransaction(session);

                await bus.Send(item);

                await session.SaveChangesAsync();
            }

            using (var session = senderStore.LightweightSession())
            {
                var outgoing = session.AllOutgoingEnvelopes().SingleOrDefault();

                outgoing.MessageType.ShouldBe(typeof(ItemCreated).ToMessageAlias());
            }
        }
Exemplo n.º 10
0
        public void Process(ItemCreated evt)
        {
            var taskList = _repositoryForTaskList.GetById(evt.ListId);

            if (taskList == null)
            {
                taskList = new TaskList
                {
                    Id    = evt.ListId,
                    Tasks = new []
                    {
                        new TodoTask
                        {
                            Text = evt.Text,
                        }
                    }
                };

                _repositoryForTaskList.Insert(taskList);
            }
            else
            {
                taskList.Tasks.Add(new TodoTask
                {
                    Text = evt.Text,
                });

                _repositoryForTaskList.Update(taskList);
            }
        }
Exemplo n.º 11
0
        public async Task send_and_await_still_works()
        {
            var bus         = theSender.Get <IMessageContext>();
            var senderStore = theSender.Get <IDocumentStore>();

            var item = new ItemCreated
            {
                Name = "Hat",
                Id   = Guid.NewGuid()
            };

            using (var session = senderStore.LightweightSession())
            {
                await bus.EnlistInTransaction(session);

                await bus.SendAndWait(item);
            }

            using (var session = theReceiver.Get <IDocumentStore>().QuerySession())
            {
                var item2 = session.Load <ItemCreated>(item.Id);

                item2.Name.ShouldBe("Hat");

                var deleted = session.AllIncomingEnvelopes().Any();
                if (!deleted)
                {
                    Thread.Sleep(500);
                    session.AllIncomingEnvelopes().Any().ShouldBeFalse();
                }
            }
        }
Exemplo n.º 12
0
        public async Task schedule_local_job_durably()
        {
            var bus         = theSender.Get <IMessageContext>();
            var senderStore = theSender.Get <IDocumentStore>();

            var item = new ItemCreated
            {
                Name = "Shoe",
                Id   = Guid.NewGuid()
            };

            using (var session = senderStore.LightweightSession())
            {
                await bus.EnlistInTransaction(session);

                await bus.Schedule(item, 1.Hours());

                await session.SaveChangesAsync();
            }

            using (var session = senderStore.LightweightSession())
            {
                var scheduled = session.AllIncomingEnvelopes().Single();

                scheduled.MessageType.ShouldBe(typeof(ItemCreated).ToMessageAlias());
                scheduled.Status.ShouldBe(TransportConstants.Scheduled);
            }
        }
        public void InsertNewItemViewWhenHandleItemCreatedEvent()
        {
            var @event = new ItemCreated("item name");

            this.viewModelGenerator.Handle(@event);
            this.repositoryMock.Verify(x => x.Insert(new ItemView(@event.Id, @event.Name)));
        }
Exemplo n.º 14
0
        public async Task schedule_local_job_durably()
        {
            var bus = theSender.Get <IMessageContext>();

            var item = new ItemCreated
            {
                Name = "Shoe",
                Id   = Guid.NewGuid()
            };

            using (var conn = new SqlConnection(ConnectionSource.ConnectionString))
            {
                await conn.OpenAsync();

                var tx = conn.BeginTransaction();


                await bus.EnlistInTransaction(tx);

                await bus.Schedule(item, 1.Hours());



                tx.Commit();

                await bus.SendAllQueuedOutgoingMessages();
            }

            var scheduled = theSender.Get <SqlServerEnvelopePersistor>().AllIncomingEnvelopes().Single();

            scheduled.MessageType.ShouldBe(typeof(ItemCreated).ToMessageAlias());
            scheduled.Status.ShouldBe(TransportConstants.Scheduled);
        }
Exemplo n.º 15
0
        public void TestAddItemExecute()
        {
            // ARRANGE
            var businessEntityFactory          = new StarBusinessEntityFactory();
            IStarBusinessEntity businessEntity = businessEntityFactory.Create();

            var usecaseFactory = new AddItemUsecaseFactory(new IdClass());

            StarItemDto data = null;

            var returnInterface = new ItemCreated();

            returnInterface.Created += (s, e) =>
            {
                data = new StarItemDto
                {
                    Id       = e.Id,
                    IsNew    = e.IsNew,
                    ItemName = e.ItemName
                };
            };

            IAddStarItemInputPort addItemInterActor = usecaseFactory.Create(businessEntity);

            addItemInterActor.BindOutputBoundary(returnInterface);

            // ACT
            addItemInterActor.Execute();

            // ASSERT
            Assert.IsNotNull(data, "StarItemCreated return interface did not return data.");
            Assert.AreEqual(Guid.Parse(@"01234567-89ab-cdef-0000-0123456789AB"), data.Id);
            Assert.IsTrue(data.IsNew);
            Assert.AreEqual(String.Empty, data.ItemName);
        }
Exemplo n.º 16
0
        public void Process(ItemCreated evt)
        {
            var allLists = _repositoryForAvailableLists.GetById(default(Guid));

            if (allLists != null)
            {
                if (!allLists.Lists.Any(list => list == evt.ListId))
                {
                    allLists.Lists.Add(evt.ListId);
                    _repositoryForAvailableLists.Update(allLists);
                }
            }
            else
            {
                allLists = new AvailableLists
                {
                    Id    = default(Guid),
                    Lists = new ListId[]
                    {
                        evt.ListId
                    }
                };

                _repositoryForAvailableLists.Insert(allLists);
            }
        }
Exemplo n.º 17
0
        public void ThrowsDomainExceptionWhenEnableAndItemIsAlreadyEnabled()
        {
            var itemCreated = new ItemCreated("item name");
            var item        = new Item(new Event[] { itemCreated });

            Check.ThatCode(() => item.Enable()).Throws <DomainException>();
        }
Exemplo n.º 18
0
        public void IgnoreUnexpectedEvents()
        {
            var itemCreated = new ItemCreated("item name");
            var events      = new Event[] { itemCreated, new ItemRenamed(It.IsAny <Guid>(), "new item name"), new Event1Fake() };

            Check.ThatCode(() => new Item(events)).DoesNotThrow();
        }
Exemplo n.º 19
0
        public void ThrowsDomainExceptionWhenRenameWithAnName(string newName)
        {
            var itemCreated = new ItemCreated("item name");
            var item        = new Item(new Event[] { itemCreated, new ItemDisabled(It.IsAny <Guid>()) });

            Check.ThatCode(() => item.Rename(newName)).Throws <DomainException>();
        }
Exemplo n.º 20
0
        public void BeEnableWhenProvideItemCreated()
        {
            var itemCreated = new ItemCreated("item name");
            var item        = new Item(new[] { itemCreated });

            Check.That(item.IsEnabled).IsTrue();
        }
Exemplo n.º 21
0
        public void ThrowsDomainExceptionWhenRemoveMoreUnitsThanExisting()
        {
            var itemCreated = new ItemCreated("item name");
            var item        = new Item(new Event[] { itemCreated, new UnitsAdded(itemCreated.Id, 2) });

            Check.ThatCode(() => item.RemoveUnits(6)).Throws <DomainException>();
        }
Exemplo n.º 22
0
        public void ThrowsDomainExceptionWhenRemoveUnitsAndItemIsDisabled()
        {
            var itemCreated = new ItemCreated("item name");
            var item        = new Item(new Event[] { itemCreated, new ItemDisabled(itemCreated.Id) });

            Check.ThatCode(() => item.RemoveUnits(5)).Throws <DomainException>();
        }
Exemplo n.º 23
0
        public T Create()
        {
            var entity = new T();

            ItemCreated?.Invoke();
            return(entity);
        }
Exemplo n.º 24
0
 public static void Handle(ItemCreated created, IDocumentSession session,
                           Jasper.Messaging.Tracking.MessageTracker tracker,
                           Envelope envelope)
 {
     session.Store(created);
     tracker.Record(created, envelope);
 }
Exemplo n.º 25
0
        public void HaveCorrectIdAndNameWhenProvideItemCreated()
        {
            var itemCreated = new ItemCreated("item name");
            var item        = new Item(new[] { itemCreated });

            Check.That(item.Id).Equals(itemCreated.Id);
            Check.That(item.Name).Equals("item name");
        }
Exemplo n.º 26
0
        public void DomainEventBase_WithoutDisplayName_ReturnsClassName()
        {
            var itemCreated = new ItemCreated();

            string displayName = itemCreated.GetDisplayName();

            Assert.That(displayName == "ItemCreated");
        }
Exemplo n.º 27
0
 public virtual void NotifyCreated(ContentItem item)
 {
     notifier.NotifiyCreated(item);
     if (ItemCreated != null)
     {
         ItemCreated.Invoke(this, new ItemEventArgs(item));
     }
 }
Exemplo n.º 28
0
        public void BeEnableWhenProvideItemCreatedAndItemEnabled()
        {
            var itemCreated = new ItemCreated("item name");

            var events = new Event[] { itemCreated, new ItemDisabled(itemCreated.Id), new ItemEnabled(itemCreated.Id) };
            var item   = new Item(events);

            Check.That(item.IsEnabled).IsTrue();
        }
Exemplo n.º 29
0
        public void Add(TodoText text)
        {
            var createdEvent = new ItemCreated(
                EventSourceId,
                text
                );

            Apply(createdEvent);
        }
Exemplo n.º 30
0
        public async Task basic_send()
        {
            var bus         = theSender.Get <IServiceBus>();
            var senderStore = theSender.Get <IDocumentStore>();

            var item = new ItemCreated
            {
                Name = "Shoe",
                Id   = Guid.NewGuid()
            };

            var waiter = theTracker.WaitFor <ItemCreated>();

            using (var session = senderStore.LightweightSession())
            {
                bus.EnlistInTransaction(session);

                await bus.Send(item);

                await session.SaveChangesAsync();
            }

            waiter.Wait(5.Seconds());

            waiter.IsCompleted.ShouldBeTrue();

            using (var session = theReceiver.Get <IDocumentStore>().QuerySession())
            {
                var item2 = session.Load <ItemCreated>(item.Id);
                if (item2 == null)
                {
                    Thread.Sleep(500);
                    item2 = session.Load <ItemCreated>(item.Id);
                }



                item2.Name.ShouldBe("Shoe");

                var allGone = session.AllIncomingEnvelopes().Any();
                if (!allGone)
                {
                    Thread.Sleep(500);
                    session.AllIncomingEnvelopes().Any().ShouldBeFalse();
                }
            }

            using (var session = senderStore.QuerySession())
            {
                var allGone = session.AllOutgoingEnvelopes().Any();
                if (allGone)
                {
                    Thread.Sleep(500);
                    session.AllOutgoingEnvelopes().Any().ShouldBeFalse();
                }
            }
        }
        public void Handle(ItemCreated msg)
        {
            if(msg == null) throw new ArgumentNullException("msg");

            _repository.Update(ItemEvent.NewItemCreated(msg));
        }